3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='git-pack-object
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"
24 echo -n ${x4k:0:$3} |
tr x
'\0'
34 echo -n "$x4k" | tr x $i >$i &&
35 git update-index --add $i || return 1
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` && {
42 git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
44 git diff-tree --root -p $commit &&
47 t=`git cat-file -t $object` &&
48 git cat-file $t $object || return 1
53 'pack without delta' \
54 'packname_1=$(git pack-objects --window=0 test-1 <obj-list)'
60 'unpack without delta' \
61 "GIT_OBJECT_DIRECTORY=.git2/objects &&
62 export GIT_OBJECT_DIRECTORY &&
64 git unpack-objects -n <test-1-${packname_1}.pack &&
65 git unpack-objects <test-1-${packname_1}.pack"
67 unset GIT_OBJECT_DIRECTORY
71 'check unpack without delta' \
72 '(cd ../.git && find objects -type f -print) |
75 cmp $path ../.git/$path || {
83 'pack with REF_DELTA' \
85 packname_2=$(git pack-objects test-2 <obj-list)'
91 'unpack with REF_DELTA' \
92 'GIT_OBJECT_DIRECTORY=.git2/objects &&
93 export GIT_OBJECT_DIRECTORY &&
95 git unpack-objects -n <test-2-${packname_2}.pack &&
96 git unpack-objects <test-2-${packname_2}.pack'
98 unset GIT_OBJECT_DIRECTORY
100 test_expect_success \
101 'check unpack with REF_DELTA' \
102 '(cd ../.git && find objects -type f -print) |
105 cmp $path ../.git/$path || {
112 test_expect_success \
113 'pack with OFS_DELTA' \
115 packname_3=$(git pack-objects --delta-base-offset test-3 <obj-list)'
120 test_expect_success \
121 'unpack with OFS_DELTA' \
122 'GIT_OBJECT_DIRECTORY=.git2/objects &&
123 export GIT_OBJECT_DIRECTORY &&
125 git unpack-objects -n <test-3-${packname_3}.pack &&
126 git unpack-objects <test-3-${packname_3}.pack'
128 unset GIT_OBJECT_DIRECTORY
130 test_expect_success \
131 'check unpack with OFS_DELTA' \
132 '(cd ../.git && find objects -type f -print) |
135 cmp $path ../.git/$path || {
142 test_expect_success
'compare delta flavors' '
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
152 test_expect_success \
153 'use packed objects' \
154 'GIT_OBJECT_DIRECTORY=.git2/objects &&
155 export GIT_OBJECT_DIRECTORY &&
157 cp test-1-${packname_1}.pack test-1-${packname_1}.idx .git2/objects/pack && {
158 git diff-tree --root -p $commit &&
161 t=`git cat-file -t $object` &&
162 git cat-file $t $object || return 1
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 &&
176 t=`git cat-file -t $object` &&
177 git cat-file $t $object || return 1
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 &&
191 t=`git cat-file -t $object` &&
192 git cat-file $t $object || return 1
197 unset GIT_OBJECT_DIRECTORY
199 test_expect_success \
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
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
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
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
238 test_expect_success \
239 'verify-pack catches a corrupted sum of the index file itself' \
240 'l=`wc -c <test-3.idx` &&
242 corrupt test-1-${packname_1}.pack test-3.pack 20 $l &&
243 if git verify-pack test-3.pack
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"
301 git update-index --index-info <LIST &&
302 LIST=$(git write-tree) &&
304 head -n 10 LIST | git update-index --index-info &&
305 LI=$(git write-tree) &&
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 ) &&
315 ) | git pack-objects test-6 ) &&
316 test_create_repo test-5 &&
319 git unpack-objects --strict <../test-5-$PACK5.pack &&
320 git ls-tree -r $LIST &&
321 git ls-tree -r $LI &&
324 test_create_repo test-6 &&
326 # tree-only into empty repo -- many unreachables
328 test_must_fail git unpack-objects --strict <../test-6-$PACK6.pack
331 # already populated -- no unreachables
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"
348 git update-index --index-info <LIST &&
349 LIST=$(git write-tree) &&
351 head -n 10 LIST | git update-index --index-info &&
352 LI=$(git write-tree) &&
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 ) &&
362 ) | git pack-objects test-6 ) &&
363 test_create_repo test-7 &&
366 git index-pack --strict --stdin <../test-5-$PACK5.pack &&
367 git ls-tree -r $LIST &&
368 git ls-tree -r $LI &&
371 test_create_repo test-8 &&
373 # tree-only into empty repo -- many unreachables
375 test_must_fail git index-pack --strict --stdin <../test-6-$PACK6.pack
378 # already populated -- no unreachables
380 git index-pack --strict --stdin <../test-6-$PACK6.pack