Skip to content

Commit 19d951f

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> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 4f9b731 commit 19d951f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

t/t5300-pack-object.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,31 @@ test_expect_success 'build pack index for an existing pack' '
355355
:
356356
'
357357

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

0 commit comments

Comments
 (0)