]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5300-pack-object.sh
Merge branch 'gc/branch-recurse-submodules-fix'
[thirdparty/git.git] / t / t5300-pack-object.sh
CommitLineData
8ee378a0
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
3604e7c5 6test_description='git pack-object
8ee378a0
JH
7
8'
9. ./test-lib.sh
10
54898998
JK
11test_expect_success 'setup' '
12 rm -f .git/index* &&
13 perl -e "print \"a\" x 4096;" >a &&
14 perl -e "print \"b\" x 4096;" >b &&
15 perl -e "print \"c\" x 4096;" >c &&
16 test-tool genrandom "seed a" 2097152 >a_big &&
17 test-tool genrandom "seed b" 2097152 >b_big &&
18 git update-index --add a a_big b b_big c &&
19 cat c >d && echo foo >>d && git update-index --add d &&
20 tree=$(git write-tree) &&
21 commit=$(git commit-tree $tree </dev/null) &&
22 {
23 echo $tree &&
24 echo $commit &&
25 git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
26 } >obj-list &&
27 {
28 git diff-tree --root -p $commit &&
29 while read object
30 do
31 t=$(git cat-file -t $object) &&
32 git cat-file $t $object || return 1
33 done <obj-list
34 } >expect
35'
8ee378a0 36
fb20d4b1
ÆAB
37test_expect_success 'setup pack-object <stdin' '
38 git init pack-object-stdin &&
39 test_commit -C pack-object-stdin one &&
40 test_commit -C pack-object-stdin two
41
42'
43
44test_expect_success 'pack-object <stdin parsing: basic [|--revs]' '
45 cat >in <<-EOF &&
46 $(git -C pack-object-stdin rev-parse one)
47 EOF
48
49 git -C pack-object-stdin pack-objects basic-stdin <in &&
50 idx=$(echo pack-object-stdin/basic-stdin-*.idx) &&
51 git show-index <"$idx" >actual &&
52 test_line_count = 1 actual &&
53
54 git -C pack-object-stdin pack-objects --revs basic-stdin-revs <in &&
55 idx=$(echo pack-object-stdin/basic-stdin-revs-*.idx) &&
56 git show-index <"$idx" >actual &&
57 test_line_count = 3 actual
58'
59
60test_expect_success 'pack-object <stdin parsing: [|--revs] bad line' '
61 cat >in <<-EOF &&
62 $(git -C pack-object-stdin rev-parse one)
63 garbage
64 $(git -C pack-object-stdin rev-parse two)
65 EOF
66
67 sed "s/^> //g" >err.expect <<-EOF &&
68 fatal: expected object ID, got garbage:
69 > garbage
70
71 EOF
72 test_must_fail git -C pack-object-stdin pack-objects bad-line-stdin <in 2>err.actual &&
73 test_cmp err.expect err.actual &&
74
75 cat >err.expect <<-EOF &&
76 fatal: bad revision '"'"'garbage'"'"'
77 EOF
78 test_must_fail git -C pack-object-stdin pack-objects --revs bad-line-stdin-revs <in 2>err.actual &&
79 test_cmp err.expect err.actual
80'
81
82test_expect_success 'pack-object <stdin parsing: [|--revs] empty line' '
83 cat >in <<-EOF &&
84 $(git -C pack-object-stdin rev-parse one)
85
86 $(git -C pack-object-stdin rev-parse two)
87 EOF
88
89 sed -e "s/^> //g" -e "s/Z$//g" >err.expect <<-EOF &&
90 fatal: expected object ID, got garbage:
91 > Z
92
93 EOF
94 test_must_fail git -C pack-object-stdin pack-objects empty-line-stdin <in 2>err.actual &&
95 test_cmp err.expect err.actual &&
96
97 git -C pack-object-stdin pack-objects --revs empty-line-stdin-revs <in &&
98 idx=$(echo pack-object-stdin/empty-line-stdin-revs-*.idx) &&
99 git show-index <"$idx" >actual &&
100 test_line_count = 3 actual
101'
102
103test_expect_success 'pack-object <stdin parsing: [|--revs] with --stdin' '
104 cat >in <<-EOF &&
105 $(git -C pack-object-stdin rev-parse one)
106 $(git -C pack-object-stdin rev-parse two)
107 EOF
108
109 # There is the "--stdin-packs is incompatible with --revs"
110 # test below, but we should make sure that the revision.c
111 # --stdin is not picked up
112 cat >err.expect <<-EOF &&
113 fatal: disallowed abbreviated or ambiguous option '"'"'stdin'"'"'
114 EOF
115 test_must_fail git -C pack-object-stdin pack-objects stdin-with-stdin-option --stdin <in 2>err.actual &&
116 test_cmp err.expect err.actual &&
117
118 test_must_fail git -C pack-object-stdin pack-objects --stdin --revs stdin-with-stdin-option-revs 2>err.actual <in &&
119 test_cmp err.expect err.actual
120'
121
561fa035
ÆAB
122test_expect_success 'pack-object <stdin parsing: --stdin-packs handles garbage' '
123 cat >in <<-EOF &&
124 $(git -C pack-object-stdin rev-parse one)
125 $(git -C pack-object-stdin rev-parse two)
126 EOF
127
128 # That we get "two" and not "one" has to do with OID
129 # ordering. It happens to be the same here under SHA-1 and
130 # SHA-256. See commentary in pack-objects.c
131 cat >err.expect <<-EOF &&
132 fatal: could not find pack '"'"'$(git -C pack-object-stdin rev-parse two)'"'"'
133 EOF
134 test_must_fail git \
135 -C pack-object-stdin \
136 pack-objects stdin-with-stdin-option --stdin-packs \
137 <in 2>err.actual &&
138 test_cmp err.expect err.actual
139'
140
95356789
JK
141# usage: check_deltas <stderr_from_pack_objects> <cmp_op> <nr_deltas>
142# e.g.: check_deltas stderr -gt 0
143check_deltas() {
144 deltas=$(perl -lne '/delta (\d+)/ and print $1' "$1") &&
145 shift &&
146 if ! test "$deltas" "$@"
147 then
148 echo >&2 "unexpected number of deltas (compared $delta $*)"
149 return 1
150 fi
151}
152
54898998 153test_expect_success 'pack without delta' '
95356789
JK
154 packname_1=$(git pack-objects --progress --window=0 test-1 \
155 <obj-list 2>stderr) &&
156 check_deltas stderr = 0
54898998 157'
8ee378a0 158
54898998
JK
159test_expect_success 'pack-objects with bogus arguments' '
160 test_must_fail git pack-objects --window=0 test-1 blah blah <obj-list
161'
8ee378a0 162
54898998
JK
163check_unpack () {
164 test_when_finished "rm -rf git2" &&
165 git init --bare git2 &&
166 git -C git2 unpack-objects -n <"$1".pack &&
167 git -C git2 unpack-objects <"$1".pack &&
168 (cd .git && find objects -type f -print) |
169 while read path
170 do
171 cmp git2/$path .git/$path || {
172 echo $path differs.
173 return 1
174 }
175 done
176}
177
178test_expect_success 'unpack without delta' '
179 check_unpack test-1-${packname_1}
180'
8ee378a0 181
54898998 182test_expect_success 'pack with REF_DELTA' '
95356789
JK
183 packname_2=$(git pack-objects --progress test-2 <obj-list 2>stderr) &&
184 check_deltas stderr -gt 0
54898998 185'
8ee378a0 186
54898998
JK
187test_expect_success 'unpack with REF_DELTA' '
188 check_unpack test-2-${packname_2}
189'
ac527b0b 190
54898998 191test_expect_success 'pack with OFS_DELTA' '
95356789
JK
192 packname_3=$(git pack-objects --progress --delta-base-offset test-3 \
193 <obj-list 2>stderr) &&
194 check_deltas stderr -gt 0
54898998 195'
ac527b0b 196
54898998
JK
197test_expect_success 'unpack with OFS_DELTA' '
198 check_unpack test-3-${packname_3}
199'
ac527b0b 200
d93f7c18 201test_expect_success 'compare delta flavors' '
94221d22 202 perl -e '\''
d93f7c18
AL
203 defined($_ = -s $_) or die for @ARGV;
204 exit 1 if $ARGV[0] <= $ARGV[1];
205 '\'' test-2-$packname_2.pack test-3-$packname_3.pack
206'
ac527b0b 207
54898998
JK
208check_use_objects () {
209 test_when_finished "rm -rf git2" &&
210 git init --bare git2 &&
211 cp "$1".pack "$1".idx git2/objects/pack &&
212 (
213 cd git2 &&
214 git diff-tree --root -p $commit &&
215 while read object
216 do
217 t=$(git cat-file -t $object) &&
218 git cat-file $t $object || exit 1
219 done
220 ) <obj-list >current &&
221 cmp expect current
222}
223
224test_expect_success 'use packed objects' '
225 check_use_objects test-1-${packname_1}
226'
1f688557 227
54898998
JK
228test_expect_success 'use packed deltified (REF_DELTA) objects' '
229 check_use_objects test-2-${packname_2}
230'
1f688557 231
54898998
JK
232test_expect_success 'use packed deltified (OFS_DELTA) objects' '
233 check_use_objects test-3-${packname_3}
234'
f9253394 235
6e180cdc
JH
236test_expect_success 'survive missing objects/pack directory' '
237 (
238 rm -fr missing-pack &&
239 mkdir missing-pack &&
240 cd missing-pack &&
241 git init &&
51b85471 242 GOP=.git/objects/pack &&
6e180cdc
JH
243 rm -fr $GOP &&
244 git index-pack --stdin --keep=test <../test-3-${packname_3}.pack &&
245 test -f $GOP/pack-${packname_3}.pack &&
ce1a0473 246 cmp $GOP/pack-${packname_3}.pack ../test-3-${packname_3}.pack &&
6e180cdc 247 test -f $GOP/pack-${packname_3}.idx &&
ce1a0473 248 cmp $GOP/pack-${packname_3}.idx ../test-3-${packname_3}.idx &&
6e180cdc
JH
249 test -f $GOP/pack-${packname_3}.keep
250 )
251'
252
f9253394
JH
253test_expect_success \
254 'verify pack' \
5be60078 255 'git verify-pack test-1-${packname_1}.idx \
ac527b0b
NP
256 test-2-${packname_2}.idx \
257 test-3-${packname_3}.idx'
f9253394 258
4b480c67
NP
259test_expect_success \
260 'verify pack -v' \
261 'git verify-pack -v test-1-${packname_1}.idx \
262 test-2-${packname_2}.idx \
263 test-3-${packname_3}.idx'
264
f9253394 265test_expect_success \
63405283 266 'verify-pack catches mismatched .idx and .pack files' \
a5878961
JH
267 'cat test-1-${packname_1}.idx >test-3.idx &&
268 cat test-2-${packname_2}.pack >test-3.pack &&
5be60078 269 if git verify-pack test-3.idx
f9253394
JH
270 then false
271 else :;
63405283 272 fi'
f9253394 273
63405283
JS
274test_expect_success \
275 'verify-pack catches a corrupted pack signature' \
276 'cat test-1-${packname_1}.pack >test-3.pack &&
b689ccf6 277 echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=2 &&
5be60078 278 if git verify-pack test-3.idx
f9253394
JH
279 then false
280 else :;
63405283 281 fi'
f9253394 282
63405283
JS
283test_expect_success \
284 'verify-pack catches a corrupted pack version' \
285 'cat test-1-${packname_1}.pack >test-3.pack &&
b689ccf6 286 echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=7 &&
5be60078 287 if git verify-pack test-3.idx
f9253394
JH
288 then false
289 else :;
63405283 290 fi'
f9253394 291
63405283
JS
292test_expect_success \
293 'verify-pack catches a corrupted type/size of the 1st packed object data' \
294 'cat test-1-${packname_1}.pack >test-3.pack &&
b689ccf6 295 echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=12 &&
5be60078 296 if git verify-pack test-3.idx
f9253394
JH
297 then false
298 else :;
63405283 299 fi'
f9253394 300
63405283
JS
301test_expect_success \
302 'verify-pack catches a corrupted sum of the index file itself' \
d6cd9ac9
EP
303 'l=$(wc -c <test-3.idx) &&
304 l=$(expr $l - 20) &&
a5878961 305 cat test-1-${packname_1}.pack >test-3.pack &&
b689ccf6 306 printf "%20s" "" | dd of=test-3.idx count=20 bs=1 conv=notrunc seek=$l &&
5be60078 307 if git verify-pack test-3.pack
c5ced645
JH
308 then false
309 else :;
63405283 310 fi'
f9253394 311
9cf6d335
SV
312test_expect_success \
313 'build pack index for an existing pack' \
a5878961 314 'cat test-1-${packname_1}.pack >test-3.pack &&
3604e7c5 315 git index-pack -o tmp.idx test-3.pack &&
9cf6d335
SV
316 cmp tmp.idx test-1-${packname_1}.idx &&
317
1f52cdfa 318 git index-pack --promisor=message test-3.pack &&
9cf6d335 319 cmp test-3.idx test-1-${packname_1}.idx &&
1f52cdfa
DS
320 echo message >expect &&
321 test_cmp expect test-3.promisor &&
9cf6d335 322
a5878961 323 cat test-2-${packname_2}.pack >test-3.pack &&
3604e7c5 324 git index-pack -o tmp.idx test-2-${packname_2}.pack &&
9cf6d335
SV
325 cmp tmp.idx test-2-${packname_2}.idx &&
326
3604e7c5 327 git index-pack test-3.pack &&
9cf6d335
SV
328 cmp test-3.idx test-2-${packname_2}.idx &&
329
a5878961 330 cat test-3-${packname_3}.pack >test-3.pack &&
3604e7c5 331 git index-pack -o tmp.idx test-3-${packname_3}.pack &&
ac527b0b
NP
332 cmp tmp.idx test-3-${packname_3}.idx &&
333
3604e7c5 334 git index-pack test-3.pack &&
ac527b0b
NP
335 cmp test-3.idx test-3-${packname_3}.idx &&
336
0e94242d
JH
337 cat test-1-${packname_1}.pack >test-4.pack &&
338 rm -f test-4.keep &&
339 git index-pack --keep=why test-4.pack &&
340 cmp test-1-${packname_1}.idx test-4.idx &&
341 test -f test-4.keep &&
342
9cf6d335
SV
343 :'
344
f2898cfa 345test_expect_success 'unpacking with --strict' '
c0e809e5 346
c0e809e5
JH
347 for j in a b c d e f g
348 do
349 for i in 0 1 2 3 4 5 6 7 8 9
350 do
351 o=$(echo $j$i | git hash-object -w --stdin) &&
d0fd9931 352 echo "100644 $o 0 $j$i" || return 1
c0e809e5
JH
353 done
354 done >LIST &&
355 rm -f .git/index &&
356 git update-index --index-info <LIST &&
357 LIST=$(git write-tree) &&
358 rm -f .git/index &&
359 head -n 10 LIST | git update-index --index-info &&
360 LI=$(git write-tree) &&
361 rm -f .git/index &&
362 tail -n 10 LIST | git update-index --index-info &&
363 ST=$(git write-tree) &&
a4d4e32a
PK
364 git rev-list --objects "$LIST" "$LI" "$ST" >actual &&
365 PACK5=$( git pack-objects test-5 <actual ) &&
08495412 366 PACK6=$( test_write_lines "$LIST" "$LI" "$ST" | git pack-objects test-6 ) &&
c0e809e5
JH
367 test_create_repo test-5 &&
368 (
369 cd test-5 &&
370 git unpack-objects --strict <../test-5-$PACK5.pack &&
371 git ls-tree -r $LIST &&
372 git ls-tree -r $LI &&
373 git ls-tree -r $ST
374 ) &&
375 test_create_repo test-6 &&
376 (
377 # tree-only into empty repo -- many unreachables
378 cd test-6 &&
379 test_must_fail git unpack-objects --strict <../test-6-$PACK6.pack
380 ) &&
381 (
382 # already populated -- no unreachables
383 cd test-5 &&
384 git unpack-objects --strict <../test-6-$PACK6.pack
385 )
386'
387
38a5739d
MK
388test_expect_success 'index-pack with --strict' '
389
390 for j in a b c d e f g
391 do
392 for i in 0 1 2 3 4 5 6 7 8 9
393 do
394 o=$(echo $j$i | git hash-object -w --stdin) &&
d0fd9931 395 echo "100644 $o 0 $j$i" || return 1
38a5739d
MK
396 done
397 done >LIST &&
398 rm -f .git/index &&
399 git update-index --index-info <LIST &&
400 LIST=$(git write-tree) &&
401 rm -f .git/index &&
402 head -n 10 LIST | git update-index --index-info &&
403 LI=$(git write-tree) &&
404 rm -f .git/index &&
405 tail -n 10 LIST | git update-index --index-info &&
406 ST=$(git write-tree) &&
a4d4e32a
PK
407 git rev-list --objects "$LIST" "$LI" "$ST" >actual &&
408 PACK5=$( git pack-objects test-5 <actual ) &&
08495412 409 PACK6=$( test_write_lines "$LIST" "$LI" "$ST" | git pack-objects test-6 ) &&
38a5739d
MK
410 test_create_repo test-7 &&
411 (
412 cd test-7 &&
413 git index-pack --strict --stdin <../test-5-$PACK5.pack &&
414 git ls-tree -r $LIST &&
415 git ls-tree -r $LI &&
416 git ls-tree -r $ST
417 ) &&
418 test_create_repo test-8 &&
419 (
420 # tree-only into empty repo -- many unreachables
421 cd test-8 &&
422 test_must_fail git index-pack --strict --stdin <../test-6-$PACK6.pack
423 ) &&
424 (
425 # already populated -- no unreachables
426 cd test-7 &&
427 git index-pack --strict --stdin <../test-6-$PACK6.pack
428 )
429'
430
2fca19fb 431test_expect_success 'honor pack.packSizeLimit' '
07cf0f24 432 git config pack.packSizeLimit 3m &&
2fca19fb 433 packname_10=$(git pack-objects test-10 <obj-list) &&
07cf0f24 434 test 2 = $(ls test-10-*.pack | wc -l)
2fca19fb
NP
435'
436
437test_expect_success 'verify resulting packs' '
438 git verify-pack test-10-*.pack
439'
440
07cf0f24
NP
441test_expect_success 'tolerate packsizelimit smaller than biggest object' '
442 git config pack.packSizeLimit 1 &&
2fca19fb 443 packname_11=$(git pack-objects test-11 <obj-list) &&
720c9f7b 444 test 5 = $(ls test-11-*.pack | wc -l)
a1e4760f
NP
445'
446
2fca19fb
NP
447test_expect_success 'verify resulting packs' '
448 git verify-pack test-11-*.pack
449'
450
7176a314
JK
451test_expect_success 'set up pack for non-repo tests' '
452 # make sure we have a pack with no matching index file
453 cp test-1-*.pack foo.pack
454'
455
456test_expect_success 'index-pack --stdin complains of non-repo' '
371c4079 457 nongit test_must_fail git index-pack --object-format=$(test_oid algo) --stdin <foo.pack &&
7176a314
JK
458 test_path_is_missing non-repo/.git
459'
460
461test_expect_success 'index-pack <pack> works in non-repo' '
371c4079 462 nongit git index-pack --object-format=$(test_oid algo) ../foo.pack &&
7176a314
JK
463 test_path_is_file foo.idx
464'
465
14a9bd28
JK
466test_expect_success 'index-pack --strict <pack> works in non-repo' '
467 rm -f foo.idx &&
371c4079 468 nongit git index-pack --strict --object-format=$(test_oid algo) ../foo.pack &&
14a9bd28
JK
469 test_path_is_file foo.idx
470'
471
27d578d9
JK
472test_expect_success !PTHREADS,!FAIL_PREREQS \
473 'index-pack --threads=N or pack.threads=N warns when no pthreads' '
967a3eaf
ÆAB
474 test_must_fail git index-pack --threads=2 2>err &&
475 grep ^warning: err >warnings &&
476 test_line_count = 1 warnings &&
477 grep -F "no threads support, ignoring --threads=2" err &&
478
479 test_must_fail git -c pack.threads=2 index-pack 2>err &&
480 grep ^warning: err >warnings &&
481 test_line_count = 1 warnings &&
482 grep -F "no threads support, ignoring pack.threads" err &&
483
484 test_must_fail git -c pack.threads=2 index-pack --threads=4 2>err &&
485 grep ^warning: err >warnings &&
486 test_line_count = 2 warnings &&
487 grep -F "no threads support, ignoring --threads=4" err &&
488 grep -F "no threads support, ignoring pack.threads" err
489'
490
27d578d9
JK
491test_expect_success !PTHREADS,!FAIL_PREREQS \
492 'pack-objects --threads=N or pack.threads=N warns when no pthreads' '
967a3eaf
ÆAB
493 git pack-objects --threads=2 --stdout --all </dev/null >/dev/null 2>err &&
494 grep ^warning: err >warnings &&
495 test_line_count = 1 warnings &&
496 grep -F "no threads support, ignoring --threads" err &&
497
498 git -c pack.threads=2 pack-objects --stdout --all </dev/null >/dev/null 2>err &&
499 grep ^warning: err >warnings &&
2e96d815 500 test_line_count = 1 warnings &&
967a3eaf
ÆAB
501 grep -F "no threads support, ignoring pack.threads" err &&
502
503 git -c pack.threads=2 pack-objects --threads=4 --stdout --all </dev/null >/dev/null 2>err &&
504 grep ^warning: err >warnings &&
505 test_line_count = 2 warnings &&
506 grep -F "no threads support, ignoring --threads" err &&
507 grep -F "no threads support, ignoring pack.threads" err
508'
509
43fa44fa
NTND
510test_expect_success 'pack-objects in too-many-packs mode' '
511 GIT_TEST_FULL_IN_PACK_ARRAY=1 git repack -ad &&
512 git fsck
513'
514
228135d9
ÆAB
515test_expect_success 'setup: fake a SHA1 hash collision' '
516 git init corrupt &&
517 (
518 cd corrupt &&
519 long_a=$(git hash-object -w ../a | sed -e "s!^..!&/!") &&
520 long_b=$(git hash-object -w ../b | sed -e "s!^..!&/!") &&
521 test -f .git/objects/$long_b &&
522 cp -f .git/objects/$long_a \
523 .git/objects/$long_b
524 )
80938c39 525'
2fca19fb 526
80938c39 527test_expect_success 'make sure index-pack detects the SHA1 collision' '
228135d9
ÆAB
528 (
529 cd corrupt &&
530 test_must_fail git index-pack -o ../bad.idx ../test-3.pack 2>msg &&
531 test_i18ngrep "SHA1 COLLISION FOUND" msg
532 )
80938c39 533'
2fca19fb 534
80938c39 535test_expect_success 'make sure index-pack detects the SHA1 collision (large blobs)' '
228135d9
ÆAB
536 (
537 cd corrupt &&
538 test_must_fail git -c core.bigfilethreshold=1 index-pack -o ../bad.idx ../test-3.pack 2>msg &&
539 test_i18ngrep "SHA1 COLLISION FOUND" msg
540 )
80938c39 541'
4614043c 542
e00549aa
JT
543test_expect_success 'prefetch objects' '
544 rm -rf server client &&
545
546 git init server &&
547 test_config -C server uploadpack.allowanysha1inwant 1 &&
548 test_config -C server uploadpack.allowfilter 1 &&
549 test_config -C server protocol.version 2 &&
550
551 echo one >server/one &&
552 git -C server add one &&
553 git -C server commit -m one &&
554 git -C server branch one_branch &&
555
556 echo two_a >server/two_a &&
557 echo two_b >server/two_b &&
558 git -C server add two_a two_b &&
559 git -C server commit -m two &&
560
561 echo three >server/three &&
562 git -C server add three &&
563 git -C server commit -m three &&
564 git -C server branch three_branch &&
565
566 # Clone, fetch "two" with blobs excluded, and re-push it. This requires
567 # the client to have the blobs of "two" - verify that these are
568 # prefetched in one batch.
569 git clone --filter=blob:none --single-branch -b one_branch \
570 "file://$(pwd)/server" client &&
571 test_config -C client protocol.version 2 &&
572 TWO=$(git -C server rev-parse three_branch^) &&
573 git -C client fetch --filter=blob:none origin "$TWO" &&
574 GIT_TRACE_PACKET=$(pwd)/trace git -C client push origin "$TWO":refs/heads/two_branch &&
7ca3c0ac 575 grep "fetch> done" trace >donelines &&
e00549aa
JT
576 test_line_count = 1 donelines
577'
578
339bce27
TB
579test_expect_success 'setup for --stdin-packs tests' '
580 git init stdin-packs &&
581 (
582 cd stdin-packs &&
583
584 test_commit A &&
585 test_commit B &&
586 test_commit C &&
587
588 for id in A B C
589 do
590 git pack-objects .git/objects/pack/pack-$id \
d0fd9931 591 --incremental --revs <<-EOF || exit 1
339bce27
TB
592 refs/tags/$id
593 EOF
594 done &&
595
596 ls -la .git/objects/pack
597 )
598'
599
600test_expect_success '--stdin-packs with excluded packs' '
601 (
602 cd stdin-packs &&
603
604 PACK_A="$(basename .git/objects/pack/pack-A-*.pack)" &&
605 PACK_B="$(basename .git/objects/pack/pack-B-*.pack)" &&
606 PACK_C="$(basename .git/objects/pack/pack-C-*.pack)" &&
607
608 git pack-objects test --stdin-packs <<-EOF &&
609 $PACK_A
610 ^$PACK_B
611 $PACK_C
612 EOF
613
614 (
615 git show-index <$(ls .git/objects/pack/pack-A-*.idx) &&
616 git show-index <$(ls .git/objects/pack/pack-C-*.idx)
617 ) >expect.raw &&
618 git show-index <$(ls test-*.idx) >actual.raw &&
619
620 cut -d" " -f2 <expect.raw | sort >expect &&
621 cut -d" " -f2 <actual.raw | sort >actual &&
622 test_cmp expect actual
623 )
624'
625
626test_expect_success '--stdin-packs is incompatible with --filter' '
627 (
628 cd stdin-packs &&
629 test_must_fail git pack-objects --stdin-packs --stdout \
630 --filter=blob:none </dev/null 2>err &&
631 test_i18ngrep "cannot use --filter with --stdin-packs" err
632 )
633'
634
635test_expect_success '--stdin-packs is incompatible with --revs' '
636 (
637 cd stdin-packs &&
638 test_must_fail git pack-objects --stdin-packs --revs out \
639 </dev/null 2>err &&
640 test_i18ngrep "cannot use internal rev list with --stdin-packs" err
641 )
642'
643
644test_expect_success '--stdin-packs with loose objects' '
645 (
646 cd stdin-packs &&
647
648 PACK_A="$(basename .git/objects/pack/pack-A-*.pack)" &&
649 PACK_B="$(basename .git/objects/pack/pack-B-*.pack)" &&
650 PACK_C="$(basename .git/objects/pack/pack-C-*.pack)" &&
651
652 test_commit D && # loose
653
654 git pack-objects test2 --stdin-packs --unpacked <<-EOF &&
655 $PACK_A
656 ^$PACK_B
657 $PACK_C
658 EOF
659
660 (
661 git show-index <$(ls .git/objects/pack/pack-A-*.idx) &&
662 git show-index <$(ls .git/objects/pack/pack-C-*.idx) &&
663 git rev-list --objects --no-object-names \
664 refs/tags/C..refs/tags/D
665
666 ) >expect.raw &&
667 ls -la . &&
668 git show-index <$(ls test2-*.idx) >actual.raw &&
669
670 cut -d" " -f2 <expect.raw | sort >expect &&
671 cut -d" " -f2 <actual.raw | sort >actual &&
672 test_cmp expect actual
673 )
674'
675
14e7b834
TB
676test_expect_success '--stdin-packs with broken links' '
677 (
678 cd stdin-packs &&
679
680 # make an unreachable object with a bogus parent
681 git cat-file -p HEAD >commit &&
682 sed "s/$(git rev-parse HEAD^)/$(test_oid zero)/" <commit |
683 git hash-object -w -t commit --stdin >in &&
684
685 git pack-objects .git/objects/pack/pack-D <in &&
686
687 PACK_A="$(basename .git/objects/pack/pack-A-*.pack)" &&
688 PACK_B="$(basename .git/objects/pack/pack-B-*.pack)" &&
689 PACK_C="$(basename .git/objects/pack/pack-C-*.pack)" &&
690 PACK_D="$(basename .git/objects/pack/pack-D-*.pack)" &&
691
692 git pack-objects test3 --stdin-packs --unpacked <<-EOF &&
693 $PACK_A
694 ^$PACK_B
695 $PACK_C
696 $PACK_D
697 EOF
698
699 (
700 git show-index <$(ls .git/objects/pack/pack-A-*.idx) &&
701 git show-index <$(ls .git/objects/pack/pack-C-*.idx) &&
702 git show-index <$(ls .git/objects/pack/pack-D-*.idx) &&
703 git rev-list --objects --no-object-names \
704 refs/tags/C..refs/tags/D
705 ) >expect.raw &&
706 git show-index <$(ls test3-*.idx) >actual.raw &&
707
708 cut -d" " -f2 <expect.raw | sort >expect &&
709 cut -d" " -f2 <actual.raw | sort >actual &&
710 test_cmp expect actual
711 )
712'
713
953aa54e
JK
714test_expect_success 'negative window clamps to 0' '
715 git pack-objects --progress --window=-1 neg-window <obj-list 2>stderr &&
716 check_deltas stderr = 0
717'
718
8ee378a0 719test_done