]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5300-pack-object.sh
Merge branch 'bc/sha-256-part-2'
[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
d6cd9ac9 11TRASH=$(pwd)
8ee378a0
JH
12
13test_expect_success \
14 'setup' \
371c4079 15 'test_oid_init &&
16 rm -f .git/index* &&
94221d22
JK
17 perl -e "print \"a\" x 4096;" > a &&
18 perl -e "print \"b\" x 4096;" > b &&
19 perl -e "print \"c\" x 4096;" > c &&
c680668d
NTND
20 test-tool genrandom "seed a" 2097152 > a_big &&
21 test-tool genrandom "seed b" 2097152 > b_big &&
07cf0f24 22 git update-index --add a a_big b b_big c &&
5be60078 23 cat c >d && echo foo >>d && git update-index --add d &&
d6cd9ac9
EP
24 tree=$(git write-tree) &&
25 commit=$(git commit-tree $tree </dev/null) && {
8ee378a0 26 echo $tree &&
1f688557 27 echo $commit &&
5be60078 28 git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
1f688557 29 } >obj-list && {
5be60078 30 git diff-tree --root -p $commit &&
1f688557
JH
31 while read object
32 do
d6cd9ac9 33 t=$(git cat-file -t $object) &&
5be60078 34 git cat-file $t $object || return 1
1f688557
JH
35 done <obj-list
36 } >expect'
8ee378a0
JH
37
38test_expect_success \
39 'pack without delta' \
5be60078 40 'packname_1=$(git pack-objects --window=0 test-1 <obj-list)'
8ee378a0 41
3a2ec52e
NTND
42test_expect_success \
43 'pack-objects with bogus arguments' \
44 'test_must_fail git pack-objects --window=0 test-1 blah blah <obj-list'
45
8ee378a0
JH
46rm -fr .git2
47mkdir .git2
48
49test_expect_success \
50 'unpack without delta' \
a61eea6a 51 "GIT_OBJECT_DIRECTORY=.git2/objects &&
8ee378a0 52 export GIT_OBJECT_DIRECTORY &&
5be60078
JH
53 git init &&
54 git unpack-objects -n <test-1-${packname_1}.pack &&
55 git unpack-objects <test-1-${packname_1}.pack"
8ee378a0
JH
56
57unset GIT_OBJECT_DIRECTORY
f07a5241 58cd "$TRASH/.git2"
8ee378a0
JH
59
60test_expect_success \
61 'check unpack without delta' \
62 '(cd ../.git && find objects -type f -print) |
63 while read path
64 do
65 cmp $path ../.git/$path || {
66 echo $path differs.
4d9d62fa 67 return 1
8ee378a0
JH
68 }
69 done'
f07a5241 70cd "$TRASH"
8ee378a0
JH
71
72test_expect_success \
ac527b0b 73 'pack with REF_DELTA' \
8ee378a0 74 'pwd &&
5be60078 75 packname_2=$(git pack-objects test-2 <obj-list)'
8ee378a0
JH
76
77rm -fr .git2
78mkdir .git2
79
80test_expect_success \
ac527b0b 81 'unpack with REF_DELTA' \
8ee378a0
JH
82 'GIT_OBJECT_DIRECTORY=.git2/objects &&
83 export GIT_OBJECT_DIRECTORY &&
5be60078
JH
84 git init &&
85 git unpack-objects -n <test-2-${packname_2}.pack &&
86 git unpack-objects <test-2-${packname_2}.pack'
8ee378a0
JH
87
88unset GIT_OBJECT_DIRECTORY
f07a5241 89cd "$TRASH/.git2"
8ee378a0 90test_expect_success \
ac527b0b 91 'check unpack with REF_DELTA' \
8ee378a0
JH
92 '(cd ../.git && find objects -type f -print) |
93 while read path
94 do
95 cmp $path ../.git/$path || {
96 echo $path differs.
4d9d62fa 97 return 1
8ee378a0
JH
98 }
99 done'
f07a5241 100cd "$TRASH"
8ee378a0 101
ac527b0b
NP
102test_expect_success \
103 'pack with OFS_DELTA' \
104 'pwd &&
5be60078 105 packname_3=$(git pack-objects --delta-base-offset test-3 <obj-list)'
ac527b0b
NP
106
107rm -fr .git2
108mkdir .git2
109
110test_expect_success \
111 'unpack with OFS_DELTA' \
112 'GIT_OBJECT_DIRECTORY=.git2/objects &&
113 export GIT_OBJECT_DIRECTORY &&
5be60078
JH
114 git init &&
115 git unpack-objects -n <test-3-${packname_3}.pack &&
116 git unpack-objects <test-3-${packname_3}.pack'
ac527b0b
NP
117
118unset GIT_OBJECT_DIRECTORY
119cd "$TRASH/.git2"
120test_expect_success \
121 'check unpack with OFS_DELTA' \
122 '(cd ../.git && find objects -type f -print) |
123 while read path
124 do
125 cmp $path ../.git/$path || {
126 echo $path differs.
127 return 1
128 }
129 done'
130cd "$TRASH"
131
d93f7c18 132test_expect_success 'compare delta flavors' '
94221d22 133 perl -e '\''
d93f7c18
AL
134 defined($_ = -s $_) or die for @ARGV;
135 exit 1 if $ARGV[0] <= $ARGV[1];
136 '\'' test-2-$packname_2.pack test-3-$packname_3.pack
137'
ac527b0b 138
1f688557
JH
139rm -fr .git2
140mkdir .git2
141
142test_expect_success \
143 'use packed objects' \
144 'GIT_OBJECT_DIRECTORY=.git2/objects &&
145 export GIT_OBJECT_DIRECTORY &&
5be60078 146 git init &&
a61eea6a 147 cp test-1-${packname_1}.pack test-1-${packname_1}.idx .git2/objects/pack && {
5be60078 148 git diff-tree --root -p $commit &&
1f688557
JH
149 while read object
150 do
d6cd9ac9 151 t=$(git cat-file -t $object) &&
5be60078 152 git cat-file $t $object || return 1
1f688557
JH
153 done <obj-list
154 } >current &&
ce1a0473 155 cmp expect current'
1f688557 156
1f688557 157test_expect_success \
ac527b0b 158 'use packed deltified (REF_DELTA) objects' \
1f688557
JH
159 'GIT_OBJECT_DIRECTORY=.git2/objects &&
160 export GIT_OBJECT_DIRECTORY &&
a5878961 161 rm -f .git2/objects/pack/test-* &&
a61eea6a 162 cp test-2-${packname_2}.pack test-2-${packname_2}.idx .git2/objects/pack && {
5be60078 163 git diff-tree --root -p $commit &&
1f688557
JH
164 while read object
165 do
d6cd9ac9 166 t=$(git cat-file -t $object) &&
5be60078 167 git cat-file $t $object || return 1
1f688557
JH
168 done <obj-list
169 } >current &&
ce1a0473 170 cmp expect current'
1f688557 171
ac527b0b
NP
172test_expect_success \
173 'use packed deltified (OFS_DELTA) objects' \
174 'GIT_OBJECT_DIRECTORY=.git2/objects &&
175 export GIT_OBJECT_DIRECTORY &&
a5878961 176 rm -f .git2/objects/pack/test-* &&
ac527b0b 177 cp test-3-${packname_3}.pack test-3-${packname_3}.idx .git2/objects/pack && {
5be60078 178 git diff-tree --root -p $commit &&
ac527b0b
NP
179 while read object
180 do
d6cd9ac9 181 t=$(git cat-file -t $object) &&
5be60078 182 git cat-file $t $object || return 1
ac527b0b
NP
183 done <obj-list
184 } >current &&
ce1a0473 185 cmp expect current'
ac527b0b 186
f9253394
JH
187unset GIT_OBJECT_DIRECTORY
188
6e180cdc
JH
189test_expect_success 'survive missing objects/pack directory' '
190 (
191 rm -fr missing-pack &&
192 mkdir missing-pack &&
193 cd missing-pack &&
194 git init &&
51b85471 195 GOP=.git/objects/pack &&
6e180cdc
JH
196 rm -fr $GOP &&
197 git index-pack --stdin --keep=test <../test-3-${packname_3}.pack &&
198 test -f $GOP/pack-${packname_3}.pack &&
ce1a0473 199 cmp $GOP/pack-${packname_3}.pack ../test-3-${packname_3}.pack &&
6e180cdc 200 test -f $GOP/pack-${packname_3}.idx &&
ce1a0473 201 cmp $GOP/pack-${packname_3}.idx ../test-3-${packname_3}.idx &&
6e180cdc
JH
202 test -f $GOP/pack-${packname_3}.keep
203 )
204'
205
f9253394
JH
206test_expect_success \
207 'verify pack' \
5be60078 208 'git verify-pack test-1-${packname_1}.idx \
ac527b0b
NP
209 test-2-${packname_2}.idx \
210 test-3-${packname_3}.idx'
f9253394 211
4b480c67
NP
212test_expect_success \
213 'verify pack -v' \
214 'git verify-pack -v test-1-${packname_1}.idx \
215 test-2-${packname_2}.idx \
216 test-3-${packname_3}.idx'
217
f9253394 218test_expect_success \
63405283 219 'verify-pack catches mismatched .idx and .pack files' \
a5878961
JH
220 'cat test-1-${packname_1}.idx >test-3.idx &&
221 cat test-2-${packname_2}.pack >test-3.pack &&
5be60078 222 if git verify-pack test-3.idx
f9253394
JH
223 then false
224 else :;
63405283 225 fi'
f9253394 226
63405283
JS
227test_expect_success \
228 'verify-pack catches a corrupted pack signature' \
229 'cat test-1-${packname_1}.pack >test-3.pack &&
b689ccf6 230 echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=2 &&
5be60078 231 if git verify-pack test-3.idx
f9253394
JH
232 then false
233 else :;
63405283 234 fi'
f9253394 235
63405283
JS
236test_expect_success \
237 'verify-pack catches a corrupted pack version' \
238 'cat test-1-${packname_1}.pack >test-3.pack &&
b689ccf6 239 echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=7 &&
5be60078 240 if git verify-pack test-3.idx
f9253394
JH
241 then false
242 else :;
63405283 243 fi'
f9253394 244
63405283
JS
245test_expect_success \
246 'verify-pack catches a corrupted type/size of the 1st packed object data' \
247 'cat test-1-${packname_1}.pack >test-3.pack &&
b689ccf6 248 echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=12 &&
5be60078 249 if git verify-pack test-3.idx
f9253394
JH
250 then false
251 else :;
63405283 252 fi'
f9253394 253
63405283
JS
254test_expect_success \
255 'verify-pack catches a corrupted sum of the index file itself' \
d6cd9ac9
EP
256 'l=$(wc -c <test-3.idx) &&
257 l=$(expr $l - 20) &&
a5878961 258 cat test-1-${packname_1}.pack >test-3.pack &&
b689ccf6 259 printf "%20s" "" | dd of=test-3.idx count=20 bs=1 conv=notrunc seek=$l &&
5be60078 260 if git verify-pack test-3.pack
c5ced645
JH
261 then false
262 else :;
63405283 263 fi'
f9253394 264
9cf6d335
SV
265test_expect_success \
266 'build pack index for an existing pack' \
a5878961 267 'cat test-1-${packname_1}.pack >test-3.pack &&
3604e7c5 268 git index-pack -o tmp.idx test-3.pack &&
9cf6d335
SV
269 cmp tmp.idx test-1-${packname_1}.idx &&
270
3604e7c5 271 git index-pack test-3.pack &&
9cf6d335
SV
272 cmp test-3.idx test-1-${packname_1}.idx &&
273
a5878961 274 cat test-2-${packname_2}.pack >test-3.pack &&
3604e7c5 275 git index-pack -o tmp.idx test-2-${packname_2}.pack &&
9cf6d335
SV
276 cmp tmp.idx test-2-${packname_2}.idx &&
277
3604e7c5 278 git index-pack test-3.pack &&
9cf6d335
SV
279 cmp test-3.idx test-2-${packname_2}.idx &&
280
a5878961 281 cat test-3-${packname_3}.pack >test-3.pack &&
3604e7c5 282 git index-pack -o tmp.idx test-3-${packname_3}.pack &&
ac527b0b
NP
283 cmp tmp.idx test-3-${packname_3}.idx &&
284
3604e7c5 285 git index-pack test-3.pack &&
ac527b0b
NP
286 cmp test-3.idx test-3-${packname_3}.idx &&
287
0e94242d
JH
288 cat test-1-${packname_1}.pack >test-4.pack &&
289 rm -f test-4.keep &&
290 git index-pack --keep=why test-4.pack &&
291 cmp test-1-${packname_1}.idx test-4.idx &&
292 test -f test-4.keep &&
293
9cf6d335
SV
294 :'
295
f2898cfa 296test_expect_success 'unpacking with --strict' '
c0e809e5 297
c0e809e5
JH
298 for j in a b c d e f g
299 do
300 for i in 0 1 2 3 4 5 6 7 8 9
301 do
302 o=$(echo $j$i | git hash-object -w --stdin) &&
303 echo "100644 $o 0 $j$i"
304 done
305 done >LIST &&
306 rm -f .git/index &&
307 git update-index --index-info <LIST &&
308 LIST=$(git write-tree) &&
309 rm -f .git/index &&
310 head -n 10 LIST | git update-index --index-info &&
311 LI=$(git write-tree) &&
312 rm -f .git/index &&
313 tail -n 10 LIST | git update-index --index-info &&
314 ST=$(git write-tree) &&
a4d4e32a
PK
315 git rev-list --objects "$LIST" "$LI" "$ST" >actual &&
316 PACK5=$( git pack-objects test-5 <actual ) &&
c0e809e5
JH
317 PACK6=$( (
318 echo "$LIST"
319 echo "$LI"
320 echo "$ST"
321 ) | git pack-objects test-6 ) &&
322 test_create_repo test-5 &&
323 (
324 cd test-5 &&
325 git unpack-objects --strict <../test-5-$PACK5.pack &&
326 git ls-tree -r $LIST &&
327 git ls-tree -r $LI &&
328 git ls-tree -r $ST
329 ) &&
330 test_create_repo test-6 &&
331 (
332 # tree-only into empty repo -- many unreachables
333 cd test-6 &&
334 test_must_fail git unpack-objects --strict <../test-6-$PACK6.pack
335 ) &&
336 (
337 # already populated -- no unreachables
338 cd test-5 &&
339 git unpack-objects --strict <../test-6-$PACK6.pack
340 )
341'
342
38a5739d
MK
343test_expect_success 'index-pack with --strict' '
344
345 for j in a b c d e f g
346 do
347 for i in 0 1 2 3 4 5 6 7 8 9
348 do
349 o=$(echo $j$i | git hash-object -w --stdin) &&
350 echo "100644 $o 0 $j$i"
351 done
352 done >LIST &&
353 rm -f .git/index &&
354 git update-index --index-info <LIST &&
355 LIST=$(git write-tree) &&
356 rm -f .git/index &&
357 head -n 10 LIST | git update-index --index-info &&
358 LI=$(git write-tree) &&
359 rm -f .git/index &&
360 tail -n 10 LIST | git update-index --index-info &&
361 ST=$(git write-tree) &&
a4d4e32a
PK
362 git rev-list --objects "$LIST" "$LI" "$ST" >actual &&
363 PACK5=$( git pack-objects test-5 <actual ) &&
38a5739d
MK
364 PACK6=$( (
365 echo "$LIST"
366 echo "$LI"
367 echo "$ST"
368 ) | git pack-objects test-6 ) &&
369 test_create_repo test-7 &&
370 (
371 cd test-7 &&
372 git index-pack --strict --stdin <../test-5-$PACK5.pack &&
373 git ls-tree -r $LIST &&
374 git ls-tree -r $LI &&
375 git ls-tree -r $ST
376 ) &&
377 test_create_repo test-8 &&
378 (
379 # tree-only into empty repo -- many unreachables
380 cd test-8 &&
381 test_must_fail git index-pack --strict --stdin <../test-6-$PACK6.pack
382 ) &&
383 (
384 # already populated -- no unreachables
385 cd test-7 &&
386 git index-pack --strict --stdin <../test-6-$PACK6.pack
387 )
388'
389
2fca19fb 390test_expect_success 'honor pack.packSizeLimit' '
07cf0f24 391 git config pack.packSizeLimit 3m &&
2fca19fb 392 packname_10=$(git pack-objects test-10 <obj-list) &&
07cf0f24 393 test 2 = $(ls test-10-*.pack | wc -l)
2fca19fb
NP
394'
395
396test_expect_success 'verify resulting packs' '
397 git verify-pack test-10-*.pack
398'
399
07cf0f24
NP
400test_expect_success 'tolerate packsizelimit smaller than biggest object' '
401 git config pack.packSizeLimit 1 &&
2fca19fb 402 packname_11=$(git pack-objects test-11 <obj-list) &&
720c9f7b 403 test 5 = $(ls test-11-*.pack | wc -l)
a1e4760f
NP
404'
405
2fca19fb
NP
406test_expect_success 'verify resulting packs' '
407 git verify-pack test-11-*.pack
408'
409
7176a314
JK
410test_expect_success 'set up pack for non-repo tests' '
411 # make sure we have a pack with no matching index file
412 cp test-1-*.pack foo.pack
413'
414
415test_expect_success 'index-pack --stdin complains of non-repo' '
371c4079 416 nongit test_must_fail git index-pack --object-format=$(test_oid algo) --stdin <foo.pack &&
7176a314
JK
417 test_path_is_missing non-repo/.git
418'
419
420test_expect_success 'index-pack <pack> works in non-repo' '
371c4079 421 nongit git index-pack --object-format=$(test_oid algo) ../foo.pack &&
7176a314
JK
422 test_path_is_file foo.idx
423'
424
14a9bd28
JK
425test_expect_success 'index-pack --strict <pack> works in non-repo' '
426 rm -f foo.idx &&
371c4079 427 nongit git index-pack --strict --object-format=$(test_oid algo) ../foo.pack &&
14a9bd28
JK
428 test_path_is_file foo.idx
429'
430
967a3eaf
ÆAB
431test_expect_success !PTHREADS,C_LOCALE_OUTPUT 'index-pack --threads=N or pack.threads=N warns when no pthreads' '
432 test_must_fail git index-pack --threads=2 2>err &&
433 grep ^warning: err >warnings &&
434 test_line_count = 1 warnings &&
435 grep -F "no threads support, ignoring --threads=2" err &&
436
437 test_must_fail git -c pack.threads=2 index-pack 2>err &&
438 grep ^warning: err >warnings &&
439 test_line_count = 1 warnings &&
440 grep -F "no threads support, ignoring pack.threads" err &&
441
442 test_must_fail git -c pack.threads=2 index-pack --threads=4 2>err &&
443 grep ^warning: err >warnings &&
444 test_line_count = 2 warnings &&
445 grep -F "no threads support, ignoring --threads=4" err &&
446 grep -F "no threads support, ignoring pack.threads" err
447'
448
449test_expect_success !PTHREADS,C_LOCALE_OUTPUT 'pack-objects --threads=N or pack.threads=N warns when no pthreads' '
450 git pack-objects --threads=2 --stdout --all </dev/null >/dev/null 2>err &&
451 grep ^warning: err >warnings &&
452 test_line_count = 1 warnings &&
453 grep -F "no threads support, ignoring --threads" err &&
454
455 git -c pack.threads=2 pack-objects --stdout --all </dev/null >/dev/null 2>err &&
456 grep ^warning: err >warnings &&
2e96d815 457 test_line_count = 1 warnings &&
967a3eaf
ÆAB
458 grep -F "no threads support, ignoring pack.threads" err &&
459
460 git -c pack.threads=2 pack-objects --threads=4 --stdout --all </dev/null >/dev/null 2>err &&
461 grep ^warning: err >warnings &&
462 test_line_count = 2 warnings &&
463 grep -F "no threads support, ignoring --threads" err &&
464 grep -F "no threads support, ignoring pack.threads" err
465'
466
43fa44fa
NTND
467test_expect_success 'pack-objects in too-many-packs mode' '
468 GIT_TEST_FULL_IN_PACK_ARRAY=1 git repack -ad &&
469 git fsck
470'
471
228135d9
ÆAB
472test_expect_success 'setup: fake a SHA1 hash collision' '
473 git init corrupt &&
474 (
475 cd corrupt &&
476 long_a=$(git hash-object -w ../a | sed -e "s!^..!&/!") &&
477 long_b=$(git hash-object -w ../b | sed -e "s!^..!&/!") &&
478 test -f .git/objects/$long_b &&
479 cp -f .git/objects/$long_a \
480 .git/objects/$long_b
481 )
80938c39 482'
2fca19fb 483
80938c39 484test_expect_success 'make sure index-pack detects the SHA1 collision' '
228135d9
ÆAB
485 (
486 cd corrupt &&
487 test_must_fail git index-pack -o ../bad.idx ../test-3.pack 2>msg &&
488 test_i18ngrep "SHA1 COLLISION FOUND" msg
489 )
80938c39 490'
2fca19fb 491
80938c39 492test_expect_success 'make sure index-pack detects the SHA1 collision (large blobs)' '
228135d9
ÆAB
493 (
494 cd corrupt &&
495 test_must_fail git -c core.bigfilethreshold=1 index-pack -o ../bad.idx ../test-3.pack 2>msg &&
496 test_i18ngrep "SHA1 COLLISION FOUND" msg
497 )
80938c39 498'
4614043c 499
8ee378a0 500test_done