Merge branch 'lt/maint-reflog-expire' into maint
[git/git-svn.git] / t / t5300-pack-object.sh
blobccfc64c6eef7e0aba7bd8a8496427470e9020309
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='git pack-object
9 . ./test-lib.sh
11 TRASH=`pwd`
13 test_expect_success \
14 'setup' \
15 'rm -f .git/index*
16 for i in a b c
18 dd if=/dev/zero bs=4k count=1 | perl -pe "y/\\000/$i/" >$i &&
19 git update-index --add $i || return 1
20 done &&
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` && {
24 echo $tree &&
25 echo $commit &&
26 git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
27 } >obj-list && {
28 git diff-tree --root -p $commit &&
29 while read object
31 t=`git cat-file -t $object` &&
32 git cat-file $t $object || return 1
33 done <obj-list
34 } >expect'
36 test_expect_success \
37 'pack without delta' \
38 'packname_1=$(git pack-objects --window=0 test-1 <obj-list)'
40 rm -fr .git2
41 mkdir .git2
43 test_expect_success \
44 'unpack without delta' \
45 "GIT_OBJECT_DIRECTORY=.git2/objects &&
46 export GIT_OBJECT_DIRECTORY &&
47 git init &&
48 git unpack-objects -n <test-1-${packname_1}.pack &&
49 git unpack-objects <test-1-${packname_1}.pack"
51 unset GIT_OBJECT_DIRECTORY
52 cd "$TRASH/.git2"
54 test_expect_success \
55 'check unpack without delta' \
56 '(cd ../.git && find objects -type f -print) |
57 while read path
59 cmp $path ../.git/$path || {
60 echo $path differs.
61 return 1
63 done'
64 cd "$TRASH"
66 test_expect_success \
67 'pack with REF_DELTA' \
68 'pwd &&
69 packname_2=$(git pack-objects test-2 <obj-list)'
71 rm -fr .git2
72 mkdir .git2
74 test_expect_success \
75 'unpack with REF_DELTA' \
76 'GIT_OBJECT_DIRECTORY=.git2/objects &&
77 export GIT_OBJECT_DIRECTORY &&
78 git init &&
79 git unpack-objects -n <test-2-${packname_2}.pack &&
80 git unpack-objects <test-2-${packname_2}.pack'
82 unset GIT_OBJECT_DIRECTORY
83 cd "$TRASH/.git2"
84 test_expect_success \
85 'check unpack with REF_DELTA' \
86 '(cd ../.git && find objects -type f -print) |
87 while read path
89 cmp $path ../.git/$path || {
90 echo $path differs.
91 return 1
93 done'
94 cd "$TRASH"
96 test_expect_success \
97 'pack with OFS_DELTA' \
98 'pwd &&
99 packname_3=$(git pack-objects --delta-base-offset test-3 <obj-list)'
101 rm -fr .git2
102 mkdir .git2
104 test_expect_success \
105 'unpack with OFS_DELTA' \
106 'GIT_OBJECT_DIRECTORY=.git2/objects &&
107 export GIT_OBJECT_DIRECTORY &&
108 git init &&
109 git unpack-objects -n <test-3-${packname_3}.pack &&
110 git unpack-objects <test-3-${packname_3}.pack'
112 unset GIT_OBJECT_DIRECTORY
113 cd "$TRASH/.git2"
114 test_expect_success \
115 'check unpack with OFS_DELTA' \
116 '(cd ../.git && find objects -type f -print) |
117 while read path
119 cmp $path ../.git/$path || {
120 echo $path differs.
121 return 1
123 done'
124 cd "$TRASH"
126 test_expect_success 'compare delta flavors' '
127 perl -e '\''
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
133 rm -fr .git2
134 mkdir .git2
136 test_expect_success \
137 'use packed objects' \
138 'GIT_OBJECT_DIRECTORY=.git2/objects &&
139 export GIT_OBJECT_DIRECTORY &&
140 git init &&
141 cp test-1-${packname_1}.pack test-1-${packname_1}.idx .git2/objects/pack && {
142 git diff-tree --root -p $commit &&
143 while read object
145 t=`git cat-file -t $object` &&
146 git cat-file $t $object || return 1
147 done <obj-list
148 } >current &&
149 diff expect current'
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 &&
158 while read object
160 t=`git cat-file -t $object` &&
161 git cat-file $t $object || return 1
162 done <obj-list
163 } >current &&
164 diff expect current'
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 &&
173 while read object
175 t=`git cat-file -t $object` &&
176 git cat-file $t $object || return 1
177 done <obj-list
178 } >current &&
179 diff expect current'
181 unset GIT_OBJECT_DIRECTORY
183 test_expect_success 'survive missing objects/pack directory' '
185 rm -fr missing-pack &&
186 mkdir missing-pack &&
187 cd missing-pack &&
188 git init &&
189 GOP=.git/objects/pack
190 rm -fr $GOP &&
191 git index-pack --stdin --keep=test <../test-3-${packname_3}.pack &&
192 test -f $GOP/pack-${packname_3}.pack &&
193 test_cmp $GOP/pack-${packname_3}.pack ../test-3-${packname_3}.pack &&
194 test -f $GOP/pack-${packname_3}.idx &&
195 test_cmp $GOP/pack-${packname_3}.idx ../test-3-${packname_3}.idx &&
196 test -f $GOP/pack-${packname_3}.keep
200 test_expect_success \
201 'verify pack' \
202 'git verify-pack test-1-${packname_1}.idx \
203 test-2-${packname_2}.idx \
204 test-3-${packname_3}.idx'
206 test_expect_success \
207 'verify pack -v' \
208 'git verify-pack -v test-1-${packname_1}.idx \
209 test-2-${packname_2}.idx \
210 test-3-${packname_3}.idx'
212 test_expect_success \
213 'verify-pack catches mismatched .idx and .pack files' \
214 'cat test-1-${packname_1}.idx >test-3.idx &&
215 cat test-2-${packname_2}.pack >test-3.pack &&
216 if git verify-pack test-3.idx
217 then false
218 else :;
221 test_expect_success \
222 'verify-pack catches a corrupted pack signature' \
223 'cat test-1-${packname_1}.pack >test-3.pack &&
224 dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=2 &&
225 if git verify-pack test-3.idx
226 then false
227 else :;
230 test_expect_success \
231 'verify-pack catches a corrupted pack version' \
232 'cat test-1-${packname_1}.pack >test-3.pack &&
233 dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=7 &&
234 if git verify-pack test-3.idx
235 then false
236 else :;
239 test_expect_success \
240 'verify-pack catches a corrupted type/size of the 1st packed object data' \
241 'cat test-1-${packname_1}.pack >test-3.pack &&
242 dd if=/dev/zero of=test-3.pack count=1 bs=1 conv=notrunc seek=12 &&
243 if git verify-pack test-3.idx
244 then false
245 else :;
248 test_expect_success \
249 'verify-pack catches a corrupted sum of the index file itself' \
250 'l=`wc -c <test-3.idx` &&
251 l=`expr $l - 20` &&
252 cat test-1-${packname_1}.pack >test-3.pack &&
253 dd if=/dev/zero of=test-3.idx count=20 bs=1 conv=notrunc seek=$l &&
254 if git verify-pack test-3.pack
255 then false
256 else :;
259 test_expect_success \
260 'build pack index for an existing pack' \
261 'cat test-1-${packname_1}.pack >test-3.pack &&
262 git index-pack -o tmp.idx test-3.pack &&
263 cmp tmp.idx test-1-${packname_1}.idx &&
265 git index-pack test-3.pack &&
266 cmp test-3.idx test-1-${packname_1}.idx &&
268 cat test-2-${packname_2}.pack >test-3.pack &&
269 git index-pack -o tmp.idx test-2-${packname_2}.pack &&
270 cmp tmp.idx test-2-${packname_2}.idx &&
272 git index-pack test-3.pack &&
273 cmp test-3.idx test-2-${packname_2}.idx &&
275 cat test-3-${packname_3}.pack >test-3.pack &&
276 git index-pack -o tmp.idx test-3-${packname_3}.pack &&
277 cmp tmp.idx test-3-${packname_3}.idx &&
279 git index-pack test-3.pack &&
280 cmp test-3.idx test-3-${packname_3}.idx &&
284 test_expect_success \
285 'fake a SHA1 hash collision' \
286 'test -f .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67 &&
287 cp -f .git/objects/9d/235ed07cd19811a6ceb342de82f190e49c9f68 \
288 .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67'
290 test_expect_success \
291 'make sure index-pack detects the SHA1 collision' \
292 'test_must_fail git index-pack -o bad.idx test-3.pack 2>msg &&
293 grep "SHA1 COLLISION FOUND" msg'
295 test_expect_success \
296 'honor pack.packSizeLimit' \
297 'git config pack.packSizeLimit 200 &&
298 packname_4=$(git pack-objects test-4 <obj-list) &&
299 test 3 = $(ls test-4-*.pack | wc -l)'
301 test_expect_success 'unpacking with --strict' '
303 git config --unset pack.packsizelimit &&
304 for j in a b c d e f g
306 for i in 0 1 2 3 4 5 6 7 8 9
308 o=$(echo $j$i | git hash-object -w --stdin) &&
309 echo "100644 $o 0 $j$i"
310 done
311 done >LIST &&
312 rm -f .git/index &&
313 git update-index --index-info <LIST &&
314 LIST=$(git write-tree) &&
315 rm -f .git/index &&
316 head -n 10 LIST | git update-index --index-info &&
317 LI=$(git write-tree) &&
318 rm -f .git/index &&
319 tail -n 10 LIST | git update-index --index-info &&
320 ST=$(git write-tree) &&
321 PACK5=$( git rev-list --objects "$LIST" "$LI" "$ST" | \
322 git pack-objects test-5 ) &&
323 PACK6=$( (
324 echo "$LIST"
325 echo "$LI"
326 echo "$ST"
327 ) | git pack-objects test-6 ) &&
328 test_create_repo test-5 &&
330 cd test-5 &&
331 git unpack-objects --strict <../test-5-$PACK5.pack &&
332 git ls-tree -r $LIST &&
333 git ls-tree -r $LI &&
334 git ls-tree -r $ST
335 ) &&
336 test_create_repo test-6 &&
338 # tree-only into empty repo -- many unreachables
339 cd test-6 &&
340 test_must_fail git unpack-objects --strict <../test-6-$PACK6.pack
341 ) &&
343 # already populated -- no unreachables
344 cd test-5 &&
345 git unpack-objects --strict <../test-6-$PACK6.pack
349 test_expect_success 'index-pack with --strict' '
351 for j in a b c d e f g
353 for i in 0 1 2 3 4 5 6 7 8 9
355 o=$(echo $j$i | git hash-object -w --stdin) &&
356 echo "100644 $o 0 $j$i"
357 done
358 done >LIST &&
359 rm -f .git/index &&
360 git update-index --index-info <LIST &&
361 LIST=$(git write-tree) &&
362 rm -f .git/index &&
363 head -n 10 LIST | git update-index --index-info &&
364 LI=$(git write-tree) &&
365 rm -f .git/index &&
366 tail -n 10 LIST | git update-index --index-info &&
367 ST=$(git write-tree) &&
368 PACK5=$( git rev-list --objects "$LIST" "$LI" "$ST" | \
369 git pack-objects test-5 ) &&
370 PACK6=$( (
371 echo "$LIST"
372 echo "$LI"
373 echo "$ST"
374 ) | git pack-objects test-6 ) &&
375 test_create_repo test-7 &&
377 cd test-7 &&
378 git index-pack --strict --stdin <../test-5-$PACK5.pack &&
379 git ls-tree -r $LIST &&
380 git ls-tree -r $LI &&
381 git ls-tree -r $ST
382 ) &&
383 test_create_repo test-8 &&
385 # tree-only into empty repo -- many unreachables
386 cd test-8 &&
387 test_must_fail git index-pack --strict --stdin <../test-6-$PACK6.pack
388 ) &&
390 # already populated -- no unreachables
391 cd test-7 &&
392 git index-pack --strict --stdin <../test-6-$PACK6.pack
396 test_expect_success 'tolerate absurdly small packsizelimit' '
397 git config pack.packSizeLimit 2 &&
398 packname_9=$(git pack-objects test-9 <obj-list) &&
399 test $(wc -l <obj-list) = $(ls test-9-*.pack | wc -l)
402 test_done