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 \
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
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
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
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
244 test_expect_success \
245 'verify-pack catches a corrupted sum of the index file itself' \
246 'l=`wc -c <test-3.idx` &&
248 corrupt test-1-${packname_1}.pack test-3.pack 20 $l &&
249 if git verify-pack test-3.pack
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"
308 git update-index --index-info <LIST &&
309 LIST=$(git write-tree) &&
311 head -n 10 LIST | git update-index --index-info &&
312 LI=$(git write-tree) &&
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 ) &&
322 ) | git pack-objects test-6 )
325 test_expect_success
'unpacking with --strict' '
327 test_create_repo test-5 &&
330 git unpack-objects --strict <../test-5-$PACK5.pack &&
331 git ls-tree -r $LIST &&
332 git ls-tree -r $LI &&
335 test_create_repo test-6 &&
337 # tree-only into empty repo -- many unreachables
339 test_must_fail git unpack-objects --strict <../test-6-$PACK6.pack
342 # already populated -- no unreachables
344 git unpack-objects --strict <../test-6-$PACK6.pack
348 test_expect_success
'index-pack with --strict' '
350 test_create_repo test-7 &&
353 git index-pack --strict --stdin <../test-5-$PACK5.pack &&
354 git ls-tree -r $LIST &&
355 git ls-tree -r $LI &&
358 test_create_repo test-8 &&
360 # tree-only into empty repo -- many unreachables
362 test_must_fail git index-pack --strict --stdin <../test-6-$PACK6.pack
365 # already populated -- no unreachables
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)