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'
29 test "$no_symlinks" && {
31 ls -l "$3" |
tr -s ' ' ' ' | cut
-d' ' -f5
40 echo -n "$x4k" | tr x $i >$i &&
41 git update-index --add $i || return 1
43 cat c >d && echo foo >>d && git update-index --add d &&
44 tree=`git write-tree` &&
45 commit=`git commit-tree $tree </dev/null` && {
48 git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
50 git diff-tree --root -p $commit &&
53 t=`git cat-file -t $object` &&
54 git cat-file $t $object || return 1
59 'pack without delta' \
60 'packname_1=$(git pack-objects --window=0 test-1 <obj-list)'
66 'unpack without delta' \
67 "GIT_OBJECT_DIRECTORY=.git2/objects &&
68 export GIT_OBJECT_DIRECTORY &&
70 git unpack-objects -n <test-1-${packname_1}.pack &&
71 git unpack-objects <test-1-${packname_1}.pack"
73 unset GIT_OBJECT_DIRECTORY
77 'check unpack without delta' \
78 '(cd ../.git && /usr/bin/find objects -type f -print) |
81 cmp $path ../.git/$path || {
89 'pack with REF_DELTA' \
91 packname_2=$(git pack-objects test-2 <obj-list)'
97 'unpack with REF_DELTA' \
98 'GIT_OBJECT_DIRECTORY=.git2/objects &&
99 export GIT_OBJECT_DIRECTORY &&
101 git unpack-objects -n <test-2-${packname_2}.pack &&
102 git unpack-objects <test-2-${packname_2}.pack'
104 unset GIT_OBJECT_DIRECTORY
106 test_expect_success \
107 'check unpack with REF_DELTA' \
108 '(cd ../.git && /usr/bin/find objects -type f -print) |
111 cmp $path ../.git/$path || {
118 test_expect_success \
119 'pack with OFS_DELTA' \
121 packname_3=$(git pack-objects --delta-base-offset test-3 <obj-list)'
126 test_expect_success \
127 'unpack with OFS_DELTA' \
128 'GIT_OBJECT_DIRECTORY=.git2/objects &&
129 export GIT_OBJECT_DIRECTORY &&
131 git unpack-objects -n <test-3-${packname_3}.pack &&
132 git unpack-objects <test-3-${packname_3}.pack'
134 unset GIT_OBJECT_DIRECTORY
136 test_expect_success \
137 'check unpack with OFS_DELTA' \
138 '(cd ../.git && /usr/bin/find objects -type f -print) |
141 cmp $path ../.git/$path || {
148 test_expect_success
'compare delta flavors' '
150 defined($_ = -s $_) or die for @ARGV;
151 exit 1 if $ARGV[0] <= $ARGV[1];
152 '\'' test-2-$packname_2.pack test-3-$packname_3.pack
158 test_expect_success \
159 'use packed objects' \
160 'GIT_OBJECT_DIRECTORY=.git2/objects &&
161 export GIT_OBJECT_DIRECTORY &&
163 cp test-1-${packname_1}.pack test-1-${packname_1}.idx .git2/objects/pack && {
164 git diff-tree --root -p $commit &&
167 t=`git cat-file -t $object` &&
168 git cat-file $t $object || return 1
173 test_expect_success \
174 'use packed deltified (REF_DELTA) objects' \
175 'GIT_OBJECT_DIRECTORY=.git2/objects &&
176 export GIT_OBJECT_DIRECTORY &&
177 rm -f .git2/objects/pack/test-* &&
178 cp test-2-${packname_2}.pack test-2-${packname_2}.idx .git2/objects/pack && {
179 git diff-tree --root -p $commit &&
182 t=`git cat-file -t $object` &&
183 git cat-file $t $object || return 1
188 test_expect_success \
189 'use packed deltified (OFS_DELTA) objects' \
190 'GIT_OBJECT_DIRECTORY=.git2/objects &&
191 export GIT_OBJECT_DIRECTORY &&
192 rm -f .git2/objects/pack/test-* &&
193 cp test-3-${packname_3}.pack test-3-${packname_3}.idx .git2/objects/pack && {
194 git diff-tree --root -p $commit &&
197 t=`git cat-file -t $object` &&
198 git cat-file $t $object || return 1
203 unset GIT_OBJECT_DIRECTORY
205 test_expect_success \
207 'git verify-pack 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_failure \
286 'make sure index-pack detects the SHA1 collision' \
287 'git-index-pack -o bad.idx test-3.pack'