3 test_description='on-disk reverse index'
6 # The below tests want control over the 'pack.writeReverseIndex' setting
7 # themselves to assert various combinations of it with other options.
8 sane_unset GIT_TEST_WRITE_REV_INDEX
10 packdir=.git/objects/pack
12 test_expect_success 'setup' '
15 pack=$(git pack-objects --all $packdir/pack) &&
16 rev=$packdir/pack-$pack.rev &&
18 test_path_is_missing $rev
25 # remove the index since Windows won't overwrite an existing file
26 rm $packdir/pack-$pack.idx &&
27 git -c pack.writeReverseIndex=$conf index-pack "$@" \
28 $packdir/pack-$pack.pack
31 test_expect_success 'index-pack with pack.writeReverseIndex' '
33 test_path_is_missing $rev &&
35 test_index_pack false &&
36 test_path_is_missing $rev &&
38 test_index_pack true &&
39 test_path_is_file $rev
42 test_expect_success 'index-pack with --[no-]rev-index' '
43 for conf in "" true false
45 test_index_pack "$conf" --rev-index &&
46 test_path_exists $rev &&
48 test_index_pack "$conf" --no-rev-index &&
49 test_path_is_missing $rev
53 test_expect_success 'index-pack can verify reverse indexes' '
54 test_when_finished "rm -f $rev" &&
55 test_index_pack true &&
57 test_path_is_file $rev &&
58 git index-pack --rev-index --verify $packdir/pack-$pack.pack &&
60 # Intentionally corrupt the reverse index.
62 printf "xxxx" | dd of=$rev bs=1 count=4 conv=notrunc &&
64 test_must_fail git index-pack --rev-index --verify \
65 $packdir/pack-$pack.pack 2>err &&
66 grep "validation error" err
69 test_expect_success 'index-pack infers reverse index name with -o' '
70 git index-pack --rev-index -o other.idx $packdir/pack-$pack.pack &&
71 test_path_is_file other.idx &&
72 test_path_is_file other.rev
75 test_expect_success 'pack-objects respects pack.writeReverseIndex' '
76 test_when_finished "rm -fr pack-1-*" &&
78 git -c pack.writeReverseIndex= pack-objects --all pack-1 &&
79 test_path_is_missing pack-1-*.rev &&
81 git -c pack.writeReverseIndex=false pack-objects --all pack-1 &&
82 test_path_is_missing pack-1-*.rev &&
84 git -c pack.writeReverseIndex=true pack-objects --all pack-1 &&
85 test_path_is_file pack-1-*.rev
88 test_expect_success 'reverse index is not generated when available on disk' '
89 test_index_pack true &&
90 test_path_is_file $rev &&
92 git rev-parse HEAD >tip &&
93 GIT_TEST_REV_INDEX_DIE_IN_MEMORY=1 git cat-file \
94 --batch-check="%(objectsize:disk)" <tip
97 test_expect_success 'revindex in-memory vs on-disk' '
99 test_when_finished "rm -fr repo" &&
103 test_commit commit &&
105 git rev-list --objects --no-object-names --all >objects &&
107 git -c pack.writeReverseIndex=false repack -ad &&
108 test_path_is_missing $packdir/pack-*.rev &&
109 git cat-file --batch-check="%(objectsize:disk) %(objectname)" \
112 git -c pack.writeReverseIndex=true repack -ad &&
113 test_path_is_file $packdir/pack-*.rev &&
114 git cat-file --batch-check="%(objectsize:disk) %(objectname)" \
117 test_cmp on-disk in-core