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 <jeffhostetler@github.com>
  • Loading branch information
jeffhostetler committed Aug 25, 2023
1 parent c68e5fb commit 2e0c3ed
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 2e0c3ed

Please sign in to comment.