Skip to content

Commit

Permalink
t5300: confirm failure of git index-pack when non-idx suffix requested
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
jeffhostetler authored and dscho committed Mar 15, 2024
1 parent 4f9b731 commit ac1b218
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions t/t5300-pack-object.sh
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,31 @@ test_expect_success 'build pack index for an existing pack' '
:
'

# The `--rev-index` option of `git index-pack` is now the default, so
# a `foo.rev` REV file will be created when a `foo.idx` IDX file is
# created. Normally, these pathnames are based upon the `foo.pack`
# PACK file pathname.
#
# However, the `-o` option lets you set the pathname of the IDX file
# indepdent of the PACK file.
#
# Verify what happens if these suffixes are changed.
#
test_expect_success 'complain about index name' '
# Normal case { .pack, .idx, .rev }
cat test-1-${packname_1}.pack >test-complain-0.pack &&
git index-pack -o test-complain-0.idx --rev-index test-complain-0.pack &&
test -f test-complain-0.idx &&
test -f test-complain-0.rev &&
# Non .idx suffix
cat test-1-${packname_1}.pack >test-complain-1.pack &&
test_must_fail git index-pack -o test-complain-1.idx-suffix --rev-index test-complain-1.pack 2>err &&
grep "does not end" err &&
! test -f test-complain-1.idx-suffix &&
! test -f test-complain-1.rev
'

test_expect_success 'unpacking with --strict' '
for j in a b c d e f g
Expand Down

0 comments on commit ac1b218

Please sign in to comment.