]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5300-pack-object.sh
pack-objects: do not accept "--index-version=version,"
[thirdparty/git.git] / t / t5300-pack-object.sh
CommitLineData
8ee378a0
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
3604e7c5 6test_description='git pack-object
8ee378a0
JH
7
8'
9. ./test-lib.sh
10
11TRASH=`pwd`
12
13test_expect_success \
14 'setup' \
a48fcd83 15 'rm -f .git/index* &&
b689ccf6
JS
16 perl -e "print \"a\" x 4096;" > a &&
17 perl -e "print \"b\" x 4096;" > b &&
18 perl -e "print \"c\" x 4096;" > c &&
07cf0f24
NP
19 test-genrandom "seed a" 2097152 > a_big &&
20 test-genrandom "seed b" 2097152 > b_big &&
21 git update-index --add a a_big b b_big c &&
5be60078
JH
22 cat c >d && echo foo >>d && git update-index --add d &&
23 tree=`git write-tree` &&
24 commit=`git commit-tree $tree </dev/null` && {
8ee378a0 25 echo $tree &&
1f688557 26 echo $commit &&
5be60078 27 git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
1f688557 28 } >obj-list && {
5be60078 29 git diff-tree --root -p $commit &&
1f688557
JH
30 while read object
31 do
5be60078
JH
32 t=`git cat-file -t $object` &&
33 git cat-file $t $object || return 1
1f688557
JH
34 done <obj-list
35 } >expect'
8ee378a0
JH
36
37test_expect_success \
38 'pack without delta' \
5be60078 39 'packname_1=$(git pack-objects --window=0 test-1 <obj-list)'
8ee378a0
JH
40
41rm -fr .git2
42mkdir .git2
43
44test_expect_success \
45 'unpack without delta' \
a61eea6a 46 "GIT_OBJECT_DIRECTORY=.git2/objects &&
8ee378a0 47 export GIT_OBJECT_DIRECTORY &&
5be60078
JH
48 git init &&
49 git unpack-objects -n <test-1-${packname_1}.pack &&
50 git unpack-objects <test-1-${packname_1}.pack"
8ee378a0
JH
51
52unset GIT_OBJECT_DIRECTORY
f07a5241 53cd "$TRASH/.git2"
8ee378a0
JH
54
55test_expect_success \
56 'check unpack without delta' \
57 '(cd ../.git && find objects -type f -print) |
58 while read path
59 do
60 cmp $path ../.git/$path || {
61 echo $path differs.
4d9d62fa 62 return 1
8ee378a0
JH
63 }
64 done'
f07a5241 65cd "$TRASH"
8ee378a0
JH
66
67test_expect_success \
ac527b0b 68 'pack with REF_DELTA' \
8ee378a0 69 'pwd &&
5be60078 70 packname_2=$(git pack-objects test-2 <obj-list)'
8ee378a0
JH
71
72rm -fr .git2
73mkdir .git2
74
75test_expect_success \
ac527b0b 76 'unpack with REF_DELTA' \
8ee378a0
JH
77 'GIT_OBJECT_DIRECTORY=.git2/objects &&
78 export GIT_OBJECT_DIRECTORY &&
5be60078
JH
79 git init &&
80 git unpack-objects -n <test-2-${packname_2}.pack &&
81 git unpack-objects <test-2-${packname_2}.pack'
8ee378a0
JH
82
83unset GIT_OBJECT_DIRECTORY
f07a5241 84cd "$TRASH/.git2"
8ee378a0 85test_expect_success \
ac527b0b 86 'check unpack with REF_DELTA' \
8ee378a0
JH
87 '(cd ../.git && find objects -type f -print) |
88 while read path
89 do
90 cmp $path ../.git/$path || {
91 echo $path differs.
4d9d62fa 92 return 1
8ee378a0
JH
93 }
94 done'
f07a5241 95cd "$TRASH"
8ee378a0 96
ac527b0b
NP
97test_expect_success \
98 'pack with OFS_DELTA' \
99 'pwd &&
5be60078 100 packname_3=$(git pack-objects --delta-base-offset test-3 <obj-list)'
ac527b0b
NP
101
102rm -fr .git2
103mkdir .git2
104
105test_expect_success \
106 'unpack with OFS_DELTA' \
107 'GIT_OBJECT_DIRECTORY=.git2/objects &&
108 export GIT_OBJECT_DIRECTORY &&
5be60078
JH
109 git init &&
110 git unpack-objects -n <test-3-${packname_3}.pack &&
111 git unpack-objects <test-3-${packname_3}.pack'
ac527b0b
NP
112
113unset GIT_OBJECT_DIRECTORY
114cd "$TRASH/.git2"
115test_expect_success \
116 'check unpack with OFS_DELTA' \
117 '(cd ../.git && find objects -type f -print) |
118 while read path
119 do
120 cmp $path ../.git/$path || {
121 echo $path differs.
122 return 1
123 }
124 done'
125cd "$TRASH"
126
d93f7c18
AL
127test_expect_success 'compare delta flavors' '
128 perl -e '\''
129 defined($_ = -s $_) or die for @ARGV;
130 exit 1 if $ARGV[0] <= $ARGV[1];
131 '\'' test-2-$packname_2.pack test-3-$packname_3.pack
132'
ac527b0b 133
1f688557
JH
134rm -fr .git2
135mkdir .git2
136
137test_expect_success \
138 'use packed objects' \
139 'GIT_OBJECT_DIRECTORY=.git2/objects &&
140 export GIT_OBJECT_DIRECTORY &&
5be60078 141 git init &&
a61eea6a 142 cp test-1-${packname_1}.pack test-1-${packname_1}.idx .git2/objects/pack && {
5be60078 143 git diff-tree --root -p $commit &&
1f688557
JH
144 while read object
145 do
5be60078
JH
146 t=`git cat-file -t $object` &&
147 git cat-file $t $object || return 1
1f688557
JH
148 done <obj-list
149 } >current &&
4fdf71be 150 test_cmp expect current'
1f688557 151
1f688557 152test_expect_success \
ac527b0b 153 'use packed deltified (REF_DELTA) objects' \
1f688557
JH
154 'GIT_OBJECT_DIRECTORY=.git2/objects &&
155 export GIT_OBJECT_DIRECTORY &&
a5878961 156 rm -f .git2/objects/pack/test-* &&
a61eea6a 157 cp test-2-${packname_2}.pack test-2-${packname_2}.idx .git2/objects/pack && {
5be60078 158 git diff-tree --root -p $commit &&
1f688557
JH
159 while read object
160 do
5be60078
JH
161 t=`git cat-file -t $object` &&
162 git cat-file $t $object || return 1
1f688557
JH
163 done <obj-list
164 } >current &&
4fdf71be 165 test_cmp expect current'
1f688557 166
ac527b0b
NP
167test_expect_success \
168 'use packed deltified (OFS_DELTA) objects' \
169 'GIT_OBJECT_DIRECTORY=.git2/objects &&
170 export GIT_OBJECT_DIRECTORY &&
a5878961 171 rm -f .git2/objects/pack/test-* &&
ac527b0b 172 cp test-3-${packname_3}.pack test-3-${packname_3}.idx .git2/objects/pack && {
5be60078 173 git diff-tree --root -p $commit &&
ac527b0b
NP
174 while read object
175 do
5be60078
JH
176 t=`git cat-file -t $object` &&
177 git cat-file $t $object || return 1
ac527b0b
NP
178 done <obj-list
179 } >current &&
4fdf71be 180 test_cmp expect current'
ac527b0b 181
f9253394
JH
182unset GIT_OBJECT_DIRECTORY
183
6e180cdc
JH
184test_expect_success 'survive missing objects/pack directory' '
185 (
186 rm -fr missing-pack &&
187 mkdir missing-pack &&
188 cd missing-pack &&
189 git init &&
190 GOP=.git/objects/pack
191 rm -fr $GOP &&
192 git index-pack --stdin --keep=test <../test-3-${packname_3}.pack &&
193 test -f $GOP/pack-${packname_3}.pack &&
194 test_cmp $GOP/pack-${packname_3}.pack ../test-3-${packname_3}.pack &&
195 test -f $GOP/pack-${packname_3}.idx &&
196 test_cmp $GOP/pack-${packname_3}.idx ../test-3-${packname_3}.idx &&
197 test -f $GOP/pack-${packname_3}.keep
198 )
199'
200
f9253394
JH
201test_expect_success \
202 'verify pack' \
5be60078 203 'git verify-pack test-1-${packname_1}.idx \
ac527b0b
NP
204 test-2-${packname_2}.idx \
205 test-3-${packname_3}.idx'
f9253394 206
4b480c67
NP
207test_expect_success \
208 'verify pack -v' \
209 'git verify-pack -v test-1-${packname_1}.idx \
210 test-2-${packname_2}.idx \
211 test-3-${packname_3}.idx'
212
f9253394 213test_expect_success \
63405283 214 'verify-pack catches mismatched .idx and .pack files' \
a5878961
JH
215 'cat test-1-${packname_1}.idx >test-3.idx &&
216 cat test-2-${packname_2}.pack >test-3.pack &&
5be60078 217 if git verify-pack test-3.idx
f9253394
JH
218 then false
219 else :;
63405283 220 fi'
f9253394 221
63405283
JS
222test_expect_success \
223 'verify-pack catches a corrupted pack signature' \
224 'cat test-1-${packname_1}.pack >test-3.pack &&
b689ccf6 225 echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=2 &&
5be60078 226 if git verify-pack test-3.idx
f9253394
JH
227 then false
228 else :;
63405283 229 fi'
f9253394 230
63405283
JS
231test_expect_success \
232 'verify-pack catches a corrupted pack version' \
233 'cat test-1-${packname_1}.pack >test-3.pack &&
b689ccf6 234 echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=7 &&
5be60078 235 if git verify-pack test-3.idx
f9253394
JH
236 then false
237 else :;
63405283 238 fi'
f9253394 239
63405283
JS
240test_expect_success \
241 'verify-pack catches a corrupted type/size of the 1st packed object data' \
242 'cat test-1-${packname_1}.pack >test-3.pack &&
b689ccf6 243 echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=12 &&
5be60078 244 if git verify-pack test-3.idx
f9253394
JH
245 then false
246 else :;
63405283 247 fi'
f9253394 248
63405283
JS
249test_expect_success \
250 'verify-pack catches a corrupted sum of the index file itself' \
251 'l=`wc -c <test-3.idx` &&
8eafa3da 252 l=`expr $l - 20` &&
a5878961 253 cat test-1-${packname_1}.pack >test-3.pack &&
b689ccf6 254 printf "%20s" "" | dd of=test-3.idx count=20 bs=1 conv=notrunc seek=$l &&
5be60078 255 if git verify-pack test-3.pack
c5ced645
JH
256 then false
257 else :;
63405283 258 fi'
f9253394 259
9cf6d335
SV
260test_expect_success \
261 'build pack index for an existing pack' \
a5878961 262 'cat test-1-${packname_1}.pack >test-3.pack &&
3604e7c5 263 git index-pack -o tmp.idx test-3.pack &&
9cf6d335
SV
264 cmp tmp.idx test-1-${packname_1}.idx &&
265
3604e7c5 266 git index-pack test-3.pack &&
9cf6d335
SV
267 cmp test-3.idx test-1-${packname_1}.idx &&
268
a5878961 269 cat test-2-${packname_2}.pack >test-3.pack &&
3604e7c5 270 git index-pack -o tmp.idx test-2-${packname_2}.pack &&
9cf6d335
SV
271 cmp tmp.idx test-2-${packname_2}.idx &&
272
3604e7c5 273 git index-pack test-3.pack &&
9cf6d335
SV
274 cmp test-3.idx test-2-${packname_2}.idx &&
275
a5878961 276 cat test-3-${packname_3}.pack >test-3.pack &&
3604e7c5 277 git index-pack -o tmp.idx test-3-${packname_3}.pack &&
ac527b0b
NP
278 cmp tmp.idx test-3-${packname_3}.idx &&
279
3604e7c5 280 git index-pack test-3.pack &&
ac527b0b
NP
281 cmp test-3.idx test-3-${packname_3}.idx &&
282
9cf6d335
SV
283 :'
284
f2898cfa 285test_expect_success 'unpacking with --strict' '
c0e809e5 286
c0e809e5
JH
287 for j in a b c d e f g
288 do
289 for i in 0 1 2 3 4 5 6 7 8 9
290 do
291 o=$(echo $j$i | git hash-object -w --stdin) &&
292 echo "100644 $o 0 $j$i"
293 done
294 done >LIST &&
295 rm -f .git/index &&
296 git update-index --index-info <LIST &&
297 LIST=$(git write-tree) &&
298 rm -f .git/index &&
299 head -n 10 LIST | git update-index --index-info &&
300 LI=$(git write-tree) &&
301 rm -f .git/index &&
302 tail -n 10 LIST | git update-index --index-info &&
303 ST=$(git write-tree) &&
304 PACK5=$( git rev-list --objects "$LIST" "$LI" "$ST" | \
305 git pack-objects test-5 ) &&
306 PACK6=$( (
307 echo "$LIST"
308 echo "$LI"
309 echo "$ST"
310 ) | git pack-objects test-6 ) &&
311 test_create_repo test-5 &&
312 (
313 cd test-5 &&
314 git unpack-objects --strict <../test-5-$PACK5.pack &&
315 git ls-tree -r $LIST &&
316 git ls-tree -r $LI &&
317 git ls-tree -r $ST
318 ) &&
319 test_create_repo test-6 &&
320 (
321 # tree-only into empty repo -- many unreachables
322 cd test-6 &&
323 test_must_fail git unpack-objects --strict <../test-6-$PACK6.pack
324 ) &&
325 (
326 # already populated -- no unreachables
327 cd test-5 &&
328 git unpack-objects --strict <../test-6-$PACK6.pack
329 )
330'
331
38a5739d
MK
332test_expect_success 'index-pack with --strict' '
333
334 for j in a b c d e f g
335 do
336 for i in 0 1 2 3 4 5 6 7 8 9
337 do
338 o=$(echo $j$i | git hash-object -w --stdin) &&
339 echo "100644 $o 0 $j$i"
340 done
341 done >LIST &&
342 rm -f .git/index &&
343 git update-index --index-info <LIST &&
344 LIST=$(git write-tree) &&
345 rm -f .git/index &&
346 head -n 10 LIST | git update-index --index-info &&
347 LI=$(git write-tree) &&
348 rm -f .git/index &&
349 tail -n 10 LIST | git update-index --index-info &&
350 ST=$(git write-tree) &&
351 PACK5=$( git rev-list --objects "$LIST" "$LI" "$ST" | \
352 git pack-objects test-5 ) &&
353 PACK6=$( (
354 echo "$LIST"
355 echo "$LI"
356 echo "$ST"
357 ) | git pack-objects test-6 ) &&
358 test_create_repo test-7 &&
359 (
360 cd test-7 &&
361 git index-pack --strict --stdin <../test-5-$PACK5.pack &&
362 git ls-tree -r $LIST &&
363 git ls-tree -r $LI &&
364 git ls-tree -r $ST
365 ) &&
366 test_create_repo test-8 &&
367 (
368 # tree-only into empty repo -- many unreachables
369 cd test-8 &&
370 test_must_fail git index-pack --strict --stdin <../test-6-$PACK6.pack
371 ) &&
372 (
373 # already populated -- no unreachables
374 cd test-7 &&
375 git index-pack --strict --stdin <../test-6-$PACK6.pack
376 )
377'
378
2fca19fb 379test_expect_success 'honor pack.packSizeLimit' '
07cf0f24 380 git config pack.packSizeLimit 3m &&
2fca19fb 381 packname_10=$(git pack-objects test-10 <obj-list) &&
07cf0f24 382 test 2 = $(ls test-10-*.pack | wc -l)
2fca19fb
NP
383'
384
385test_expect_success 'verify resulting packs' '
386 git verify-pack test-10-*.pack
387'
388
07cf0f24
NP
389test_expect_success 'tolerate packsizelimit smaller than biggest object' '
390 git config pack.packSizeLimit 1 &&
2fca19fb 391 packname_11=$(git pack-objects test-11 <obj-list) &&
720c9f7b 392 test 5 = $(ls test-11-*.pack | wc -l)
a1e4760f
NP
393'
394
2fca19fb
NP
395test_expect_success 'verify resulting packs' '
396 git verify-pack test-11-*.pack
397'
398
399#
400# WARNING!
401#
402# The following test is destructive. Please keep the next
403# two tests at the end of this file.
404#
405
406test_expect_success \
407 'fake a SHA1 hash collision' \
408 'test -f .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67 &&
409 cp -f .git/objects/9d/235ed07cd19811a6ceb342de82f190e49c9f68 \
410 .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67'
411
412test_expect_success \
413 'make sure index-pack detects the SHA1 collision' \
414 'test_must_fail git index-pack -o bad.idx test-3.pack 2>msg &&
415 grep "SHA1 COLLISION FOUND" msg'
416
8ee378a0 417test_done