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
'survive missing objects/pack directory' '
201 rm -fr missing-pack &&
202 mkdir missing-pack &&
205 GOP=.git/objects/pack
207 git index-pack --stdin --keep=test <../test-3-${packname_3}.pack &&
208 test -f $GOP/pack-${packname_3}.pack &&
209 test_cmp $GOP/pack-${packname_3}.pack ../test-3-${packname_3}.pack &&
210 test -f $GOP/pack-${packname_3}.idx &&
211 test_cmp $GOP/pack-${packname_3}.idx ../test-3-${packname_3}.idx &&
212 test -f $GOP/pack-${packname_3}.keep
216 test_expect_success \
218 'git verify-pack test-1-${packname_1}.idx \
219 test-2-${packname_2}.idx \
220 test-3-${packname_3}.idx'
222 test_expect_success \
224 'git verify-pack -v test-1-${packname_1}.idx \
225 test-2-${packname_2}.idx \
226 test-3-${packname_3}.idx'
228 test_expect_success \
229 'verify-pack catches mismatched .idx and .pack files' \
230 'cat test-1-${packname_1}.idx >test-3.idx &&
231 cat test-2-${packname_2}.pack >test-3.pack &&
232 if git verify-pack test-3.idx
237 test_expect_success \
238 'verify-pack catches a corrupted pack signature' \
239 'corrupt test-1-${packname_1}.pack test-3.pack 1 2 &&
240 if git verify-pack test-3.idx
245 test_expect_success \
246 'verify-pack catches a corrupted pack version' \
247 'corrupt test-1-${packname_1}.pack test-3.pack 1 7 &&
248 if git verify-pack test-3.idx
253 test_expect_success \
254 'verify-pack catches a corrupted type/size of the 1st packed object data' \
255 'corrupt test-1-${packname_1}.pack test-3.pack 1 12 &&
256 if git verify-pack test-3.idx
261 test_expect_success \
262 'verify-pack catches a corrupted sum of the index file itself' \
263 'l=`wc -c <test-3.idx` &&
265 corrupt test-1-${packname_1}.pack test-3.pack 20 $l &&
266 if git verify-pack test-3.pack
271 test_expect_success \
272 'build pack index for an existing pack' \
273 'cat test-1-${packname_1}.pack >test-3.pack &&
274 git index-pack -o tmp.idx test-3.pack &&
275 cmp tmp.idx test-1-${packname_1}.idx &&
277 git index-pack test-3.pack &&
278 cmp test-3.idx test-1-${packname_1}.idx &&
280 cat test-2-${packname_2}.pack >test-3.pack &&
281 git index-pack -o tmp.idx test-2-${packname_2}.pack &&
282 cmp tmp.idx test-2-${packname_2}.idx &&
284 git index-pack test-3.pack &&
285 cmp test-3.idx test-2-${packname_2}.idx &&
287 cat test-3-${packname_3}.pack >test-3.pack &&
288 git index-pack -o tmp.idx test-3-${packname_3}.pack &&
289 cmp tmp.idx test-3-${packname_3}.idx &&
291 git index-pack test-3.pack &&
292 cmp test-3.idx test-3-${packname_3}.idx &&
296 test_expect_success \
297 'fake a SHA1 hash collision' \
298 'test -f .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67 &&
299 cp -f .git/objects/9d/235ed07cd19811a6ceb342de82f190e49c9f68 \
300 .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67'
302 test_expect_success \
303 'make sure index-pack detects the SHA1 collision' \
304 'test_must_fail git index-pack -o bad.idx test-3.pack 2>msg &&
305 grep "SHA1 COLLISION FOUND" msg'
307 test_expect_success \
308 'honor pack.packSizeLimit' \
309 'git config pack.packSizeLimit 200 &&
310 packname_4=$(git pack-objects test-4 <obj-list) &&
311 test 3 = $(ls test-4-*.pack | wc -l)'
313 test_expect_success
'setup --strict tests' '
315 git config --unset pack.packsizelimit &&
316 for j in a b c d e f g
318 for i in 0 1 2 3 4 5 6 7 8 9
320 o=$(echo $j$i | git hash-object -w --stdin) &&
321 echo "100644 $o 0 $j$i"
325 git update-index --index-info <LIST &&
326 LIST=$(git write-tree) &&
328 head -n 10 LIST | git update-index --index-info &&
329 LI=$(git write-tree) &&
331 tail -n 10 LIST | git update-index --index-info &&
332 ST=$(git write-tree) &&
333 PACK5=$( git rev-list --objects "$LIST" "$LI" "$ST" | \
334 git pack-objects test-5 ) &&
339 ) | git pack-objects test-6 )
342 test_expect_success
'unpacking with --strict' '
344 test_create_repo test-5 &&
347 git unpack-objects --strict <../test-5-$PACK5.pack &&
348 git ls-tree -r $LIST &&
349 git ls-tree -r $LI &&
352 test_create_repo test-6 &&
354 # tree-only into empty repo -- many unreachables
356 test_must_fail git unpack-objects --strict <../test-6-$PACK6.pack
359 # already populated -- no unreachables
361 git unpack-objects --strict <../test-6-$PACK6.pack
365 test_expect_success
'index-pack with --strict' '
367 test_create_repo test-7 &&
370 git index-pack --strict --stdin <../test-5-$PACK5.pack &&
371 git ls-tree -r $LIST &&
372 git ls-tree -r $LI &&
375 test_create_repo test-8 &&
377 # tree-only into empty repo -- many unreachables
379 test_must_fail git index-pack --strict --stdin <../test-6-$PACK6.pack
382 # already populated -- no unreachables
384 git index-pack --strict --stdin <../test-6-$PACK6.pack
388 test_expect_success
'tolerate absurdly small packsizelimit' '
389 git config pack.packSizeLimit 2 &&
390 packname_9=$(git pack-objects test-9 <obj-list) &&
391 test $(wc -l <obj-list) = $(ls test-9-*.pack | wc -l)