Skip more symbolic link tests.
[git/mingw.git] / t / t5300-pack-object.sh
blob83c67c4a5af1b3317a4041c205a8e2af6a4a8ff9
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 catches mismatched .idx and .pack files' \
207 'cat test-1-${packname_1}.idx >test-3.idx &&
208 cat test-2-${packname_2}.pack >test-3.pack &&
209 if git verify-pack test-3.idx
210 then false
211 else :;
214 test_expect_success \
215 'verify-pack catches a corrupted pack signature' \
216 'corrupt test-1-${packname_1}.pack test-3.pack 1 2 &&
217 if git verify-pack test-3.idx
218 then false
219 else :;
222 test_expect_success \
223 'verify-pack catches a corrupted pack version' \
224 'corrupt test-1-${packname_1}.pack test-3.pack 1 7 &&
225 if git verify-pack test-3.idx
226 then false
227 else :;
230 test_expect_success \
231 'verify-pack catches a corrupted type/size of the 1st packed object data' \
232 'corrupt test-1-${packname_1}.pack test-3.pack 1 12 &&
233 if git verify-pack test-3.idx
234 then false
235 else :;
238 test_expect_success \
239 'verify-pack catches a corrupted sum of the index file itself' \
240 'l=`wc -c <test-3.idx` &&
241 l=`expr $l - 20` &&
242 corrupt test-1-${packname_1}.pack test-3.pack 20 $l &&
243 if git verify-pack test-3.pack
244 then false
245 else :;
248 test_expect_success \
249 'build pack index for an existing pack' \
250 'cat test-1-${packname_1}.pack >test-3.pack &&
251 git-index-pack -o tmp.idx test-3.pack &&
252 cmp tmp.idx test-1-${packname_1}.idx &&
254 git-index-pack test-3.pack &&
255 cmp test-3.idx test-1-${packname_1}.idx &&
257 cat test-2-${packname_2}.pack >test-3.pack &&
258 git-index-pack -o tmp.idx test-2-${packname_2}.pack &&
259 cmp tmp.idx test-2-${packname_2}.idx &&
261 git-index-pack test-3.pack &&
262 cmp test-3.idx test-2-${packname_2}.idx &&
264 cat test-3-${packname_3}.pack >test-3.pack &&
265 git-index-pack -o tmp.idx test-3-${packname_3}.pack &&
266 cmp tmp.idx test-3-${packname_3}.idx &&
268 git-index-pack test-3.pack &&
269 cmp test-3.idx test-3-${packname_3}.idx &&
273 test_expect_success \
274 'fake a SHA1 hash collision' \
275 'test -f .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67 &&
276 cp -f .git/objects/9d/235ed07cd19811a6ceb342de82f190e49c9f68 \
277 .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67'
279 test_expect_success \
280 'make sure index-pack detects the SHA1 collision' \
281 '! git-index-pack -o bad.idx test-3.pack'
283 test_expect_success \
284 'honor pack.packSizeLimit' \
285 'git config pack.packSizeLimit 200 &&
286 packname_4=$(git pack-objects test-4 <obj-list) &&
287 test 3 = $(ls test-4-*.pack | wc -l)'
289 test_expect_success 'unpacking with --strict' '
291 git config --unset pack.packsizelimit &&
292 for j in a b c d e f g
294 for i in 0 1 2 3 4 5 6 7 8 9
296 o=$(echo $j$i | git hash-object -w --stdin) &&
297 echo "100644 $o 0 $j$i"
298 done
299 done >LIST &&
300 rm -f .git/index &&
301 git update-index --index-info <LIST &&
302 LIST=$(git write-tree) &&
303 rm -f .git/index &&
304 head -n 10 LIST | git update-index --index-info &&
305 LI=$(git write-tree) &&
306 rm -f .git/index &&
307 tail -n 10 LIST | git update-index --index-info &&
308 ST=$(git write-tree) &&
309 PACK5=$( git rev-list --objects "$LIST" "$LI" "$ST" | \
310 git pack-objects test-5 ) &&
311 PACK6=$( (
312 echo "$LIST"
313 echo "$LI"
314 echo "$ST"
315 ) | git pack-objects test-6 ) &&
316 test_create_repo test-5 &&
318 cd test-5 &&
319 git unpack-objects --strict <../test-5-$PACK5.pack &&
320 git ls-tree -r $LIST &&
321 git ls-tree -r $LI &&
322 git ls-tree -r $ST
323 ) &&
324 test_create_repo test-6 &&
326 # tree-only into empty repo -- many unreachables
327 cd test-6 &&
328 test_must_fail git unpack-objects --strict <../test-6-$PACK6.pack
329 ) &&
331 # already populated -- no unreachables
332 cd test-5 &&
333 git unpack-objects --strict <../test-6-$PACK6.pack
337 test_expect_success 'index-pack with --strict' '
339 for j in a b c d e f g
341 for i in 0 1 2 3 4 5 6 7 8 9
343 o=$(echo $j$i | git hash-object -w --stdin) &&
344 echo "100644 $o 0 $j$i"
345 done
346 done >LIST &&
347 rm -f .git/index &&
348 git update-index --index-info <LIST &&
349 LIST=$(git write-tree) &&
350 rm -f .git/index &&
351 head -n 10 LIST | git update-index --index-info &&
352 LI=$(git write-tree) &&
353 rm -f .git/index &&
354 tail -n 10 LIST | git update-index --index-info &&
355 ST=$(git write-tree) &&
356 PACK5=$( git rev-list --objects "$LIST" "$LI" "$ST" | \
357 git pack-objects test-5 ) &&
358 PACK6=$( (
359 echo "$LIST"
360 echo "$LI"
361 echo "$ST"
362 ) | git pack-objects test-6 ) &&
363 test_create_repo test-7 &&
365 cd test-7 &&
366 git index-pack --strict --stdin <../test-5-$PACK5.pack &&
367 git ls-tree -r $LIST &&
368 git ls-tree -r $LI &&
369 git ls-tree -r $ST
370 ) &&
371 test_create_repo test-8 &&
373 # tree-only into empty repo -- many unreachables
374 cd test-8 &&
375 test_must_fail git index-pack --strict --stdin <../test-6-$PACK6.pack
376 ) &&
378 # already populated -- no unreachables
379 cd test-7 &&
380 git index-pack --strict --stdin <../test-6-$PACK6.pack
384 test_done