3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='git pack-object
18 dd if=/dev/zero bs=4k count=1 | perl -pe "y/\\000/$i/" >$i &&
19 git update-index --add $i || return 1
21 cat c >d && echo foo >>d && git update-index --add d &&
22 tree=`git write-tree` &&
23 commit=`git commit-tree $tree </dev/null` && {
26 git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
28 git diff-tree --root -p $commit &&
31 t=`git cat-file -t $object` &&
32 git cat-file $t $object || return 1
37 'pack without delta' \
38 'packname_1=$(git pack-objects --window=0 test-1 <obj-list)'
44 'unpack without delta' \
45 "GIT_OBJECT_DIRECTORY=.git2/objects &&
46 export GIT_OBJECT_DIRECTORY &&
48 git unpack-objects -n <test-1-${packname_1}.pack &&
49 git unpack-objects <test-1-${packname_1}.pack"
51 unset GIT_OBJECT_DIRECTORY
55 'check unpack without delta' \
56 '(cd ../.git && find objects -type f -print) |
59 cmp $path ../.git/$path || {
67 'pack with REF_DELTA' \
69 packname_2=$(git pack-objects test-2 <obj-list)'
75 'unpack with REF_DELTA' \
76 'GIT_OBJECT_DIRECTORY=.git2/objects &&
77 export GIT_OBJECT_DIRECTORY &&
79 git unpack-objects -n <test-2-${packname_2}.pack &&
80 git unpack-objects <test-2-${packname_2}.pack'
82 unset GIT_OBJECT_DIRECTORY
85 'check unpack with REF_DELTA' \
86 '(cd ../.git && find objects -type f -print) |
89 cmp $path ../.git/$path || {
97 'pack with OFS_DELTA' \
99 packname_3=$(git pack-objects --delta-base-offset test-3 <obj-list)'
104 test_expect_success \
105 'unpack with OFS_DELTA' \
106 'GIT_OBJECT_DIRECTORY=.git2/objects &&
107 export GIT_OBJECT_DIRECTORY &&
109 git unpack-objects -n <test-3-${packname_3}.pack &&
110 git unpack-objects <test-3-${packname_3}.pack'
112 unset GIT_OBJECT_DIRECTORY
114 test_expect_success \
115 'check unpack with OFS_DELTA' \
116 '(cd ../.git && find objects -type f -print) |
119 cmp $path ../.git/$path || {
126 test_expect_success
'compare delta flavors' '
128 defined($_ = -s $_) or die for @ARGV;
129 exit 1 if $ARGV[0] <= $ARGV[1];
130 '\'' test-2-$packname_2.pack test-3-$packname_3.pack
136 test_expect_success \
137 'use packed objects' \
138 'GIT_OBJECT_DIRECTORY=.git2/objects &&
139 export GIT_OBJECT_DIRECTORY &&
141 cp test-1-${packname_1}.pack test-1-${packname_1}.idx .git2/objects/pack && {
142 git diff-tree --root -p $commit &&
145 t=`git cat-file -t $object` &&
146 git cat-file $t $object || return 1
151 test_expect_success \
152 'use packed deltified (REF_DELTA) objects' \
153 'GIT_OBJECT_DIRECTORY=.git2/objects &&
154 export GIT_OBJECT_DIRECTORY &&
155 rm -f .git2/objects/pack/test-* &&
156 cp test-2-${packname_2}.pack test-2-${packname_2}.idx .git2/objects/pack && {
157 git diff-tree --root -p $commit &&
160 t=`git cat-file -t $object` &&
161 git cat-file $t $object || return 1
166 test_expect_success \
167 'use packed deltified (OFS_DELTA) objects' \
168 'GIT_OBJECT_DIRECTORY=.git2/objects &&
169 export GIT_OBJECT_DIRECTORY &&
170 rm -f .git2/objects/pack/test-* &&
171 cp test-3-${packname_3}.pack test-3-${packname_3}.idx .git2/objects/pack && {
172 git diff-tree --root -p $commit &&
175 t=`git cat-file -t $object` &&
176 git cat-file $t $object || return 1
181 unset GIT_OBJECT_DIRECTORY
183 test_expect_success \
185 'git verify-pack test-1-${packname_1}.idx \
186 test-2-${packname_2}.idx \
187 test-3-${packname_3}.idx'
189 test_expect_success \
191 'git verify-pack -v test-1-${packname_1}.idx \
192 test-2-${packname_2}.idx \
193 test-3-${packname_3}.idx'
195 test_expect_success \
196 'verify-pack catches mismatched .idx and .pack files' \
197 'cat test-1-${packname_1}.idx >test-3.idx &&
198 cat test-2-${packname_2}.pack >test-3.pack &&
199 if git verify-pack test-3.idx
204 test_expect_success \
205 'verify-pack catches a corrupted pack signature' \
206 'cat test-1-${packname_1}.pack >test-3.pack &&
207 dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=2 &&
208 if git verify-pack test-3.idx
213 test_expect_success \
214 'verify-pack catches a corrupted pack version' \
215 'cat test-1-${packname_1}.pack >test-3.pack &&
216 dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=7 &&
217 if git verify-pack test-3.idx
222 test_expect_success \
223 'verify-pack catches a corrupted type/size of the 1st packed object data' \
224 'cat test-1-${packname_1}.pack >test-3.pack &&
225 dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=12 &&
226 if git verify-pack test-3.idx
231 test_expect_success \
232 'verify-pack catches a corrupted sum of the index file itself' \
233 'l=`wc -c <test-3.idx` &&
235 cat test-1-${packname_1}.pack >test-3.pack &&
236 dd if=/dev/zero of=test-3.idx count=20 bs=1 conv=notrunc seek=$l &&
237 if git verify-pack test-3.pack
242 test_expect_success \
243 'build pack index for an existing pack' \
244 'cat test-1-${packname_1}.pack >test-3.pack &&
245 git index-pack -o tmp.idx test-3.pack &&
246 cmp tmp.idx test-1-${packname_1}.idx &&
248 git index-pack test-3.pack &&
249 cmp test-3.idx test-1-${packname_1}.idx &&
251 cat test-2-${packname_2}.pack >test-3.pack &&
252 git index-pack -o tmp.idx test-2-${packname_2}.pack &&
253 cmp tmp.idx test-2-${packname_2}.idx &&
255 git index-pack test-3.pack &&
256 cmp test-3.idx test-2-${packname_2}.idx &&
258 cat test-3-${packname_3}.pack >test-3.pack &&
259 git index-pack -o tmp.idx test-3-${packname_3}.pack &&
260 cmp tmp.idx test-3-${packname_3}.idx &&
262 git index-pack test-3.pack &&
263 cmp test-3.idx test-3-${packname_3}.idx &&
267 test_expect_success \
268 'fake a SHA1 hash collision' \
269 'test -f .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67 &&
270 cp -f .git/objects/9d/235ed07cd19811a6ceb342de82f190e49c9f68 \
271 .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67'
273 test_expect_success \
274 'make sure index-pack detects the SHA1 collision' \
275 'test_must_fail git index-pack -o bad.idx test-3.pack 2>msg &&
276 grep "SHA1 COLLISION FOUND" msg'
278 test_expect_success \
279 'honor pack.packSizeLimit' \
280 'git config pack.packSizeLimit 200 &&
281 packname_4=$(git pack-objects test-4 <obj-list) &&
282 test 3 = $(ls test-4-*.pack | wc -l)'
284 test_expect_success
'unpacking with --strict' '
286 git config --unset pack.packsizelimit &&
287 for j in a b c d e f g
289 for i in 0 1 2 3 4 5 6 7 8 9
291 o=$(echo $j$i | git hash-object -w --stdin) &&
292 echo "100644 $o 0 $j$i"
296 git update-index --index-info <LIST &&
297 LIST=$(git write-tree) &&
299 head -n 10 LIST | git update-index --index-info &&
300 LI=$(git write-tree) &&
302 tail -n 10 LIST | git update-index --index-info &&
303 ST=$(git write-tree) &&
304 PACK5=$( git rev-list --objects "$LIST" "$LI" "$ST" | \
305 git pack-objects test-5 ) &&
310 ) | git pack-objects test-6 ) &&
311 test_create_repo test-5 &&
314 git unpack-objects --strict <../test-5-$PACK5.pack &&
315 git ls-tree -r $LIST &&
316 git ls-tree -r $LI &&
319 test_create_repo test-6 &&
321 # tree-only into empty repo -- many unreachables
323 test_must_fail git unpack-objects --strict <../test-6-$PACK6.pack
326 # already populated -- no unreachables
328 git unpack-objects --strict <../test-6-$PACK6.pack
332 test_expect_success
'index-pack with --strict' '
334 for j in a b c d e f g
336 for i in 0 1 2 3 4 5 6 7 8 9
338 o=$(echo $j$i | git hash-object -w --stdin) &&
339 echo "100644 $o 0 $j$i"
343 git update-index --index-info <LIST &&
344 LIST=$(git write-tree) &&
346 head -n 10 LIST | git update-index --index-info &&
347 LI=$(git write-tree) &&
349 tail -n 10 LIST | git update-index --index-info &&
350 ST=$(git write-tree) &&
351 PACK5=$( git rev-list --objects "$LIST" "$LI" "$ST" | \
352 git pack-objects test-5 ) &&
357 ) | git pack-objects test-6 ) &&
358 test_create_repo test-7 &&
361 git index-pack --strict --stdin <../test-5-$PACK5.pack &&
362 git ls-tree -r $LIST &&
363 git ls-tree -r $LI &&
366 test_create_repo test-8 &&
368 # tree-only into empty repo -- many unreachables
370 test_must_fail git index-pack --strict --stdin <../test-6-$PACK6.pack
373 # already populated -- no unreachables
375 git index-pack --strict --stdin <../test-6-$PACK6.pack