interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t5300-pack-object.sh

769 lines · 23861 bytes Raw Blame History
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='git pack-object'
7
8. ./test-lib.sh
9
10test_expect_success 'setup' '
11 rm -f .git/index* &&
12 test-tool genzeros 4096 | tr "\000" "a" >a &&
13 test-tool genzeros 4096 | tr "\000" "b" >b &&
14 test-tool genzeros 4096 | tr "\000" "c" >c &&
15 test-tool genrandom "seed a" 2097152 >a_big &&
16 test-tool genrandom "seed b" 2097152 >b_big &&
17 git update-index --add a a_big b b_big c &&
18 cat c >d && echo foo >>d && git update-index --add d &&
19 tree=$(git write-tree) &&
20 commit=$(git commit-tree $tree </dev/null) &&
21 {
22 echo $tree &&
23 echo $commit &&
24 git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
25 } >obj-list &&
26 {
27 git diff-tree --root -p $commit &&
28 while read object
29 do
30 t=$(git cat-file -t $object) &&
31 git cat-file $t $object || return 1
32 done <obj-list
33 } >expect
34'
35
36test_expect_success 'pack-object traces bytes written to stdout' '
37 test_when_finished "rm -f pack.trace pack.pack" &&
38 GIT_TRACE2_EVENT="$PWD/pack.trace" \
39 git pack-objects --quiet --revs --stdout >pack.pack <<-EOF &&
40 $commit
41 EOF
42 bytes=$(test_file_size pack.pack) &&
43 test_grep "\"key\":\"write_pack_file/wrote_bytes\",\"value\":\"$bytes\"" pack.trace
44'
45
46test_expect_success 'pack-object traces bytes written to split pack files' '
47 test_when_finished "rm -f split.trace traced-pack-*" &&
48 GIT_TRACE2_EVENT="$PWD/split.trace" \
49 git -c pack.packSizeLimit=3m pack-objects --quiet traced-pack <obj-list &&
50 test 2 = $(ls traced-pack-*.pack | wc -l) &&
51 bytes=0 &&
52 for pack in traced-pack-*.pack
53 do
54 pack_size=$(test_file_size "$pack") &&
55 bytes=$((bytes + pack_size)) || return 1
56 done &&
57 test_grep "\"key\":\"write_pack_file/wrote_bytes\",\"value\":\"$bytes\"" split.trace
58'
59
60test_expect_success 'setup pack-object <stdin' '
61 git init pack-object-stdin &&
62 test_commit -C pack-object-stdin one &&
63 test_commit -C pack-object-stdin two
64
65'
66
67test_expect_success 'pack-object <stdin parsing: basic [|--revs]' '
68 cat >in <<-EOF &&
69 $(git -C pack-object-stdin rev-parse one)
70 EOF
71
72 git -C pack-object-stdin pack-objects basic-stdin <in &&
73 idx=$(echo pack-object-stdin/basic-stdin-*.idx) &&
74 git show-index <"$idx" >actual &&
75 test_line_count = 1 actual &&
76
77 git -C pack-object-stdin pack-objects --revs basic-stdin-revs <in &&
78 idx=$(echo pack-object-stdin/basic-stdin-revs-*.idx) &&
79 git show-index <"$idx" >actual &&
80 test_line_count = 3 actual
81'
82
83test_expect_success 'pack-object <stdin parsing: [|--revs] bad line' '
84 cat >in <<-EOF &&
85 $(git -C pack-object-stdin rev-parse one)
86 garbage
87 $(git -C pack-object-stdin rev-parse two)
88 EOF
89
90 sed "s/^> //g" >err.expect <<-EOF &&
91 fatal: expected object ID, got garbage:
92 > garbage
93
94 EOF
95 test_must_fail git -C pack-object-stdin pack-objects bad-line-stdin <in 2>err.actual &&
96 test_cmp err.expect err.actual &&
97
98 cat >err.expect <<-EOF &&
99 fatal: bad revision '"'"'garbage'"'"'
100 EOF
101 test_must_fail git -C pack-object-stdin pack-objects --revs bad-line-stdin-revs <in 2>err.actual &&
102 test_cmp err.expect err.actual
103'
104
105test_expect_success 'pack-object <stdin parsing: [|--revs] empty line' '
106 cat >in <<-EOF &&
107 $(git -C pack-object-stdin rev-parse one)
108
109 $(git -C pack-object-stdin rev-parse two)
110 EOF
111
112 sed -e "s/^> //g" -e "s/Z$//g" >err.expect <<-EOF &&
113 fatal: expected object ID, got garbage:
114 > Z
115
116 EOF
117 test_must_fail git -C pack-object-stdin pack-objects empty-line-stdin <in 2>err.actual &&
118 test_cmp err.expect err.actual &&
119
120 git -C pack-object-stdin pack-objects --revs empty-line-stdin-revs <in &&
121 idx=$(echo pack-object-stdin/empty-line-stdin-revs-*.idx) &&
122 git show-index <"$idx" >actual &&
123 test_line_count = 3 actual
124'
125
126test_expect_success 'pack-object <stdin parsing: [|--revs] with --stdin' '
127 cat >in <<-EOF &&
128 $(git -C pack-object-stdin rev-parse one)
129 $(git -C pack-object-stdin rev-parse two)
130 EOF
131
132 # There is the "--stdin-packs is incompatible with --revs"
133 # test below, but we should make sure that the revision.c
134 # --stdin is not picked up
135 cat >err.expect <<-EOF &&
136 fatal: disallowed abbreviated or ambiguous option '"'"'stdin'"'"'
137 EOF
138 test_must_fail git -C pack-object-stdin pack-objects stdin-with-stdin-option --stdin <in 2>err.actual &&
139 test_cmp err.expect err.actual &&
140
141 test_must_fail git -C pack-object-stdin pack-objects --stdin --revs stdin-with-stdin-option-revs 2>err.actual <in &&
142 test_cmp err.expect err.actual
143'
144
145test_expect_success 'pack-object <stdin parsing: --stdin-packs handles garbage' '
146 cat >in <<-EOF &&
147 $(git -C pack-object-stdin rev-parse one)
148 $(git -C pack-object-stdin rev-parse two)
149 EOF
150
151 # That we get "two" and not "one" has to do with OID
152 # ordering. It happens to be the same here under SHA-1 and
153 # SHA-256. See commentary in pack-objects.c
154 cat >err.expect <<-EOF &&
155 fatal: could not find pack '"'"'$(git -C pack-object-stdin rev-parse two)'"'"'
156 EOF
157 test_must_fail git \
158 -C pack-object-stdin \
159 pack-objects stdin-with-stdin-option --stdin-packs \
160 <in 2>err.actual &&
161 test_cmp err.expect err.actual
162'
163
164# usage: check_deltas <stderr_from_pack_objects> <cmp_op> <nr_deltas>
165# e.g.: check_deltas stderr -gt 0
166check_deltas() {
167 deltas=$(sed -n 's/Total [0-9][0-9]* (delta \([0-9][0-9]*\)).*/\1/p' "$1") &&
168 shift &&
169 if ! test "$deltas" "$@"
170 then
171 echo >&2 "unexpected number of deltas (compared $delta $*)"
172 return 1
173 fi
174}
175
176test_expect_success 'pack without delta' '
177 packname_1=$(git pack-objects --progress --window=0 test-1 \
178 <obj-list 2>stderr) &&
179 check_deltas stderr = 0
180'
181
182test_expect_success 'negative window clamps to 0' '
183 git pack-objects --progress --window=-1 neg-window <obj-list 2>stderr &&
184 check_deltas stderr = 0
185'
186
187test_expect_success 'pack-objects with bogus arguments' '
188 test_must_fail git pack-objects --window=0 test-1 blah blah <obj-list
189'
190
191check_unpack () {
192 local packname="$1" &&
193 local object_list="$2" &&
194 local git_config="$3" &&
195 test_when_finished "rm -rf git2" &&
196 git $git_config init --bare git2 &&
197 (
198 git $git_config -C git2 unpack-objects -n <"$packname".pack &&
199 git $git_config -C git2 unpack-objects <"$packname".pack &&
200 git $git_config -C git2 cat-file --batch-check="%(objectname)"
201 ) <"$object_list" >current &&
202 cmp "$object_list" current
203}
204
205test_expect_success 'unpack without delta' '
206 check_unpack test-1-${packname_1} obj-list
207'
208
209BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch'
210
211test_expect_success 'unpack without delta (core.fsyncmethod=batch)' '
212 check_unpack test-1-${packname_1} obj-list "$BATCH_CONFIGURATION"
213'
214
215test_expect_success 'pack with REF_DELTA' '
216 packname_2=$(git pack-objects --progress test-2 <obj-list 2>stderr) &&
217 check_deltas stderr -gt 0
218'
219
220test_expect_success 'unpack with REF_DELTA' '
221 check_unpack test-2-${packname_2} obj-list
222'
223
224test_expect_success 'unpack with REF_DELTA (core.fsyncmethod=batch)' '
225 check_unpack test-2-${packname_2} obj-list "$BATCH_CONFIGURATION"
226'
227
228test_expect_success 'pack with OFS_DELTA' '
229 packname_3=$(git pack-objects --progress --delta-base-offset test-3 \
230 <obj-list 2>stderr) &&
231 check_deltas stderr -gt 0
232'
233
234test_expect_success 'unpack with OFS_DELTA' '
235 check_unpack test-3-${packname_3} obj-list
236'
237
238test_expect_success 'unpack with OFS_DELTA (core.fsyncmethod=batch)' '
239 check_unpack test-3-${packname_3} obj-list "$BATCH_CONFIGURATION"
240'
241
242test_expect_success PERL_TEST_HELPERS 'compare delta flavors' '
243 perl -e '\''
244 defined($_ = -s $_) or die for @ARGV;
245 exit 1 if $ARGV[0] <= $ARGV[1];
246 '\'' test-2-$packname_2.pack test-3-$packname_3.pack
247'
248
249check_use_objects () {
250 test_when_finished "rm -rf git2" &&
251 git init --bare git2 &&
252 cp "$1".pack "$1".idx git2/objects/pack &&
253 (
254 cd git2 &&
255 git diff-tree --root -p $commit &&
256 while read object
257 do
258 t=$(git cat-file -t $object) &&
259 git cat-file $t $object || exit 1
260 done
261 ) <obj-list >current &&
262 cmp expect current
263}
264
265test_expect_success 'use packed objects' '
266 check_use_objects test-1-${packname_1}
267'
268
269test_expect_success 'use packed deltified (REF_DELTA) objects' '
270 check_use_objects test-2-${packname_2}
271'
272
273test_expect_success 'use packed deltified (OFS_DELTA) objects' '
274 check_use_objects test-3-${packname_3}
275'
276
277test_expect_success 'survive missing objects/pack directory' '
278 (
279 rm -fr missing-pack &&
280 mkdir missing-pack &&
281 cd missing-pack &&
282 git init &&
283 GOP=.git/objects/pack &&
284 rm -fr $GOP &&
285 git index-pack --stdin --keep=test <../test-3-${packname_3}.pack &&
286 test_path_is_file $GOP/pack-${packname_3}.pack &&
287 cmp $GOP/pack-${packname_3}.pack ../test-3-${packname_3}.pack &&
288 test_path_is_file $GOP/pack-${packname_3}.idx &&
289 cmp $GOP/pack-${packname_3}.idx ../test-3-${packname_3}.idx &&
290 test_path_is_file $GOP/pack-${packname_3}.keep
291 )
292'
293
294test_expect_success 'verify pack' '
295 git verify-pack test-1-${packname_1}.idx \
296 test-2-${packname_2}.idx \
297 test-3-${packname_3}.idx
298'
299
300test_expect_success 'verify pack -v' '
301 git verify-pack -v test-1-${packname_1}.idx \
302 test-2-${packname_2}.idx \
303 test-3-${packname_3}.idx
304'
305
306test_expect_success 'verify-pack catches mismatched .idx and .pack files' '
307 cat test-1-${packname_1}.idx >test-3.idx &&
308 cat test-2-${packname_2}.pack >test-3.pack &&
309 if git verify-pack test-3.idx
310 then false
311 else :;
312 fi
313'
314
315test_expect_success 'verify-pack catches a corrupted pack signature' '
316 cat test-1-${packname_1}.pack >test-3.pack &&
317 echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=2 &&
318 if git verify-pack test-3.idx
319 then false
320 else :;
321 fi
322'
323
324test_expect_success 'verify-pack catches a corrupted pack version' '
325 cat test-1-${packname_1}.pack >test-3.pack &&
326 echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=7 &&
327 if git verify-pack test-3.idx
328 then false
329 else :;
330 fi
331'
332
333test_expect_success 'verify-pack catches a corrupted type/size of the 1st packed object data' '
334 cat test-1-${packname_1}.pack >test-3.pack &&
335 echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=12 &&
336 if git verify-pack test-3.idx
337 then false
338 else :;
339 fi
340'
341
342test_expect_success 'verify-pack catches a corrupted sum of the index file itself' '
343 l=$(wc -c <test-3.idx) &&
344 l=$(expr $l - 20) &&
345 cat test-1-${packname_1}.pack >test-3.pack &&
346 printf "%20s" "" | dd of=test-3.idx count=20 bs=1 conv=notrunc seek=$l &&
347 if git verify-pack test-3.pack
348 then false
349 else :;
350 fi
351'
352
353test_expect_success 'build pack index for an existing pack' '
354 cat test-1-${packname_1}.pack >test-3.pack &&
355 git index-pack -o tmp.idx test-3.pack &&
356 cmp tmp.idx test-1-${packname_1}.idx &&
357
358 git index-pack test-3.pack &&
359 cmp test-3.idx test-1-${packname_1}.idx &&
360
361 cat test-2-${packname_2}.pack >test-3.pack &&
362 git index-pack -o tmp.idx test-2-${packname_2}.pack &&
363 cmp tmp.idx test-2-${packname_2}.idx &&
364
365 git index-pack test-3.pack &&
366 cmp test-3.idx test-2-${packname_2}.idx &&
367
368 cat test-3-${packname_3}.pack >test-3.pack &&
369 git index-pack -o tmp.idx test-3-${packname_3}.pack &&
370 cmp tmp.idx test-3-${packname_3}.idx &&
371
372 git index-pack test-3.pack &&
373 cmp test-3.idx test-3-${packname_3}.idx &&
374
375 cat test-1-${packname_1}.pack >test-4.pack &&
376 rm -f test-4.keep &&
377 git index-pack --keep=why test-4.pack &&
378 cmp test-1-${packname_1}.idx test-4.idx &&
379 test_path_is_file test-4.keep &&
380
381 :
382'
383
384test_expect_success 'unpacking with --strict' '
385
386 for j in a b c d e f g
387 do
388 for i in 0 1 2 3 4 5 6 7 8 9
389 do
390 o=$(echo $j$i | git hash-object -w --stdin) &&
391 echo "100644 $o 0 $j$i" || return 1
392 done
393 done >LIST &&
394 rm -f .git/index &&
395 git update-index --index-info <LIST &&
396 LIST=$(git write-tree) &&
397 rm -f .git/index &&
398 head -n 10 LIST | git update-index --index-info &&
399 LI=$(git write-tree) &&
400 rm -f .git/index &&
401 tail -n 10 LIST | git update-index --index-info &&
402 ST=$(git write-tree) &&
403 git rev-list --objects "$LIST" "$LI" "$ST" >actual &&
404 PACK5=$( git pack-objects test-5 <actual ) &&
405 PACK6=$( test_write_lines "$LIST" "$LI" "$ST" | git pack-objects test-6 ) &&
406 test_create_repo test-5 &&
407 (
408 cd test-5 &&
409 git unpack-objects --strict <../test-5-$PACK5.pack &&
410 git ls-tree -r $LIST &&
411 git ls-tree -r $LI &&
412 git ls-tree -r $ST
413 ) &&
414 test_create_repo test-6 &&
415 (
416 # tree-only into empty repo -- many unreachables
417 cd test-6 &&
418 test_must_fail git unpack-objects --strict <../test-6-$PACK6.pack
419 ) &&
420 (
421 # already populated -- no unreachables
422 cd test-5 &&
423 git unpack-objects --strict <../test-6-$PACK6.pack
424 )
425'
426
427test_expect_success 'index-pack with --strict' '
428
429 for j in a b c d e f g
430 do
431 for i in 0 1 2 3 4 5 6 7 8 9
432 do
433 o=$(echo $j$i | git hash-object -w --stdin) &&
434 echo "100644 $o 0 $j$i" || return 1
435 done
436 done >LIST &&
437 rm -f .git/index &&
438 git update-index --index-info <LIST &&
439 LIST=$(git write-tree) &&
440 rm -f .git/index &&
441 head -n 10 LIST | git update-index --index-info &&
442 LI=$(git write-tree) &&
443 rm -f .git/index &&
444 tail -n 10 LIST | git update-index --index-info &&
445 ST=$(git write-tree) &&
446 git rev-list --objects "$LIST" "$LI" "$ST" >actual &&
447 PACK5=$( git pack-objects test-5 <actual ) &&
448 PACK6=$( test_write_lines "$LIST" "$LI" "$ST" | git pack-objects test-6 ) &&
449 test_create_repo test-7 &&
450 (
451 cd test-7 &&
452 git index-pack --strict --stdin <../test-5-$PACK5.pack &&
453 git ls-tree -r $LIST &&
454 git ls-tree -r $LI &&
455 git ls-tree -r $ST
456 ) &&
457 test_create_repo test-8 &&
458 (
459 # tree-only into empty repo -- many unreachables
460 cd test-8 &&
461 test_must_fail git index-pack --strict --stdin <../test-6-$PACK6.pack
462 ) &&
463 (
464 # already populated -- no unreachables
465 cd test-7 &&
466 git index-pack --strict --stdin <../test-6-$PACK6.pack
467 )
468'
469
470test_expect_success 'setup for --strict and --fsck-objects downgrading fsck msgs' '
471 git init strict &&
472 (
473 cd strict &&
474 test_commit first hello &&
475 cat >commit <<-EOF &&
476 tree $(git rev-parse HEAD^{tree})
477 parent $(git rev-parse HEAD)
478 author A U Thor
479 committer A U Thor
480
481 commit: this is a commit with bad emails
482
483 EOF
484 git hash-object --literally -t commit -w --stdin <commit >commit_list &&
485 git pack-objects test <commit_list >pack-name
486 )
487'
488
489test_with_bad_commit () {
490 must_fail_arg="$1" &&
491 must_pass_arg="$2" &&
492 (
493 cd strict &&
494 test_must_fail git index-pack "$must_fail_arg" "test-$(cat pack-name).pack" &&
495 git index-pack "$must_pass_arg" "test-$(cat pack-name).pack"
496 )
497}
498
499test_expect_success 'index-pack with --strict downgrading fsck msgs' '
500 test_with_bad_commit --strict --strict="missingEmail=ignore"
501'
502
503test_expect_success 'index-pack with --fsck-objects downgrading fsck msgs' '
504 test_with_bad_commit --fsck-objects --fsck-objects="missingEmail=ignore"
505'
506
507test_expect_success 'cleanup for --strict and --fsck-objects downgrading fsck msgs' '
508 rm -rf strict
509'
510
511test_expect_success 'honor pack.packSizeLimit' '
512 git config pack.packSizeLimit 3m &&
513 packname_10=$(git pack-objects test-10 <obj-list) &&
514 test 2 = $(ls test-10-*.pack | wc -l)
515'
516
517test_expect_success 'verify resulting packs' '
518 git verify-pack test-10-*.pack
519'
520
521test_expect_success 'tolerate packsizelimit smaller than biggest object' '
522 git config pack.packSizeLimit 1 &&
523 packname_11=$(git pack-objects test-11 <obj-list) &&
524 test 5 = $(ls test-11-*.pack | wc -l)
525'
526
527test_expect_success 'verify resulting packs' '
528 git verify-pack test-11-*.pack
529'
530
531test_expect_success 'set up pack for non-repo tests' '
532 # make sure we have a pack with no matching index file
533 cp test-1-*.pack foo.pack
534'
535
536test_expect_success 'index-pack --stdin complains of non-repo' '
537 nongit test_must_fail git index-pack --object-format=$(test_oid algo) --stdin <foo.pack &&
538 test_path_is_missing non-repo/.git
539'
540
541test_expect_success 'index-pack <pack> works in non-repo' '
542 nongit git index-pack --object-format=$(test_oid algo) ../foo.pack &&
543 test_path_is_file foo.idx
544'
545
546test_expect_success 'index-pack --strict <pack> works in non-repo' '
547 rm -f foo.idx &&
548 nongit git index-pack --strict --object-format=$(test_oid algo) ../foo.pack &&
549 test_path_is_file foo.idx
550'
551
552test_expect_success DEFAULT_HASH_ALGORITHM 'show-index works OK outside a repository' '
553 nongit git show-index <foo.idx
554'
555
556for hash in sha1 sha256
557do
558 test_expect_success 'show-index works OK outside a repository with hash algo passed in via --object-format' '
559 test_when_finished "rm -rf explicit-hash-$hash" &&
560 git init --object-format=$hash explicit-hash-$hash &&
561 test_commit -C explicit-hash-$hash one &&
562 git -C explicit-hash-$hash rev-parse one >in &&
563 git -C explicit-hash-$hash pack-objects explicit-hash-$hash <in &&
564 idx=$(echo explicit-hash-$hash/explicit-hash-$hash*.idx) &&
565 nongit git show-index --object-format=$hash <"$idx" >actual &&
566 test_line_count = 1 actual
567 '
568done
569
570test_expect_success !PTHREADS,!FAIL_PREREQS \
571 'index-pack --threads=N or pack.threads=N warns when no pthreads' '
572 test_must_fail git index-pack --threads=2 2>err &&
573 grep ^warning: err >warnings &&
574 test_line_count = 1 warnings &&
575 test_grep -F "no threads support, ignoring --threads=2" err &&
576
577 test_must_fail git -c pack.threads=2 index-pack 2>err &&
578 grep ^warning: err >warnings &&
579 test_line_count = 1 warnings &&
580 test_grep -F "no threads support, ignoring pack.threads" err &&
581
582 test_must_fail git -c pack.threads=2 index-pack --threads=4 2>err &&
583 grep ^warning: err >warnings &&
584 test_line_count = 2 warnings &&
585 test_grep -F "no threads support, ignoring --threads=4" err &&
586 test_grep -F "no threads support, ignoring pack.threads" err
587'
588
589test_expect_success !PTHREADS,!FAIL_PREREQS \
590 'pack-objects --threads=N or pack.threads=N warns when no pthreads' '
591 git pack-objects --threads=2 --stdout --all </dev/null >/dev/null 2>err &&
592 grep ^warning: err >warnings &&
593 test_line_count = 1 warnings &&
594 test_grep -F "no threads support, ignoring --threads" err &&
595
596 git -c pack.threads=2 pack-objects --stdout --all </dev/null >/dev/null 2>err &&
597 grep ^warning: err >warnings &&
598 test_line_count = 1 warnings &&
599 test_grep -F "no threads support, ignoring pack.threads" err &&
600
601 git -c pack.threads=2 pack-objects --threads=4 --stdout --all </dev/null >/dev/null 2>err &&
602 grep ^warning: err >warnings &&
603 test_line_count = 2 warnings &&
604 test_grep -F "no threads support, ignoring --threads" err &&
605 test_grep -F "no threads support, ignoring pack.threads" err
606'
607
608test_expect_success 'pack-objects in too-many-packs mode' '
609 GIT_TEST_FULL_IN_PACK_ARRAY=1 git repack -ad &&
610 git fsck
611'
612
613test_expect_success 'setup: fake a SHA1 hash collision' '
614 git init corrupt &&
615 (
616 cd corrupt &&
617 long_a=$(git hash-object -w ../a | sed -e "s!^..!&/!") &&
618 long_b=$(git hash-object -w ../b | sed -e "s!^..!&/!") &&
619 test_path_is_file .git/objects/$long_b &&
620 cp -f .git/objects/$long_a \
621 .git/objects/$long_b
622 )
623'
624
625test_expect_success 'make sure index-pack detects the SHA1 collision' '
626 (
627 cd corrupt &&
628 test_must_fail git index-pack -o ../bad.idx ../test-3.pack 2>msg &&
629 test_grep "SHA1 COLLISION FOUND" msg
630 )
631'
632
633test_expect_success 'make sure index-pack detects the SHA1 collision (large blobs)' '
634 (
635 cd corrupt &&
636 test_must_fail git -c core.bigfilethreshold=1 index-pack -o ../bad.idx ../test-3.pack 2>msg &&
637 test_grep "SHA1 COLLISION FOUND" msg
638 )
639'
640
641test_expect_success 'prefetch objects' '
642 rm -rf server client &&
643
644 git init server &&
645 test_config -C server uploadpack.allowanysha1inwant 1 &&
646 test_config -C server uploadpack.allowfilter 1 &&
647 test_config -C server protocol.version 2 &&
648
649 echo one >server/one &&
650 git -C server add one &&
651 git -C server commit -m one &&
652 git -C server branch one_branch &&
653
654 echo two_a >server/two_a &&
655 echo two_b >server/two_b &&
656 git -C server add two_a two_b &&
657 git -C server commit -m two &&
658
659 echo three >server/three &&
660 git -C server add three &&
661 git -C server commit -m three &&
662 git -C server branch three_branch &&
663
664 # Clone, fetch "two" with blobs excluded, and re-push it. This requires
665 # the client to have the blobs of "two" - verify that these are
666 # prefetched in one batch.
667 git clone --filter=blob:none --single-branch -b one_branch \
668 "file://$(pwd)/server" client &&
669 test_config -C client protocol.version 2 &&
670 TWO=$(git -C server rev-parse three_branch^) &&
671 git -C client fetch --filter=blob:none origin "$TWO" &&
672 GIT_TRACE_PACKET=$(pwd)/trace git -C client push origin "$TWO":refs/heads/two_branch &&
673 grep "fetch> done" trace >donelines &&
674 test_line_count = 1 donelines
675'
676
677for hash in sha1 sha256
678do
679 test_expect_success "verify-pack with $hash packfile" '
680 test_when_finished "rm -rf repo" &&
681 git init --object-format=$hash repo &&
682 test_commit -C repo initial &&
683 git -C repo repack -ad &&
684 git -C repo verify-pack "$(pwd)"/repo/.git/objects/pack/*.idx &&
685 if test $hash = $GIT_TEST_BUILTIN_HASH
686 then
687 nongit git verify-pack "$(pwd)"/repo/.git/objects/pack/*.idx
688 else
689 # We have no way to identify the hash used by packfiles
690 # or indices, so we always fall back to SHA1.
691 nongit test_must_fail git verify-pack "$(pwd)"/repo/.git/objects/pack/*.idx &&
692 # But with an explicit object format we should succeed.
693 nongit git verify-pack --object-format=$hash "$(pwd)"/repo/.git/objects/pack/*.idx
694 fi
695 '
696
697 test_expect_success "index-pack outside of a $hash repository" '
698 test_when_finished "rm -rf repo" &&
699 git init --object-format=$hash repo &&
700 test_commit -C repo initial &&
701 git -C repo repack -ad &&
702 git -C repo index-pack --verify "$(pwd)"/repo/.git/objects/pack/*.pack &&
703 if test $hash = $GIT_TEST_BUILTIN_HASH
704 then
705 nongit git index-pack --verify "$(pwd)"/repo/.git/objects/pack/*.pack
706 else
707 # We have no way to identify the hash used by packfiles
708 # or indices, so we always fall back to SHA1.
709 nongit test_must_fail git index-pack --verify "$(pwd)"/repo/.git/objects/pack/*.pack 2>err &&
710 # But with an explicit object format we should succeed.
711 nongit git index-pack --object-format=$hash --verify "$(pwd)"/repo/.git/objects/pack/*.pack
712 fi
713 '
714done
715
716test_expect_success 'valid and invalid --name-hash-versions' '
717 sane_unset GIT_TEST_NAME_HASH_VERSION &&
718
719 # Valid values are hard to verify other than "do not fail".
720 # Performance tests will be more valuable to validate these versions.
721 # Negative values are converted to version 1.
722 for value in -1 1 2
723 do
724 git pack-objects base --all --name-hash-version=$value || return 1
725 done &&
726
727 # Invalid values have clear post-conditions.
728 for value in 0 3
729 do
730 test_must_fail git pack-objects base --all --name-hash-version=$value 2>err &&
731 test_grep "invalid --name-hash-version option" err || return 1
732 done
733'
734
735# The following test is not necessarily a permanent choice, but since we do not
736# have a "name hash version" bit in the .bitmap file format, we cannot write the
737# hash values into the .bitmap file without risking breakage later.
738#
739# TODO: Make these compatible in the future and replace this test with the
740# expected behavior when both are specified.
741test_expect_success '--name-hash-version=2 and --write-bitmap-index are incompatible' '
742 git pack-objects base --all --name-hash-version=2 --write-bitmap-index 2>err &&
743 test_grep "currently, --write-bitmap-index requires --name-hash-version=1" err &&
744
745 # --stdout option silently removes --write-bitmap-index
746 git pack-objects --stdout --all --name-hash-version=2 --write-bitmap-index >out 2>err &&
747 test_grep ! "currently, --write-bitmap-index requires --name-hash-version=1" err
748'
749
750test_expect_success '--path-walk pack everything' '
751 git -C server rev-parse HEAD >in &&
752 GIT_PROGRESS_DELAY=0 git -C server pack-objects \
753 --stdout --revs --path-walk --progress <in >out.pack 2>err &&
754 test_grep "Compressing objects by path" err &&
755 git -C server index-pack --stdin <out.pack
756'
757
758test_expect_success '--path-walk thin pack' '
759 cat >in <<-EOF &&
760 $(git -C server rev-parse HEAD)
761 ^$(git -C server rev-parse HEAD~2)
762 EOF
763 GIT_PROGRESS_DELAY=0 git -C server pack-objects \
764 --thin --stdout --revs --path-walk --progress <in >out.pack 2>err &&
765 test_grep "Compressing objects by path" err &&
766 git -C server index-pack --fix-thin --stdin <out.pack
767'
768
769test_done