Merge branch 'master' of git://repo.or.cz/alt-git
[git/dscho.git] / t / t5300-pack-object.sh
blobcfe9cbdafc2ca61cf77868d235e663e7d5bafd3b
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='git pack-object
9 . ./test-lib.sh
11 TRASH=`pwd`
13 x4k=xxxxxxxx
14 x4k="$x4k$x4k$x4k$x4k$x4k$x4k$x4k$x4k"
15 x4k="$x4k$x4k$x4k$x4k$x4k$x4k$x4k$x4k"
16 x4k="$x4k$x4k$x4k$x4k$x4k$x4k$x4k$x4k"
18 corrupt()
21 read -d "" -n $4 l
22 echo -n "$l"
23 read -d "" -n $3 l
24 echo -n ${x4k:0:$3} | tr x '\0'
25 cat
26 ) < $1 > $2
29 test_expect_success \
30 'setup' \
31 'rm -f .git/index*
32 for i in a b c
34 echo -n "$x4k" | tr x $i >$i &&
35 git update-index --add $i || return 1
36 done &&
37 cat c >d && echo foo >>d && git update-index --add d &&
38 tree=`git write-tree` &&
39 commit=`git commit-tree $tree </dev/null` && {
40 echo $tree &&
41 echo $commit &&
42 git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
43 } >obj-list && {
44 git diff-tree --root -p $commit &&
45 while read object
47 t=`git cat-file -t $object` &&
48 git cat-file $t $object || return 1
49 done <obj-list
50 } >expect'
52 test_expect_success \
53 'pack without delta' \
54 'packname_1=$(git pack-objects --window=0 test-1 <obj-list)'
56 rm -fr .git2
57 mkdir .git2
59 test_expect_success \
60 'unpack without delta' \
61 "GIT_OBJECT_DIRECTORY=.git2/objects &&
62 export GIT_OBJECT_DIRECTORY &&
63 git init &&
64 git unpack-objects -n <test-1-${packname_1}.pack &&
65 git unpack-objects <test-1-${packname_1}.pack"
67 unset GIT_OBJECT_DIRECTORY
68 cd "$TRASH/.git2"
70 test_expect_success \
71 'check unpack without delta' \
72 '(cd ../.git && find objects -type f -print) |
73 while read path
75 cmp $path ../.git/$path || {
76 echo $path differs.
77 return 1
79 done'
80 cd "$TRASH"
82 test_expect_success \
83 'pack with REF_DELTA' \
84 'pwd &&
85 packname_2=$(git pack-objects test-2 <obj-list)'
87 rm -fr .git2
88 mkdir .git2
90 test_expect_success \
91 'unpack with REF_DELTA' \
92 'GIT_OBJECT_DIRECTORY=.git2/objects &&
93 export GIT_OBJECT_DIRECTORY &&
94 git init &&
95 git unpack-objects -n <test-2-${packname_2}.pack &&
96 git unpack-objects <test-2-${packname_2}.pack'
98 unset GIT_OBJECT_DIRECTORY
99 cd "$TRASH/.git2"
100 test_expect_success \
101 'check unpack with REF_DELTA' \
102 '(cd ../.git && find objects -type f -print) |
103 while read path
105 cmp $path ../.git/$path || {
106 echo $path differs.
107 return 1
109 done'
110 cd "$TRASH"
112 test_expect_success \
113 'pack with OFS_DELTA' \
114 'pwd &&
115 packname_3=$(git pack-objects --delta-base-offset test-3 <obj-list)'
117 rm -fr .git2
118 mkdir .git2
120 test_expect_success \
121 'unpack with OFS_DELTA' \
122 'GIT_OBJECT_DIRECTORY=.git2/objects &&
123 export GIT_OBJECT_DIRECTORY &&
124 git init &&
125 git unpack-objects -n <test-3-${packname_3}.pack &&
126 git unpack-objects <test-3-${packname_3}.pack'
128 unset GIT_OBJECT_DIRECTORY
129 cd "$TRASH/.git2"
130 test_expect_success \
131 'check unpack with OFS_DELTA' \
132 '(cd ../.git && find objects -type f -print) |
133 while read path
135 cmp $path ../.git/$path || {
136 echo $path differs.
137 return 1
139 done'
140 cd "$TRASH"
142 test_expect_success 'compare delta flavors' '
143 perl -e '\''
144 defined($_ = -s $_) or die for @ARGV;
145 exit 1 if $ARGV[0] <= $ARGV[1];
146 '\'' test-2-$packname_2.pack test-3-$packname_3.pack
149 rm -fr .git2
150 mkdir .git2
152 test_expect_success \
153 'use packed objects' \
154 'GIT_OBJECT_DIRECTORY=.git2/objects &&
155 export GIT_OBJECT_DIRECTORY &&
156 git init &&
157 cp test-1-${packname_1}.pack test-1-${packname_1}.idx .git2/objects/pack && {
158 git diff-tree --root -p $commit &&
159 while read object
161 t=`git cat-file -t $object` &&
162 git cat-file $t $object || return 1
163 done <obj-list
164 } >current &&
165 diff expect current'
167 test_expect_success \
168 'use packed deltified (REF_DELTA) objects' \
169 'GIT_OBJECT_DIRECTORY=.git2/objects &&
170 export GIT_OBJECT_DIRECTORY &&
171 rm -f .git2/objects/pack/test-* &&
172 cp test-2-${packname_2}.pack test-2-${packname_2}.idx .git2/objects/pack && {
173 git diff-tree --root -p $commit &&
174 while read object
176 t=`git cat-file -t $object` &&
177 git cat-file $t $object || return 1
178 done <obj-list
179 } >current &&
180 diff expect current'
182 test_expect_success \
183 'use packed deltified (OFS_DELTA) objects' \
184 'GIT_OBJECT_DIRECTORY=.git2/objects &&
185 export GIT_OBJECT_DIRECTORY &&
186 rm -f .git2/objects/pack/test-* &&
187 cp test-3-${packname_3}.pack test-3-${packname_3}.idx .git2/objects/pack && {
188 git diff-tree --root -p $commit &&
189 while read object
191 t=`git cat-file -t $object` &&
192 git cat-file $t $object || return 1
193 done <obj-list
194 } >current &&
195 diff expect current'
197 unset GIT_OBJECT_DIRECTORY
199 test_expect_success \
200 'verify pack' \
201 'git verify-pack test-1-${packname_1}.idx \
202 test-2-${packname_2}.idx \
203 test-3-${packname_3}.idx'
205 test_expect_success \
206 'verify pack -v' \
207 'git verify-pack -v test-1-${packname_1}.idx \
208 test-2-${packname_2}.idx \
209 test-3-${packname_3}.idx'
211 test_expect_success \
212 'verify-pack catches mismatched .idx and .pack files' \
213 'cat test-1-${packname_1}.idx >test-3.idx &&
214 cat test-2-${packname_2}.pack >test-3.pack &&
215 if git verify-pack test-3.idx
216 then false
217 else :;
220 test_expect_success \
221 'verify-pack catches a corrupted pack signature' \
222 'corrupt test-1-${packname_1}.pack test-3.pack 1 2 &&
223 if git verify-pack test-3.idx
224 then false
225 else :;
228 test_expect_success \
229 'verify-pack catches a corrupted pack version' \
230 'corrupt test-1-${packname_1}.pack test-3.pack 1 7 &&
231 if git verify-pack test-3.idx
232 then false
233 else :;
236 test_expect_success \
237 'verify-pack catches a corrupted type/size of the 1st packed object data' \
238 'corrupt test-1-${packname_1}.pack test-3.pack 1 12 &&
239 if git verify-pack test-3.idx
240 then false
241 else :;
244 test_expect_success \
245 'verify-pack catches a corrupted sum of the index file itself' \
246 'l=`wc -c <test-3.idx` &&
247 l=`expr $l - 20` &&
248 corrupt test-1-${packname_1}.pack test-3.pack 20 $l &&
249 if git verify-pack test-3.pack
250 then false
251 else :;
254 test_expect_success \
255 'build pack index for an existing pack' \
256 'cat test-1-${packname_1}.pack >test-3.pack &&
257 git index-pack -o tmp.idx test-3.pack &&
258 cmp tmp.idx test-1-${packname_1}.idx &&
260 git index-pack test-3.pack &&
261 cmp test-3.idx test-1-${packname_1}.idx &&
263 cat test-2-${packname_2}.pack >test-3.pack &&
264 git index-pack -o tmp.idx test-2-${packname_2}.pack &&
265 cmp tmp.idx test-2-${packname_2}.idx &&
267 git index-pack test-3.pack &&
268 cmp test-3.idx test-2-${packname_2}.idx &&
270 cat test-3-${packname_3}.pack >test-3.pack &&
271 git index-pack -o tmp.idx test-3-${packname_3}.pack &&
272 cmp tmp.idx test-3-${packname_3}.idx &&
274 git index-pack test-3.pack &&
275 cmp test-3.idx test-3-${packname_3}.idx &&
279 test_expect_success \
280 'fake a SHA1 hash collision' \
281 'test -f .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67 &&
282 cp -f .git/objects/9d/235ed07cd19811a6ceb342de82f190e49c9f68 \
283 .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67'
285 test_expect_success \
286 'make sure index-pack detects the SHA1 collision' \
287 'test_must_fail git index-pack -o bad.idx test-3.pack 2>msg &&
288 grep "SHA1 COLLISION FOUND" msg'
290 test_expect_success \
291 'honor pack.packSizeLimit' \
292 'git config pack.packSizeLimit 200 &&
293 packname_4=$(git pack-objects test-4 <obj-list) &&
294 test 3 = $(ls test-4-*.pack | wc -l)'
296 test_expect_success 'setup --strict tests' '
298 git config --unset pack.packsizelimit &&
299 for j in a b c d e f g
301 for i in 0 1 2 3 4 5 6 7 8 9
303 o=$(echo $j$i | git hash-object -w --stdin) &&
304 echo "100644 $o 0 $j$i"
305 done
306 done >LIST &&
307 rm -f .git/index &&
308 git update-index --index-info <LIST &&
309 LIST=$(git write-tree) &&
310 rm -f .git/index &&
311 head -n 10 LIST | git update-index --index-info &&
312 LI=$(git write-tree) &&
313 rm -f .git/index &&
314 tail -n 10 LIST | git update-index --index-info &&
315 ST=$(git write-tree) &&
316 PACK5=$( git rev-list --objects "$LIST" "$LI" "$ST" | \
317 git pack-objects test-5 ) &&
318 PACK6=$( (
319 echo "$LIST"
320 echo "$LI"
321 echo "$ST"
322 ) | git pack-objects test-6 )
325 test_expect_success 'unpacking with --strict' '
327 test_create_repo test-5 &&
329 cd test-5 &&
330 git unpack-objects --strict <../test-5-$PACK5.pack &&
331 git ls-tree -r $LIST &&
332 git ls-tree -r $LI &&
333 git ls-tree -r $ST
334 ) &&
335 test_create_repo test-6 &&
337 # tree-only into empty repo -- many unreachables
338 cd test-6 &&
339 test_must_fail git unpack-objects --strict <../test-6-$PACK6.pack
340 ) &&
342 # already populated -- no unreachables
343 cd test-5 &&
344 git unpack-objects --strict <../test-6-$PACK6.pack
348 test_expect_success 'index-pack with --strict' '
350 test_create_repo test-7 &&
352 cd test-7 &&
353 git index-pack --strict --stdin <../test-5-$PACK5.pack &&
354 git ls-tree -r $LIST &&
355 git ls-tree -r $LI &&
356 git ls-tree -r $ST
357 ) &&
358 test_create_repo test-8 &&
360 # tree-only into empty repo -- many unreachables
361 cd test-8 &&
362 test_must_fail git index-pack --strict --stdin <../test-6-$PACK6.pack
363 ) &&
365 # already populated -- no unreachables
366 cd test-7 &&
367 git index-pack --strict --stdin <../test-6-$PACK6.pack
371 test_expect_success 'tolerate absurdly small packsizelimit' '
372 git config pack.packSizeLimit 2 &&
373 packname_9=$(git pack-objects test-9 <obj-list) &&
374 test $(wc -l <obj-list) = $(ls test-9-*.pack | wc -l)
377 test_done