]>
Commit | Line | Data |
---|---|---|
a3407730 DS |
1 | #!/bin/sh |
2 | ||
3 | test_description='multi-pack-indexes' | |
4 | . ./test-lib.sh | |
5 | ||
52fe41ff | 6 | GIT_TEST_MULTI_PACK_INDEX=0 |
c4d25228 DS |
7 | objdir=.git/objects |
8 | ||
d9607542 DS |
9 | HASH_LEN=$(test_oid rawsz) |
10 | ||
4d80560c | 11 | midx_read_expect () { |
396f2570 | 12 | NUM_PACKS=$1 |
d7cacf29 | 13 | NUM_OBJECTS=$2 |
662148c4 DS |
14 | NUM_CHUNKS=$3 |
15 | OBJECT_DIR=$4 | |
16 | EXTRA_CHUNKS="$5" | |
3227565c DS |
17 | { |
18 | cat <<-EOF && | |
d9607542 | 19 | header: 4d494458 1 $HASH_LEN $NUM_CHUNKS $NUM_PACKS |
662148c4 | 20 | chunks: pack-names oid-fanout oid-lookup object-offsets$EXTRA_CHUNKS |
d7cacf29 | 21 | num_objects: $NUM_OBJECTS |
3227565c DS |
22 | packs: |
23 | EOF | |
24 | if test $NUM_PACKS -ge 1 | |
25 | then | |
662148c4 | 26 | ls $OBJECT_DIR/pack/ | grep idx | sort |
3227565c | 27 | fi && |
662148c4 | 28 | printf "object-dir: $OBJECT_DIR\n" |
3227565c | 29 | } >expect && |
662148c4 | 30 | test-tool read-midx $OBJECT_DIR >actual && |
4d80560c DS |
31 | test_cmp expect actual |
32 | } | |
33 | ||
3c5e65ca | 34 | test_expect_success 'setup' ' |
3c5e65ca | 35 | test_oid_cache <<-EOF |
36 | idxoff sha1:2999 | |
37 | idxoff sha256:3739 | |
38 | ||
39 | packnameoff sha1:652 | |
40 | packnameoff sha256:940 | |
41 | ||
42 | fanoutoff sha1:1 | |
43 | fanoutoff sha256:3 | |
44 | EOF | |
45 | ' | |
46 | ||
796d61cd DR |
47 | test_expect_success "don't write midx with no packs" ' |
48 | test_must_fail git multi-pack-index --object-dir=. write && | |
49 | test_path_is_missing pack/multi-pack-index | |
50 | ' | |
51 | ||
d9607542 | 52 | test_expect_success SHA1 'warn if a midx contains no oid' ' |
796d61cd DR |
53 | cp "$TEST_DIRECTORY"/t5319/no-objects.midx $objdir/pack/multi-pack-index && |
54 | test_must_fail git multi-pack-index verify && | |
55 | rm $objdir/pack/multi-pack-index | |
a3407730 DS |
56 | ' |
57 | ||
2c381335 DS |
58 | generate_objects () { |
59 | i=$1 | |
60 | iii=$(printf '%03i' $i) | |
61 | { | |
62 | test-tool genrandom "bar" 200 && | |
63 | test-tool genrandom "baz $iii" 50 | |
64 | } >wide_delta_$iii && | |
65 | { | |
66 | test-tool genrandom "foo"$i 100 && | |
67 | test-tool genrandom "foo"$(( $i + 1 )) 100 && | |
68 | test-tool genrandom "foo"$(( $i + 2 )) 100 | |
69 | } >deep_delta_$iii && | |
70 | { | |
71 | echo $iii && | |
72 | test-tool genrandom "$iii" 8192 | |
73 | } >file_$iii && | |
74 | git update-index --add file_$iii deep_delta_$iii wide_delta_$iii | |
75 | } | |
76 | ||
77 | commit_and_list_objects () { | |
78 | { | |
79 | echo 101 && | |
80 | test-tool genrandom 100 8192; | |
81 | } >file_101 && | |
82 | git update-index --add file_101 && | |
83 | tree=$(git write-tree) && | |
84 | commit=$(git commit-tree $tree -p HEAD</dev/null) && | |
85 | { | |
86 | echo $tree && | |
87 | git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/" | |
88 | } >obj-list && | |
89 | git reset --hard $commit | |
90 | } | |
91 | ||
92 | test_expect_success 'create objects' ' | |
93 | test_commit initial && | |
94 | for i in $(test_seq 1 5) | |
95 | do | |
d0fd9931 | 96 | generate_objects $i || return 1 |
2c381335 DS |
97 | done && |
98 | commit_and_list_objects | |
99 | ' | |
100 | ||
101 | test_expect_success 'write midx with one v1 pack' ' | |
c4d25228 DS |
102 | pack=$(git pack-objects --index-version=1 $objdir/pack/test <obj-list) && |
103 | test_when_finished rm $objdir/pack/test-$pack.pack \ | |
104 | $objdir/pack/test-$pack.idx $objdir/pack/multi-pack-index && | |
105 | git multi-pack-index --object-dir=$objdir write && | |
106 | midx_read_expect 1 18 4 $objdir | |
2c381335 DS |
107 | ' |
108 | ||
c4d25228 | 109 | midx_git_two_modes () { |
b4a14394 JK |
110 | git -c core.multiPackIndex=false $1 >expect && |
111 | git -c core.multiPackIndex=true $1 >actual && | |
e9ab2ed7 DS |
112 | if [ "$2" = "sorted" ] |
113 | then | |
b4a14394 JK |
114 | sort <expect >expect.sorted && |
115 | mv expect.sorted expect && | |
116 | sort <actual >actual.sorted && | |
117 | mv actual.sorted actual | |
e9ab2ed7 | 118 | fi && |
c4d25228 DS |
119 | test_cmp expect actual |
120 | } | |
121 | ||
122 | compare_results_with_midx () { | |
123 | MSG=$1 | |
124 | test_expect_success "check normal git operations: $MSG" ' | |
125 | midx_git_two_modes "rev-list --objects --all" && | |
e9ab2ed7 DS |
126 | midx_git_two_modes "log --raw" && |
127 | midx_git_two_modes "count-objects --verbose" && | |
5670ad98 JK |
128 | midx_git_two_modes "cat-file --batch-all-objects --batch-check" && |
129 | midx_git_two_modes "cat-file --batch-all-objects --batch-check --unordered" sorted | |
c4d25228 DS |
130 | ' |
131 | } | |
132 | ||
2c381335 | 133 | test_expect_success 'write midx with one v2 pack' ' |
c4d25228 DS |
134 | git pack-objects --index-version=2,0x40 $objdir/pack/test <obj-list && |
135 | git multi-pack-index --object-dir=$objdir write && | |
136 | midx_read_expect 1 18 4 $objdir | |
2c381335 DS |
137 | ' |
138 | ||
c4d25228 DS |
139 | compare_results_with_midx "one v2 pack" |
140 | ||
c8a45eb6 | 141 | test_expect_success 'corrupt idx reports errors' ' |
fc789156 JK |
142 | idx=$(test-tool read-midx $objdir | grep "\.idx\$") && |
143 | mv $objdir/pack/$idx backup-$idx && | |
144 | test_when_finished "mv backup-\$idx \$objdir/pack/\$idx" && | |
145 | ||
146 | # This is the minimum size for a sha-1 based .idx; this lets | |
147 | # us pass perfunctory tests, but anything that actually opens and reads | |
148 | # the idx file will complain. | |
149 | test_copy_bytes 1064 <backup-$idx >$objdir/pack/$idx && | |
150 | ||
151 | git -c core.multiPackIndex=true rev-list --objects --all 2>err && | |
c8a45eb6 | 152 | grep "index unavailable" err |
fc789156 JK |
153 | ' |
154 | ||
2c381335 DS |
155 | test_expect_success 'add more objects' ' |
156 | for i in $(test_seq 6 10) | |
157 | do | |
d0fd9931 | 158 | generate_objects $i || return 1 |
2c381335 DS |
159 | done && |
160 | commit_and_list_objects | |
161 | ' | |
162 | ||
163 | test_expect_success 'write midx with two packs' ' | |
c4d25228 DS |
164 | git pack-objects --index-version=1 $objdir/pack/test-2 <obj-list && |
165 | git multi-pack-index --object-dir=$objdir write && | |
166 | midx_read_expect 2 34 4 $objdir | |
2c381335 DS |
167 | ' |
168 | ||
c4d25228 DS |
169 | compare_results_with_midx "two packs" |
170 | ||
6fb22ca4 TB |
171 | test_expect_success 'write midx with --stdin-packs' ' |
172 | rm -fr $objdir/pack/multi-pack-index && | |
173 | ||
174 | idx="$(find $objdir/pack -name "test-2-*.idx")" && | |
175 | basename "$idx" >in && | |
176 | ||
177 | git multi-pack-index write --stdin-packs <in && | |
178 | ||
179 | test-tool read-midx $objdir | grep "\.idx$" >packs && | |
180 | ||
181 | test_cmp packs in | |
182 | ' | |
183 | ||
184 | compare_results_with_midx "mixed mode (one pack + extra)" | |
185 | ||
680cba2c WB |
186 | test_expect_success 'write progress off for redirected stderr' ' |
187 | git multi-pack-index --object-dir=$objdir write 2>err && | |
188 | test_line_count = 0 err | |
189 | ' | |
190 | ||
191 | test_expect_success 'write force progress on for stderr' ' | |
0394f8d0 | 192 | GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir write --progress 2>err && |
680cba2c WB |
193 | test_file_not_empty err |
194 | ' | |
195 | ||
196 | test_expect_success 'write with the --no-progress option' ' | |
0394f8d0 | 197 | GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir write --no-progress 2>err && |
680cba2c WB |
198 | test_line_count = 0 err |
199 | ' | |
200 | ||
2c381335 DS |
201 | test_expect_success 'add more packs' ' |
202 | for j in $(test_seq 11 20) | |
203 | do | |
204 | generate_objects $j && | |
205 | commit_and_list_objects && | |
d0fd9931 | 206 | git pack-objects --index-version=2 $objdir/pack/test-pack <obj-list || return 1 |
2c381335 DS |
207 | done |
208 | ' | |
209 | ||
c4d25228 DS |
210 | compare_results_with_midx "mixed mode (two packs + extra)" |
211 | ||
2c381335 | 212 | test_expect_success 'write midx with twelve packs' ' |
c4d25228 DS |
213 | git multi-pack-index --object-dir=$objdir write && |
214 | midx_read_expect 12 74 4 $objdir | |
662148c4 DS |
215 | ' |
216 | ||
c4d25228 DS |
217 | compare_results_with_midx "twelve packs" |
218 | ||
426c00e4 TB |
219 | test_expect_success 'multi-pack-index *.rev cleanup with --object-dir' ' |
220 | git init repo && | |
221 | git clone -s repo alternate && | |
222 | ||
223 | test_when_finished "rm -rf repo alternate" && | |
224 | ||
225 | ( | |
226 | cd repo && | |
227 | test_commit base && | |
228 | git repack -d | |
229 | ) && | |
230 | ||
231 | ours="alternate/.git/objects/pack/multi-pack-index-123.rev" && | |
232 | theirs="repo/.git/objects/pack/multi-pack-index-abc.rev" && | |
233 | touch "$ours" "$theirs" && | |
234 | ||
235 | ( | |
236 | cd alternate && | |
237 | git multi-pack-index --object-dir ../repo/.git/objects write | |
238 | ) && | |
239 | ||
240 | # writing a midx in "repo" should not remove the .rev file in the | |
241 | # alternate | |
242 | test_path_is_file repo/.git/objects/pack/multi-pack-index && | |
243 | test_path_is_file $ours && | |
244 | test_path_is_missing $theirs | |
245 | ' | |
246 | ||
d9607542 DS |
247 | test_expect_success 'warn on improper hash version' ' |
248 | git init --object-format=sha1 sha1 && | |
249 | ( | |
250 | cd sha1 && | |
251 | git config core.multiPackIndex true && | |
252 | test_commit 1 && | |
253 | git repack -a && | |
254 | git multi-pack-index write && | |
255 | mv .git/objects/pack/multi-pack-index ../mpi-sha1 | |
256 | ) && | |
257 | git init --object-format=sha256 sha256 && | |
258 | ( | |
259 | cd sha256 && | |
260 | git config core.multiPackIndex true && | |
261 | test_commit 1 && | |
262 | git repack -a && | |
263 | git multi-pack-index write && | |
264 | mv .git/objects/pack/multi-pack-index ../mpi-sha256 | |
265 | ) && | |
266 | ( | |
267 | cd sha1 && | |
268 | mv ../mpi-sha256 .git/objects/pack/multi-pack-index && | |
269 | git log -1 2>err && | |
270 | test_i18ngrep "multi-pack-index hash version 2 does not match version 1" err | |
271 | ) && | |
272 | ( | |
273 | cd sha256 && | |
274 | mv ../mpi-sha1 .git/objects/pack/multi-pack-index && | |
275 | git log -1 2>err && | |
276 | test_i18ngrep "multi-pack-index hash version 1 does not match version 2" err | |
277 | ) | |
278 | ' | |
279 | ||
9218c6a4 TB |
280 | test_expect_success 'midx picks objects from preferred pack' ' |
281 | test_when_finished rm -rf preferred.git && | |
282 | git init --bare preferred.git && | |
283 | ( | |
284 | cd preferred.git && | |
285 | ||
286 | a=$(echo "a" | git hash-object -w --stdin) && | |
287 | b=$(echo "b" | git hash-object -w --stdin) && | |
288 | c=$(echo "c" | git hash-object -w --stdin) && | |
289 | ||
290 | # Set up two packs, duplicating the object "B" at different | |
291 | # offsets. | |
292 | # | |
293 | # Note that the "BC" pack (the one we choose as preferred) sorts | |
294 | # lexically after the "AB" pack, meaning that omitting the | |
295 | # --preferred-pack argument would cause this test to fail (since | |
296 | # the MIDX code would select the copy of "b" in the "AB" pack). | |
297 | git pack-objects objects/pack/test-AB <<-EOF && | |
298 | $a | |
299 | $b | |
300 | EOF | |
301 | bc=$(git pack-objects objects/pack/test-BC <<-EOF | |
302 | $b | |
303 | $c | |
304 | EOF | |
305 | ) && | |
306 | ||
307 | git multi-pack-index --object-dir=objects \ | |
308 | write --preferred-pack=test-BC-$bc.idx 2>err && | |
309 | test_must_be_empty err && | |
310 | ||
311 | test-tool read-midx --show-objects objects >out && | |
312 | ||
313 | ofs=$(git show-index <objects/pack/test-BC-$bc.idx | grep $b | | |
314 | cut -d" " -f1) && | |
315 | printf "%s %s\tobjects/pack/test-BC-%s.pack\n" \ | |
316 | "$b" "$ofs" "$bc" >expect && | |
317 | grep ^$b out >actual && | |
318 | ||
319 | test_cmp expect actual | |
320 | ) | |
321 | ' | |
d9607542 | 322 | |
5d3cd09a TB |
323 | test_expect_success 'preferred packs must be non-empty' ' |
324 | test_when_finished rm -rf preferred.git && | |
325 | git init preferred.git && | |
326 | ( | |
327 | cd preferred.git && | |
328 | ||
329 | test_commit base && | |
330 | git repack -ad && | |
331 | ||
332 | empty="$(git pack-objects $objdir/pack/pack </dev/null)" && | |
333 | ||
334 | test_must_fail git multi-pack-index write \ | |
335 | --preferred-pack=pack-$empty.pack 2>err && | |
336 | grep "with no objects" err | |
337 | ) | |
338 | ' | |
339 | ||
56ee7ff1 DS |
340 | test_expect_success 'verify multi-pack-index success' ' |
341 | git multi-pack-index verify --object-dir=$objdir | |
342 | ' | |
343 | ||
680cba2c WB |
344 | test_expect_success 'verify progress off for redirected stderr' ' |
345 | git multi-pack-index verify --object-dir=$objdir 2>err && | |
346 | test_line_count = 0 err | |
347 | ' | |
348 | ||
349 | test_expect_success 'verify force progress on for stderr' ' | |
350 | git multi-pack-index verify --object-dir=$objdir --progress 2>err && | |
351 | test_file_not_empty err | |
352 | ' | |
353 | ||
354 | test_expect_success 'verify with the --no-progress option' ' | |
355 | git multi-pack-index verify --object-dir=$objdir --no-progress 2>err && | |
356 | test_line_count = 0 err | |
357 | ' | |
358 | ||
53ad0407 DS |
359 | # usage: corrupt_midx_and_verify <pos> <data> <objdir> <string> |
360 | corrupt_midx_and_verify() { | |
361 | POS=$1 && | |
362 | DATA="${2:-\0}" && | |
363 | OBJDIR=$3 && | |
364 | GREPSTR="$4" && | |
66ec0390 DS |
365 | COMMAND="$5" && |
366 | if test -z "$COMMAND" | |
367 | then | |
368 | COMMAND="git multi-pack-index verify --object-dir=$OBJDIR" | |
369 | fi && | |
53ad0407 DS |
370 | FILE=$OBJDIR/pack/multi-pack-index && |
371 | chmod a+w $FILE && | |
372 | test_when_finished mv midx-backup $FILE && | |
373 | cp $FILE midx-backup && | |
374 | printf "$DATA" | dd of="$FILE" bs=1 seek="$POS" conv=notrunc && | |
66ec0390 | 375 | test_must_fail $COMMAND 2>test_err && |
53ad0407 DS |
376 | grep -v "^+" test_err >err && |
377 | test_i18ngrep "$GREPSTR" err | |
378 | } | |
379 | ||
380 | test_expect_success 'verify bad signature' ' | |
381 | corrupt_midx_and_verify 0 "\00" $objdir \ | |
382 | "multi-pack-index signature" | |
383 | ' | |
384 | ||
cc6af73c | 385 | NUM_OBJECTS=74 |
53ad0407 DS |
386 | MIDX_BYTE_VERSION=4 |
387 | MIDX_BYTE_OID_VERSION=5 | |
388 | MIDX_BYTE_CHUNK_COUNT=6 | |
d3f8e211 DS |
389 | MIDX_HEADER_SIZE=12 |
390 | MIDX_BYTE_CHUNK_ID=$MIDX_HEADER_SIZE | |
391 | MIDX_BYTE_CHUNK_OFFSET=$(($MIDX_HEADER_SIZE + 4)) | |
8e72a3c3 DS |
392 | MIDX_NUM_CHUNKS=5 |
393 | MIDX_CHUNK_LOOKUP_WIDTH=12 | |
394 | MIDX_OFFSET_PACKNAMES=$(($MIDX_HEADER_SIZE + \ | |
395 | $MIDX_NUM_CHUNKS * $MIDX_CHUNK_LOOKUP_WIDTH)) | |
396 | MIDX_BYTE_PACKNAME_ORDER=$(($MIDX_OFFSET_PACKNAMES + 2)) | |
3c5e65ca | 397 | MIDX_OFFSET_OID_FANOUT=$(($MIDX_OFFSET_PACKNAMES + $(test_oid packnameoff))) |
2f23d3f3 | 398 | MIDX_OID_FANOUT_WIDTH=4 |
3c5e65ca | 399 | MIDX_BYTE_OID_FANOUT_ORDER=$((MIDX_OFFSET_OID_FANOUT + 250 * $MIDX_OID_FANOUT_WIDTH + $(test_oid fanoutoff))) |
55c5648d DS |
400 | MIDX_OFFSET_OID_LOOKUP=$(($MIDX_OFFSET_OID_FANOUT + 256 * $MIDX_OID_FANOUT_WIDTH)) |
401 | MIDX_BYTE_OID_LOOKUP=$(($MIDX_OFFSET_OID_LOOKUP + 16 * $HASH_LEN)) | |
cc6af73c DS |
402 | MIDX_OFFSET_OBJECT_OFFSETS=$(($MIDX_OFFSET_OID_LOOKUP + $NUM_OBJECTS * $HASH_LEN)) |
403 | MIDX_OFFSET_WIDTH=8 | |
404 | MIDX_BYTE_PACK_INT_ID=$(($MIDX_OFFSET_OBJECT_OFFSETS + 16 * $MIDX_OFFSET_WIDTH + 2)) | |
405 | MIDX_BYTE_OFFSET=$(($MIDX_OFFSET_OBJECT_OFFSETS + 16 * $MIDX_OFFSET_WIDTH + 6)) | |
53ad0407 DS |
406 | |
407 | test_expect_success 'verify bad version' ' | |
408 | corrupt_midx_and_verify $MIDX_BYTE_VERSION "\00" $objdir \ | |
409 | "multi-pack-index version" | |
410 | ' | |
411 | ||
412 | test_expect_success 'verify bad OID version' ' | |
d9607542 | 413 | corrupt_midx_and_verify $MIDX_BYTE_OID_VERSION "\03" $objdir \ |
53ad0407 DS |
414 | "hash version" |
415 | ' | |
416 | ||
417 | test_expect_success 'verify truncated chunk count' ' | |
418 | corrupt_midx_and_verify $MIDX_BYTE_CHUNK_COUNT "\01" $objdir \ | |
6ab3b8b8 | 419 | "final chunk has non-zero id" |
53ad0407 DS |
420 | ' |
421 | ||
422 | test_expect_success 'verify extended chunk count' ' | |
423 | corrupt_midx_and_verify $MIDX_BYTE_CHUNK_COUNT "\07" $objdir \ | |
6ab3b8b8 | 424 | "terminating chunk id appears earlier than expected" |
53ad0407 DS |
425 | ' |
426 | ||
d3f8e211 DS |
427 | test_expect_success 'verify missing required chunk' ' |
428 | corrupt_midx_and_verify $MIDX_BYTE_CHUNK_ID "\01" $objdir \ | |
429 | "missing required" | |
430 | ' | |
431 | ||
432 | test_expect_success 'verify invalid chunk offset' ' | |
433 | corrupt_midx_and_verify $MIDX_BYTE_CHUNK_OFFSET "\01" $objdir \ | |
6ab3b8b8 | 434 | "improper chunk offset(s)" |
d3f8e211 DS |
435 | ' |
436 | ||
8e72a3c3 DS |
437 | test_expect_success 'verify packnames out of order' ' |
438 | corrupt_midx_and_verify $MIDX_BYTE_PACKNAME_ORDER "z" $objdir \ | |
439 | "pack names out of order" | |
440 | ' | |
441 | ||
d4bf1d88 DS |
442 | test_expect_success 'verify packnames out of order' ' |
443 | corrupt_midx_and_verify $MIDX_BYTE_PACKNAME_ORDER "a" $objdir \ | |
444 | "failed to load pack" | |
445 | ' | |
446 | ||
2f23d3f3 DS |
447 | test_expect_success 'verify oid fanout out of order' ' |
448 | corrupt_midx_and_verify $MIDX_BYTE_OID_FANOUT_ORDER "\01" $objdir \ | |
449 | "oid fanout out of order" | |
450 | ' | |
451 | ||
55c5648d DS |
452 | test_expect_success 'verify oid lookup out of order' ' |
453 | corrupt_midx_and_verify $MIDX_BYTE_OID_LOOKUP "\00" $objdir \ | |
454 | "oid lookup out of order" | |
455 | ' | |
456 | ||
cc6af73c DS |
457 | test_expect_success 'verify incorrect pack-int-id' ' |
458 | corrupt_midx_and_verify $MIDX_BYTE_PACK_INT_ID "\07" $objdir \ | |
459 | "bad pack-int-id" | |
460 | ' | |
461 | ||
462 | test_expect_success 'verify incorrect offset' ' | |
235d3cdd | 463 | corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \ |
cc6af73c DS |
464 | "incorrect object offset" |
465 | ' | |
466 | ||
66ec0390 | 467 | test_expect_success 'git-fsck incorrect offset' ' |
235d3cdd | 468 | corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \ |
66ec0390 | 469 | "incorrect object offset" \ |
dc557087 GC |
470 | "git -c core.multiPackIndex=true fsck" && |
471 | test_unconfig core.multiPackIndex && | |
472 | test_must_fail git fsck && | |
473 | git -c core.multiPackIndex=false fsck | |
66ec0390 DS |
474 | ' |
475 | ||
ec1e28ef TB |
476 | test_expect_success 'corrupt MIDX is not reused' ' |
477 | corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \ | |
478 | "incorrect object offset" && | |
479 | git multi-pack-index write 2>err && | |
480 | test_i18ngrep checksum.mismatch err && | |
481 | git multi-pack-index verify | |
482 | ' | |
483 | ||
f89ecf79 | 484 | test_expect_success 'verify incorrect checksum' ' |
152923b1 JK |
485 | pos=$(($(wc -c <$objdir/pack/multi-pack-index) - 10)) && |
486 | corrupt_midx_and_verify $pos \ | |
487 | "\377\377\377\377\377\377\377\377\377\377" \ | |
488 | $objdir "incorrect checksum" | |
f89ecf79 TB |
489 | ' |
490 | ||
680cba2c | 491 | test_expect_success 'repack progress off for redirected stderr' ' |
efdd2f0d | 492 | GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack 2>err && |
680cba2c WB |
493 | test_line_count = 0 err |
494 | ' | |
495 | ||
496 | test_expect_success 'repack force progress on for stderr' ' | |
0394f8d0 | 497 | GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack --progress 2>err && |
680cba2c WB |
498 | test_file_not_empty err |
499 | ' | |
500 | ||
501 | test_expect_success 'repack with the --no-progress option' ' | |
0394f8d0 | 502 | GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack --no-progress 2>err && |
680cba2c WB |
503 | test_line_count = 0 err |
504 | ' | |
505 | ||
e08f7bb0 | 506 | test_expect_success 'repack removes multi-pack-index when deleting packs' ' |
525e18c0 | 507 | test_path_is_file $objdir/pack/multi-pack-index && |
e08f7bb0 TB |
508 | # Set GIT_TEST_MULTI_PACK_INDEX to 0 to avoid writing a new |
509 | # multi-pack-index after repacking, but set "core.multiPackIndex" to | |
510 | # true so that "git repack" can read the existing MIDX. | |
511 | GIT_TEST_MULTI_PACK_INDEX=0 git -c core.multiPackIndex repack -adf && | |
525e18c0 DS |
512 | test_path_is_missing $objdir/pack/multi-pack-index |
513 | ' | |
514 | ||
e08f7bb0 TB |
515 | test_expect_success 'repack preserves multi-pack-index when creating packs' ' |
516 | git init preserve && | |
517 | test_when_finished "rm -fr preserve" && | |
518 | ( | |
519 | cd preserve && | |
520 | packdir=.git/objects/pack && | |
521 | midx=$packdir/multi-pack-index && | |
522 | ||
523 | test_commit 1 && | |
524 | pack1=$(git pack-objects --all $packdir/pack) && | |
525 | touch $packdir/pack-$pack1.keep && | |
526 | test_commit 2 && | |
527 | pack2=$(git pack-objects --revs $packdir/pack) && | |
528 | touch $packdir/pack-$pack2.keep && | |
529 | ||
530 | git multi-pack-index write && | |
531 | cp $midx $midx.bak && | |
532 | ||
533 | cat >pack-input <<-EOF && | |
534 | HEAD | |
535 | ^HEAD~1 | |
536 | EOF | |
537 | test_commit 3 && | |
538 | pack3=$(git pack-objects --revs $packdir/pack <pack-input) && | |
539 | test_commit 4 && | |
540 | pack4=$(git pack-objects --revs $packdir/pack <pack-input) && | |
541 | ||
542 | GIT_TEST_MULTI_PACK_INDEX=0 git -c core.multiPackIndex repack -ad && | |
543 | ls -la $packdir && | |
544 | test_path_is_file $packdir/pack-$pack1.pack && | |
545 | test_path_is_file $packdir/pack-$pack2.pack && | |
546 | test_path_is_missing $packdir/pack-$pack3.pack && | |
547 | test_path_is_missing $packdir/pack-$pack4.pack && | |
548 | test_cmp_bin $midx.bak $midx | |
549 | ) | |
550 | ' | |
551 | ||
525e18c0 DS |
552 | compare_results_with_midx "after repack" |
553 | ||
e9ab2ed7 | 554 | test_expect_success 'multi-pack-index and pack-bitmap' ' |
e255a5e8 TB |
555 | GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \ |
556 | git -c repack.writeBitmaps=true repack -ad && | |
e9ab2ed7 DS |
557 | git multi-pack-index write && |
558 | git rev-list --test-bitmap HEAD | |
559 | ' | |
560 | ||
29e2016b DS |
561 | test_expect_success 'multi-pack-index and alternates' ' |
562 | git init --bare alt.git && | |
563 | echo $(pwd)/alt.git/objects >.git/objects/info/alternates && | |
564 | echo content1 >file1 && | |
565 | altblob=$(GIT_DIR=alt.git git hash-object -w file1) && | |
566 | git cat-file blob $altblob && | |
567 | git rev-list --all | |
568 | ' | |
569 | ||
570 | compare_results_with_midx "with alternate (local midx)" | |
571 | ||
572 | test_expect_success 'multi-pack-index in an alternate' ' | |
6a22d521 DS |
573 | mv .git/objects/pack/* alt.git/objects/pack && |
574 | test_commit add_local_objects && | |
575 | git repack --local && | |
576 | git multi-pack-index write && | |
577 | midx_read_expect 1 3 4 $objdir && | |
578 | git reset --hard HEAD~1 && | |
579 | rm -f .git/objects/pack/* | |
29e2016b DS |
580 | ' |
581 | ||
582 | compare_results_with_midx "with alternate (remote midx)" | |
583 | ||
662148c4 DS |
584 | # usage: corrupt_data <file> <pos> [<data>] |
585 | corrupt_data () { | |
586 | file=$1 | |
587 | pos=$2 | |
588 | data="${3:-\0}" | |
589 | printf "$data" | dd of="$file" bs=1 seek="$pos" conv=notrunc | |
590 | } | |
591 | ||
592 | # Force 64-bit offsets by manipulating the idx file. | |
593 | # This makes the IDX file _incorrect_ so be careful to clean up after! | |
594 | test_expect_success 'force some 64-bit offsets with pack-objects' ' | |
595 | mkdir objects64 && | |
596 | mkdir objects64/pack && | |
597 | for i in $(test_seq 1 11) | |
598 | do | |
d0fd9931 | 599 | generate_objects 11 || return 1 |
662148c4 DS |
600 | done && |
601 | commit_and_list_objects && | |
602 | pack64=$(git pack-objects --index-version=2,0x40 objects64/pack/test-64 <obj-list) && | |
603 | idx64=objects64/pack/test-64-$pack64.idx && | |
604 | chmod u+w $idx64 && | |
3c5e65ca | 605 | corrupt_data $idx64 $(test_oid idxoff) "\02" && |
f57a7396 TB |
606 | # objects64 is not a real repository, but can serve as an alternate |
607 | # anyway so we can write a MIDX into it | |
608 | git init repo && | |
609 | test_when_finished "rm -fr repo" && | |
610 | ( | |
611 | cd repo && | |
612 | ( cd ../objects64 && pwd ) >.git/objects/info/alternates && | |
613 | midx64=$(git multi-pack-index --object-dir=../objects64 write) | |
614 | ) && | |
662148c4 | 615 | midx_read_expect 1 63 5 objects64 " large-offsets" |
2c381335 DS |
616 | ' |
617 | ||
56ee7ff1 DS |
618 | test_expect_success 'verify multi-pack-index with 64-bit offsets' ' |
619 | git multi-pack-index verify --object-dir=objects64 | |
620 | ' | |
621 | ||
cc6af73c DS |
622 | NUM_OBJECTS=63 |
623 | MIDX_OFFSET_OID_FANOUT=$((MIDX_OFFSET_PACKNAMES + 54)) | |
624 | MIDX_OFFSET_OID_LOOKUP=$((MIDX_OFFSET_OID_FANOUT + 256 * $MIDX_OID_FANOUT_WIDTH)) | |
625 | MIDX_OFFSET_OBJECT_OFFSETS=$(($MIDX_OFFSET_OID_LOOKUP + $NUM_OBJECTS * $HASH_LEN)) | |
626 | MIDX_OFFSET_LARGE_OFFSETS=$(($MIDX_OFFSET_OBJECT_OFFSETS + $NUM_OBJECTS * $MIDX_OFFSET_WIDTH)) | |
627 | MIDX_BYTE_LARGE_OFFSET=$(($MIDX_OFFSET_LARGE_OFFSETS + 3)) | |
628 | ||
629 | test_expect_success 'verify incorrect 64-bit offset' ' | |
630 | corrupt_midx_and_verify $MIDX_BYTE_LARGE_OFFSET "\07" objects64 \ | |
631 | "incorrect object offset" | |
632 | ' | |
633 | ||
cff97116 DS |
634 | test_expect_success 'setup expire tests' ' |
635 | mkdir dup && | |
636 | ( | |
637 | cd dup && | |
638 | git init && | |
639 | test-tool genrandom "data" 4096 >large_file.txt && | |
640 | git update-index --add large_file.txt && | |
641 | for i in $(test_seq 1 20) | |
642 | do | |
d0fd9931 | 643 | test_commit $i || exit 1 |
cff97116 DS |
644 | done && |
645 | git branch A HEAD && | |
646 | git branch B HEAD~8 && | |
647 | git branch C HEAD~13 && | |
648 | git branch D HEAD~16 && | |
649 | git branch E HEAD~18 && | |
650 | git pack-objects --revs .git/objects/pack/pack-A <<-EOF && | |
651 | refs/heads/A | |
652 | ^refs/heads/B | |
653 | EOF | |
654 | git pack-objects --revs .git/objects/pack/pack-B <<-EOF && | |
655 | refs/heads/B | |
656 | ^refs/heads/C | |
657 | EOF | |
658 | git pack-objects --revs .git/objects/pack/pack-C <<-EOF && | |
659 | refs/heads/C | |
660 | ^refs/heads/D | |
661 | EOF | |
662 | git pack-objects --revs .git/objects/pack/pack-D <<-EOF && | |
663 | refs/heads/D | |
664 | ^refs/heads/E | |
665 | EOF | |
666 | git pack-objects --revs .git/objects/pack/pack-E <<-EOF && | |
667 | refs/heads/E | |
668 | EOF | |
2af890bb DS |
669 | git multi-pack-index write && |
670 | cp -r .git/objects/pack .git/objects/pack-backup | |
cff97116 DS |
671 | ) |
672 | ' | |
673 | ||
674 | test_expect_success 'expire does not remove any packs' ' | |
675 | ( | |
676 | cd dup && | |
677 | ls .git/objects/pack >expect && | |
678 | git multi-pack-index expire && | |
679 | ls .git/objects/pack >actual && | |
680 | test_cmp expect actual | |
681 | ) | |
682 | ' | |
683 | ||
680cba2c WB |
684 | test_expect_success 'expire progress off for redirected stderr' ' |
685 | ( | |
686 | cd dup && | |
687 | git multi-pack-index expire 2>err && | |
688 | test_line_count = 0 err | |
689 | ) | |
690 | ' | |
691 | ||
692 | test_expect_success 'expire force progress on for stderr' ' | |
693 | ( | |
694 | cd dup && | |
0394f8d0 | 695 | GIT_PROGRESS_DELAY=0 git multi-pack-index expire --progress 2>err && |
680cba2c WB |
696 | test_file_not_empty err |
697 | ) | |
698 | ' | |
699 | ||
700 | test_expect_success 'expire with the --no-progress option' ' | |
701 | ( | |
702 | cd dup && | |
0394f8d0 | 703 | GIT_PROGRESS_DELAY=0 git multi-pack-index expire --no-progress 2>err && |
680cba2c WB |
704 | test_line_count = 0 err |
705 | ) | |
706 | ' | |
707 | ||
19575c7c DS |
708 | test_expect_success 'expire removes unreferenced packs' ' |
709 | ( | |
710 | cd dup && | |
711 | git pack-objects --revs .git/objects/pack/pack-combined <<-EOF && | |
712 | refs/heads/A | |
713 | ^refs/heads/C | |
714 | EOF | |
715 | git multi-pack-index write && | |
716 | ls .git/objects/pack | grep -v -e pack-[AB] >expect && | |
717 | git multi-pack-index expire && | |
718 | ls .git/objects/pack >actual && | |
719 | test_cmp expect actual && | |
720 | ls .git/objects/pack/ | grep idx >expect-idx && | |
721 | test-tool read-midx .git/objects | grep idx >actual-midx && | |
722 | test_cmp expect-idx actual-midx && | |
723 | git multi-pack-index verify && | |
724 | git fsck | |
725 | ) | |
726 | ' | |
727 | ||
2af890bb DS |
728 | test_expect_success 'repack with minimum size does not alter existing packs' ' |
729 | ( | |
730 | cd dup && | |
731 | rm -rf .git/objects/pack && | |
732 | mv .git/objects/pack-backup .git/objects/pack && | |
e892a568 DS |
733 | test-tool chmtime =-5 .git/objects/pack/pack-D* && |
734 | test-tool chmtime =-4 .git/objects/pack/pack-C* && | |
735 | test-tool chmtime =-3 .git/objects/pack/pack-B* && | |
736 | test-tool chmtime =-2 .git/objects/pack/pack-A* && | |
2af890bb | 737 | ls .git/objects/pack >expect && |
3612c233 | 738 | MINSIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 1) && |
2af890bb DS |
739 | git multi-pack-index repack --batch-size=$MINSIZE && |
740 | ls .git/objects/pack >actual && | |
741 | test_cmp expect actual | |
742 | ) | |
743 | ' | |
744 | ||
3ce4ca0a DS |
745 | test_expect_success 'repack respects repack.packKeptObjects=false' ' |
746 | test_when_finished rm -f dup/.git/objects/pack/*keep && | |
747 | ( | |
748 | cd dup && | |
749 | ls .git/objects/pack/*idx >idx-list && | |
750 | test_line_count = 5 idx-list && | |
751 | ls .git/objects/pack/*.pack | sed "s/\.pack/.keep/" >keep-list && | |
752 | test_line_count = 5 keep-list && | |
753 | for keep in $(cat keep-list) | |
754 | do | |
755 | touch $keep || return 1 | |
756 | done && | |
757 | git multi-pack-index repack --batch-size=0 && | |
758 | ls .git/objects/pack/*idx >idx-list && | |
759 | test_line_count = 5 idx-list && | |
760 | test-tool read-midx .git/objects | grep idx >midx-list && | |
761 | test_line_count = 5 midx-list && | |
762 | THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | sed -n 3p) && | |
763 | BATCH_SIZE=$((THIRD_SMALLEST_SIZE + 1)) && | |
764 | git multi-pack-index repack --batch-size=$BATCH_SIZE && | |
765 | ls .git/objects/pack/*idx >idx-list && | |
766 | test_line_count = 5 idx-list && | |
767 | test-tool read-midx .git/objects | grep idx >midx-list && | |
768 | test_line_count = 5 midx-list | |
769 | ) | |
770 | ' | |
771 | ||
ce1e4a10 DS |
772 | test_expect_success 'repack creates a new pack' ' |
773 | ( | |
774 | cd dup && | |
775 | ls .git/objects/pack/*idx >idx-list && | |
776 | test_line_count = 5 idx-list && | |
3612c233 | 777 | THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 3 | tail -n 1) && |
ce1e4a10 DS |
778 | BATCH_SIZE=$(($THIRD_SMALLEST_SIZE + 1)) && |
779 | git multi-pack-index repack --batch-size=$BATCH_SIZE && | |
780 | ls .git/objects/pack/*idx >idx-list && | |
781 | test_line_count = 6 idx-list && | |
782 | test-tool read-midx .git/objects | grep idx >midx-list && | |
783 | test_line_count = 6 midx-list | |
784 | ) | |
785 | ' | |
786 | ||
d9f77214 TB |
787 | test_expect_success 'repack (all) ignores cruft pack' ' |
788 | git init repo && | |
789 | test_when_finished "rm -fr repo" && | |
790 | ( | |
791 | cd repo && | |
792 | ||
793 | test_commit base && | |
794 | test_commit --no-tag unreachable && | |
795 | ||
796 | git reset --hard base && | |
797 | git reflog expire --all --expire=all && | |
798 | git repack --cruft -d && | |
799 | ||
800 | git multi-pack-index write && | |
801 | ||
802 | find $objdir/pack | sort >before && | |
803 | git multi-pack-index repack --batch-size=0 && | |
804 | find $objdir/pack | sort >after && | |
805 | ||
806 | test_cmp before after | |
807 | ) | |
808 | ' | |
809 | ||
b62ad568 TB |
810 | test_expect_success 'repack (--batch-size) ignores cruft pack' ' |
811 | git init repo && | |
812 | test_when_finished "rm -fr repo" && | |
813 | ( | |
814 | cd repo && | |
815 | ||
816 | test_commit_bulk 5 && | |
817 | test_commit --no-tag unreachable && | |
818 | ||
819 | git reset --hard HEAD^ && | |
820 | git reflog expire --all --expire=all && | |
821 | git repack --cruft -d && | |
822 | ||
823 | test_commit four && | |
824 | ||
825 | find $objdir/pack -type f -name "*.pack" | sort >before && | |
826 | git repack -d && | |
827 | find $objdir/pack -type f -name "*.pack" | sort >after && | |
828 | ||
829 | pack="$(comm -13 before after)" && | |
830 | test_file_size "$pack" >sz && | |
831 | # Set --batch-size to twice the size of the pack created | |
832 | # in the previous step, since this is enough to | |
833 | # accommodate it and the cruft pack. | |
834 | # | |
835 | # This means that the MIDX machinery *could* combine the | |
836 | # new and cruft packs together. | |
837 | # | |
838 | # We ensure that it does not below. | |
839 | batch="$((($(cat sz) * 2)))" && | |
840 | ||
841 | git multi-pack-index write && | |
842 | ||
843 | find $objdir/pack | sort >before && | |
844 | git multi-pack-index repack --batch-size=$batch && | |
845 | find $objdir/pack | sort >after && | |
846 | ||
847 | test_cmp before after | |
848 | ) | |
849 | ' | |
850 | ||
ce1e4a10 DS |
851 | test_expect_success 'expire removes repacked packs' ' |
852 | ( | |
853 | cd dup && | |
854 | ls -al .git/objects/pack/*pack && | |
855 | ls -S .git/objects/pack/*pack | head -n 4 >expect && | |
856 | git multi-pack-index expire && | |
857 | ls -S .git/objects/pack/*pack >actual && | |
858 | test_cmp expect actual && | |
859 | test-tool read-midx .git/objects | grep idx >midx-list && | |
860 | test_line_count = 4 midx-list | |
861 | ) | |
862 | ' | |
863 | ||
d2743315 DS |
864 | test_expect_success 'expire works when adding new packs' ' |
865 | ( | |
866 | cd dup && | |
867 | git pack-objects --revs .git/objects/pack/pack-combined <<-EOF && | |
868 | refs/heads/A | |
869 | ^refs/heads/B | |
870 | EOF | |
871 | git pack-objects --revs .git/objects/pack/pack-combined <<-EOF && | |
872 | refs/heads/B | |
873 | ^refs/heads/C | |
874 | EOF | |
875 | git pack-objects --revs .git/objects/pack/pack-combined <<-EOF && | |
876 | refs/heads/C | |
877 | ^refs/heads/D | |
878 | EOF | |
879 | git multi-pack-index write && | |
880 | git pack-objects --revs .git/objects/pack/a-pack <<-EOF && | |
881 | refs/heads/D | |
882 | ^refs/heads/E | |
883 | EOF | |
884 | git multi-pack-index write && | |
885 | git pack-objects --revs .git/objects/pack/z-pack <<-EOF && | |
886 | refs/heads/E | |
887 | EOF | |
888 | git multi-pack-index expire && | |
889 | ls .git/objects/pack/ | grep idx >expect && | |
890 | test-tool read-midx .git/objects | grep idx >actual && | |
891 | test_cmp expect actual && | |
892 | git multi-pack-index verify | |
893 | ) | |
894 | ' | |
895 | ||
10bfa3f7 DS |
896 | test_expect_success 'expire respects .keep files' ' |
897 | ( | |
898 | cd dup && | |
899 | git pack-objects --revs .git/objects/pack/pack-all <<-EOF && | |
900 | refs/heads/A | |
901 | EOF | |
902 | git multi-pack-index write && | |
903 | PACKA=$(ls .git/objects/pack/a-pack*\.pack | sed s/\.pack\$//) && | |
904 | touch $PACKA.keep && | |
905 | git multi-pack-index expire && | |
35a8a354 TB |
906 | test_path_is_file $PACKA.idx && |
907 | test_path_is_file $PACKA.keep && | |
908 | test_path_is_file $PACKA.pack && | |
10bfa3f7 DS |
909 | test-tool read-midx .git/objects | grep idx >midx-list && |
910 | test_line_count = 2 midx-list | |
911 | ) | |
912 | ' | |
913 | ||
757d4579 TB |
914 | test_expect_success 'expiring unreferenced cruft pack retains pack' ' |
915 | git init repo && | |
916 | test_when_finished "rm -fr repo" && | |
917 | ( | |
918 | cd repo && | |
919 | ||
920 | test_commit base && | |
921 | test_commit --no-tag unreachable && | |
922 | unreachable=$(git rev-parse HEAD) && | |
923 | ||
924 | git reset --hard base && | |
925 | git reflog expire --all --expire=all && | |
926 | git repack --cruft -d && | |
927 | mtimes="$(ls $objdir/pack/pack-*.mtimes)" && | |
928 | ||
929 | echo "base..$unreachable" >in && | |
930 | pack="$(git pack-objects --revs --delta-base-offset \ | |
931 | $objdir/pack/pack <in)" && | |
932 | ||
933 | # Preferring the contents of "$pack" will leave the | |
934 | # cruft pack unreferenced (ie., none of the objects | |
935 | # contained in the cruft pack will have their MIDX copy | |
936 | # selected from the cruft pack). | |
937 | git multi-pack-index write --preferred-pack="pack-$pack.pack" && | |
938 | git multi-pack-index expire && | |
939 | ||
940 | test_path_is_file "$mtimes" | |
941 | ) | |
942 | ' | |
943 | ||
b526d8cb | 944 | test_expect_success 'repack --batch-size=0 repacks everything' ' |
1eb22c7d | 945 | cp -r dup dup2 && |
b526d8cb DS |
946 | ( |
947 | cd dup && | |
948 | rm .git/objects/pack/*.keep && | |
949 | ls .git/objects/pack/*idx >idx-list && | |
950 | test_line_count = 2 idx-list && | |
951 | git multi-pack-index repack --batch-size=0 && | |
952 | ls .git/objects/pack/*idx >idx-list && | |
953 | test_line_count = 3 idx-list && | |
954 | test-tool read-midx .git/objects | grep idx >midx-list && | |
955 | test_line_count = 3 midx-list && | |
956 | git multi-pack-index expire && | |
957 | ls -al .git/objects/pack/*idx >idx-list && | |
958 | test_line_count = 1 idx-list && | |
959 | git multi-pack-index repack --batch-size=0 && | |
960 | ls -al .git/objects/pack/*idx >new-idx-list && | |
961 | test_cmp idx-list new-idx-list | |
962 | ) | |
963 | ' | |
10bfa3f7 | 964 | |
1eb22c7d DS |
965 | test_expect_success 'repack --batch-size=<large> repacks everything' ' |
966 | ( | |
967 | cd dup2 && | |
968 | rm .git/objects/pack/*.keep && | |
969 | ls .git/objects/pack/*idx >idx-list && | |
970 | test_line_count = 2 idx-list && | |
971 | git multi-pack-index repack --batch-size=2000000 && | |
972 | ls .git/objects/pack/*idx >idx-list && | |
973 | test_line_count = 3 idx-list && | |
974 | test-tool read-midx .git/objects | grep idx >midx-list && | |
975 | test_line_count = 3 midx-list && | |
976 | git multi-pack-index expire && | |
977 | ls -al .git/objects/pack/*idx >idx-list && | |
978 | test_line_count = 1 idx-list | |
979 | ) | |
980 | ' | |
981 | ||
506ec2fb | 982 | test_expect_success 'load reverse index when missing .idx, .pack' ' |
c8a45eb6 TB |
983 | git init repo && |
984 | test_when_finished "rm -fr repo" && | |
985 | ( | |
986 | cd repo && | |
987 | ||
988 | git config core.multiPackIndex true && | |
989 | ||
990 | test_commit base && | |
991 | git repack -ad && | |
992 | git multi-pack-index write && | |
993 | ||
994 | git rev-parse HEAD >tip && | |
506ec2fb | 995 | pack=$(ls .git/objects/pack/pack-*.pack) && |
c8a45eb6 TB |
996 | idx=$(ls .git/objects/pack/pack-*.idx) && |
997 | ||
998 | mv $idx $idx.bak && | |
506ec2fb TB |
999 | git cat-file --batch-check="%(objectsize:disk)" <tip && |
1000 | ||
1001 | mv $idx.bak $idx && | |
1002 | ||
1003 | mv $pack $pack.bak && | |
c8a45eb6 TB |
1004 | git cat-file --batch-check="%(objectsize:disk)" <tip |
1005 | ) | |
1006 | ' | |
1007 | ||
88617d11 TB |
1008 | test_expect_success 'usage shown without sub-command' ' |
1009 | test_expect_code 129 git multi-pack-index 2>err && | |
1010 | ! test_i18ngrep "unrecognized subcommand" err | |
1011 | ' | |
1012 | ||
73ff4ad0 TB |
1013 | test_expect_success 'complains when run outside of a repository' ' |
1014 | nongit test_must_fail git multi-pack-index write 2>err && | |
1015 | grep "not a git repository" err | |
1016 | ' | |
1017 | ||
a3407730 | 1018 | test_done |