builtin/am: allow disabling conflict advice
[alt-git.git] / t / t5325-reverse-index.sh
blob431a603ca0e61d7085f28333c6a28c120ea45828
1 #!/bin/sh
3 test_description='on-disk reverse index'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 # The below tests want control over the 'pack.writeReverseIndex' setting
9 # themselves to assert various combinations of it with other options.
10 sane_unset GIT_TEST_NO_WRITE_REV_INDEX
12 packdir=.git/objects/pack
14 test_expect_success 'setup' '
15 test_commit base &&
17 test_config pack.writeReverseIndex false &&
18 pack=$(git pack-objects --all $packdir/pack) &&
19 rev=$packdir/pack-$pack.rev &&
21 test_path_is_missing $rev
24 test_index_pack () {
25 rm -f $rev &&
26 conf=$1 &&
27 shift &&
28 # remove the index since Windows won't overwrite an existing file
29 rm $packdir/pack-$pack.idx &&
30 git -c pack.writeReverseIndex=$conf index-pack "$@" \
31 $packdir/pack-$pack.pack
34 test_expect_success 'index-pack with pack.writeReverseIndex' '
35 test_index_pack "" &&
36 test_path_is_missing $rev &&
38 test_index_pack false &&
39 test_path_is_missing $rev &&
41 test_index_pack true &&
42 test_path_is_file $rev
45 test_expect_success 'index-pack with --[no-]rev-index' '
46 for conf in "" true false
48 test_index_pack "$conf" --rev-index &&
49 test_path_exists $rev &&
51 test_index_pack "$conf" --no-rev-index &&
52 test_path_is_missing $rev || return 1
53 done
56 test_expect_success 'index-pack can verify reverse indexes' '
57 test_when_finished "rm -f $rev" &&
58 test_index_pack true &&
60 test_path_is_file $rev &&
61 git index-pack --rev-index --verify $packdir/pack-$pack.pack &&
63 # Intentionally corrupt the reverse index.
64 chmod u+w $rev &&
65 printf "xxxx" | dd of=$rev bs=1 count=4 conv=notrunc &&
67 test_must_fail git index-pack --rev-index --verify \
68 $packdir/pack-$pack.pack 2>err &&
69 grep "validation error" err
72 test_expect_success 'index-pack infers reverse index name with -o' '
73 git index-pack --rev-index -o other.idx $packdir/pack-$pack.pack &&
74 test_path_is_file other.idx &&
75 test_path_is_file other.rev
78 test_expect_success 'pack-objects respects pack.writeReverseIndex' '
79 test_when_finished "rm -fr pack-1-*" &&
81 git -c pack.writeReverseIndex= pack-objects --all pack-1 &&
82 test_path_is_missing pack-1-*.rev &&
84 git -c pack.writeReverseIndex=false pack-objects --all pack-1 &&
85 test_path_is_missing pack-1-*.rev &&
87 git -c pack.writeReverseIndex=true pack-objects --all pack-1 &&
88 test_path_is_file pack-1-*.rev
91 test_expect_success 'reverse index is not generated when available on disk' '
92 test_index_pack true &&
93 test_path_is_file $rev &&
95 git rev-parse HEAD >tip &&
96 GIT_TEST_REV_INDEX_DIE_IN_MEMORY=1 git cat-file \
97 --batch-check="%(objectsize:disk)" <tip
100 test_expect_success 'reverse index is ignored when pack.readReverseIndex is false' '
101 test_index_pack true &&
102 test_path_is_file $rev &&
104 test_config pack.readReverseIndex false &&
106 git rev-parse HEAD >tip &&
107 GIT_TEST_REV_INDEX_DIE_ON_DISK=1 git cat-file \
108 --batch-check="%(objectsize:disk)" <tip
111 test_expect_success 'revindex in-memory vs on-disk' '
112 git init repo &&
113 test_when_finished "rm -fr repo" &&
115 cd repo &&
117 test_commit commit &&
119 git rev-list --objects --no-object-names --all >objects &&
121 git -c pack.writeReverseIndex=false repack -ad &&
122 test_path_is_missing $packdir/pack-*.rev &&
123 git cat-file --batch-check="%(objectsize:disk) %(objectname)" \
124 <objects >in-core &&
126 git -c pack.writeReverseIndex=true repack -ad &&
127 test_path_is_file $packdir/pack-*.rev &&
128 git cat-file --batch-check="%(objectsize:disk) %(objectname)" \
129 <objects >on-disk &&
131 test_cmp on-disk in-core
135 test_expect_success 'fsck succeeds on good rev-index' '
136 test_when_finished rm -fr repo &&
137 git init repo &&
139 cd repo &&
141 test_commit commit &&
142 git -c pack.writeReverseIndex=true repack -ad &&
143 git fsck 2>err &&
144 test_must_be_empty err
148 test_expect_success 'set up rev-index corruption tests' '
149 git init corrupt &&
151 cd corrupt &&
153 test_commit commit &&
154 git -c pack.writeReverseIndex=true repack -ad &&
156 revfile=$(ls .git/objects/pack/pack-*.rev) &&
157 chmod a+w $revfile &&
158 cp $revfile $revfile.bak
162 corrupt_rev_and_verify () {
164 pos="$1" &&
165 value="$2" &&
166 error="$3" &&
168 cd corrupt &&
169 revfile=$(ls .git/objects/pack/pack-*.rev) &&
171 # Reset to original rev-file.
172 cp $revfile.bak $revfile &&
174 printf "$value" | dd of=$revfile bs=1 seek="$pos" conv=notrunc &&
175 test_must_fail git fsck 2>err &&
176 grep "$error" err
180 test_expect_success 'fsck catches invalid checksum' '
181 revfile=$(ls corrupt/.git/objects/pack/pack-*.rev) &&
182 orig_size=$(wc -c <$revfile) &&
183 hashpos=$((orig_size - 10)) &&
184 corrupt_rev_and_verify $hashpos bogus \
185 "invalid checksum"
188 test_expect_success 'fsck catches invalid row position' '
189 corrupt_rev_and_verify 14 "\07" \
190 "invalid rev-index position"
193 test_expect_success 'fsck catches invalid header: magic number' '
194 corrupt_rev_and_verify 1 "\07" \
195 "reverse-index file .* has unknown signature"
198 test_expect_success 'fsck catches invalid header: version' '
199 corrupt_rev_and_verify 7 "\02" \
200 "reverse-index file .* has unsupported version"
203 test_expect_success 'fsck catches invalid header: hash function' '
204 corrupt_rev_and_verify 11 "\03" \
205 "reverse-index file .* has unsupported hash id"
208 test_done