Work around failures due to bogus quoting of ^ and {}.
[git/platforms.git] / t / t5300-pack-object.sh
bloba232f41edf3196d97abd698fb7aae03ce87a83a8
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='git-pack-object
9 . ./test-lib.sh
11 TRASH=`pwd`
13 x4k=xxxxxxxx
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"
18 corrupt()
21 read -d "" -n $4 l
22 echo -n "$l"
23 read -d "" -n $3 l
24 echo -n ${x4k:0:$3} | tr x '\0'
25 cat
26 ) < $1 > $2
29 test "$no_symlinks" && {
30 stat() {
31 ls -l "$3" | tr -s ' ' ' ' | cut -d' ' -f5
35 test_expect_success \
36 'setup' \
37 'rm -f .git/index*
38 for i in a b c
40 echo -n "$x4k" | tr x $i >$i &&
41 git update-index --add $i || return 1
42 done &&
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` && {
46 echo $tree &&
47 echo $commit &&
48 git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
49 } >obj-list && {
50 git diff-tree --root -p $commit &&
51 while read object
53 t=`git cat-file -t $object` &&
54 git cat-file $t $object || return 1
55 done <obj-list
56 } >expect'
58 test_expect_success \
59 'pack without delta' \
60 'packname_1=$(git pack-objects --window=0 test-1 <obj-list)'
62 rm -fr .git2
63 mkdir .git2
65 test_expect_success \
66 'unpack without delta' \
67 "GIT_OBJECT_DIRECTORY=.git2/objects &&
68 export GIT_OBJECT_DIRECTORY &&
69 git init &&
70 git unpack-objects -n <test-1-${packname_1}.pack &&
71 git unpack-objects <test-1-${packname_1}.pack"
73 unset GIT_OBJECT_DIRECTORY
74 cd "$TRASH/.git2"
76 test_expect_success \
77 'check unpack without delta' \
78 '(cd ../.git && /usr/bin/find objects -type f -print) |
79 while read path
81 cmp $path ../.git/$path || {
82 echo $path differs.
83 return 1
85 done'
86 cd "$TRASH"
88 test_expect_success \
89 'pack with REF_DELTA' \
90 'pwd &&
91 packname_2=$(git pack-objects test-2 <obj-list)'
93 rm -fr .git2
94 mkdir .git2
96 test_expect_success \
97 'unpack with REF_DELTA' \
98 'GIT_OBJECT_DIRECTORY=.git2/objects &&
99 export GIT_OBJECT_DIRECTORY &&
100 git init &&
101 git unpack-objects -n <test-2-${packname_2}.pack &&
102 git unpack-objects <test-2-${packname_2}.pack'
104 unset GIT_OBJECT_DIRECTORY
105 cd "$TRASH/.git2"
106 test_expect_success \
107 'check unpack with REF_DELTA' \
108 '(cd ../.git && /usr/bin/find objects -type f -print) |
109 while read path
111 cmp $path ../.git/$path || {
112 echo $path differs.
113 return 1
115 done'
116 cd "$TRASH"
118 test_expect_success \
119 'pack with OFS_DELTA' \
120 'pwd &&
121 packname_3=$(git pack-objects --delta-base-offset test-3 <obj-list)'
123 rm -fr .git2
124 mkdir .git2
126 test_expect_success \
127 'unpack with OFS_DELTA' \
128 'GIT_OBJECT_DIRECTORY=.git2/objects &&
129 export GIT_OBJECT_DIRECTORY &&
130 git init &&
131 git unpack-objects -n <test-3-${packname_3}.pack &&
132 git unpack-objects <test-3-${packname_3}.pack'
134 unset GIT_OBJECT_DIRECTORY
135 cd "$TRASH/.git2"
136 test_expect_success \
137 'check unpack with OFS_DELTA' \
138 '(cd ../.git && /usr/bin/find objects -type f -print) |
139 while read path
141 cmp $path ../.git/$path || {
142 echo $path differs.
143 return 1
145 done'
146 cd "$TRASH"
148 test_expect_success 'compare delta flavors' '
149 perl -e '\''
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
155 rm -fr .git2
156 mkdir .git2
158 test_expect_success \
159 'use packed objects' \
160 'GIT_OBJECT_DIRECTORY=.git2/objects &&
161 export GIT_OBJECT_DIRECTORY &&
162 git init &&
163 cp test-1-${packname_1}.pack test-1-${packname_1}.idx .git2/objects/pack && {
164 git diff-tree --root -p $commit &&
165 while read object
167 t=`git cat-file -t $object` &&
168 git cat-file $t $object || return 1
169 done <obj-list
170 } >current &&
171 diff expect current'
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 &&
180 while read object
182 t=`git cat-file -t $object` &&
183 git cat-file $t $object || return 1
184 done <obj-list
185 } >current &&
186 diff expect current'
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 &&
195 while read object
197 t=`git cat-file -t $object` &&
198 git cat-file $t $object || return 1
199 done <obj-list
200 } >current &&
201 diff expect current'
203 unset GIT_OBJECT_DIRECTORY
205 test_expect_success \
206 'verify pack' \
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
216 then false
217 else :;
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
224 then false
225 else :;
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
232 then false
233 else :;
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
240 then false
241 else :;
244 test_expect_success \
245 'verify-pack catches a corrupted sum of the index file itself' \
246 'l=`wc -c <test-3.idx` &&
247 l=`expr $l - 20` &&
248 corrupt test-1-${packname_1}.pack test-3.pack 20 $l &&
249 if git verify-pack test-3.pack
250 then false
251 else :;
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'
289 test_done