Skip to content

Commit d5da60b

Browse files
jeffhostetlerdscho
authored andcommitted
t5300: confirm failure of git index-pack when non-idx suffix requested
Add test case to demonstrate that `git index-pack -o <idx-path> pack-path` fails if <idx-path> does not end in ".idx" when `--rev-index` is enabled. In e37d0b8 (builtin/index-pack.c: write reverse indexes, 2021-01-25) we learned to create `.rev` reverse indexes in addition to `.idx` index files. The `.rev` file pathname is constructed by replacing the suffix on the `.idx` file. The code assumes a hard-coded "idx" suffix. In a8dd7e0 (config: enable `pack.writeReverseIndex` by default, 2023-04-12) reverse indexes were enabled by default. If the `-o <idx-path>` argument is used, the index file may have a different suffix. This causes an error when it tries to create the reverse index pathname. The test here demonstrates the failure. (The test forces `--rev-index` to avoid interaction with `GIT_TEST_NO_WRITE_REV_INDEX` during CI runs.) Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
1 parent 5d54b0d commit d5da60b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Diff for: t/t5300-pack-object.sh

+25
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,31 @@ test_expect_success 'build pack index for an existing pack' '
357357
:
358358
'
359359

360+
# The `--rev-index` option of `git index-pack` is now the default, so
361+
# a `foo.rev` REV file will be created when a `foo.idx` IDX file is
362+
# created. Normally, these pathnames are based upon the `foo.pack`
363+
# PACK file pathname.
364+
#
365+
# However, the `-o` option lets you set the pathname of the IDX file
366+
# indepdent of the PACK file.
367+
#
368+
# Verify what happens if these suffixes are changed.
369+
#
370+
test_expect_success 'complain about index name' '
371+
# Normal case { .pack, .idx, .rev }
372+
cat test-1-${packname_1}.pack >test-complain-0.pack &&
373+
git index-pack -o test-complain-0.idx --rev-index test-complain-0.pack &&
374+
test -f test-complain-0.idx &&
375+
test -f test-complain-0.rev &&
376+
377+
# Non .idx suffix
378+
cat test-1-${packname_1}.pack >test-complain-1.pack &&
379+
test_must_fail git index-pack -o test-complain-1.idx-suffix --rev-index test-complain-1.pack 2>err &&
380+
grep "does not end" err &&
381+
! test -f test-complain-1.idx-suffix &&
382+
! test -f test-complain-1.rev
383+
'
384+
360385
test_expect_success 'unpacking with --strict' '
361386
362387
for j in a b c d e f g

0 commit comments

Comments
 (0)