]>
Commit | Line | Data |
---|---|---|
d3d49c3d RS |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (C) 2005 Rene Scharfe | |
4 | # | |
5 | ||
5be60078 | 6 | test_description='git tar-tree and git get-tar-commit-id test |
d3d49c3d | 7 | |
5b860406 RS |
8 | This test covers the topics of file contents, commit date handling and |
9 | commit id embedding: | |
d3d49c3d RS |
10 | |
11 | The contents of the repository is compared to the extracted tar | |
12 | archive. The repository contains simple text files, symlinks and a | |
3dff5379 | 13 | binary file (/bin/sh). Only paths shorter than 99 characters are |
5b860406 | 14 | used. |
d3d49c3d | 15 | |
5be60078 | 16 | git tar-tree applies the commit date to every file in the archive it |
d3d49c3d RS |
17 | creates. The test sets the commit date to a specific value and checks |
18 | if the tar archive contains that value. | |
19 | ||
5be60078 | 20 | When giving git tar-tree a commit id (in contrast to a tree id) it |
d3d49c3d | 21 | embeds this commit id into the tar archive as a comment. The test |
5be60078 | 22 | checks the ability of git get-tar-commit-id to figure it out from the |
d3d49c3d RS |
23 | tar file. |
24 | ||
25 | ' | |
26 | ||
27 | . ./test-lib.sh | |
62cdce17 | 28 | UNZIP=${UNZIP:-unzip} |
0e804e09 JK |
29 | GZIP=${GZIP:-gzip} |
30 | GUNZIP=${GUNZIP:-gzip -d} | |
d3d49c3d | 31 | |
38c9c9b7 | 32 | SUBSTFORMAT=%H%n |
8460b2fc | 33 | |
2dd42334 RS |
34 | check_zip() { |
35 | zipfile=$1.zip | |
36 | listfile=$1.lst | |
37 | dir=$1 | |
38 | dir_with_prefix=$dir/$2 | |
39 | ||
40 | test_expect_success UNZIP " extract ZIP archive" " | |
41 | (mkdir $dir && cd $dir && $UNZIP ../$zipfile) | |
42 | " | |
43 | ||
44 | test_expect_success UNZIP " validate filenames" " | |
45 | (cd ${dir_with_prefix}a && find .) | sort >$listfile && | |
46 | test_cmp a.lst $listfile | |
47 | " | |
48 | ||
49 | test_expect_success UNZIP " validate file contents" " | |
50 | diff -r a ${dir_with_prefix}a | |
51 | " | |
52 | } | |
53 | ||
d3d49c3d RS |
54 | test_expect_success \ |
55 | 'populate workdir' \ | |
56 | 'mkdir a b c && | |
d3d49c3d | 57 | echo simple textfile >a/a && |
d3d49c3d | 58 | mkdir a/bin && |
5b860406 | 59 | cp /bin/sh a/bin && |
760da960 RS |
60 | printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 && |
61 | printf "A not substituted O" >a/substfile2 && | |
704a3143 JS |
62 | if test_have_prereq SYMLINKS; then |
63 | ln -s a a/l1 | |
64 | else | |
65 | printf %s a > a/l1 | |
66 | fi && | |
4c691724 RS |
67 | (p=long_path_to_a_file && cd a && |
68 | for depth in 1 2 3 4 5; do mkdir $p && cd $p; done && | |
69 | echo text >file_with_long_path) && | |
d3d49c3d RS |
70 | (cd a && find .) | sort >a.lst' |
71 | ||
008d896d RS |
72 | test_expect_success \ |
73 | 'add ignored file' \ | |
74 | 'echo ignore me >a/ignored && | |
ad94657f | 75 | echo ignored export-ignore >.git/info/attributes' |
008d896d | 76 | |
d3d49c3d RS |
77 | test_expect_success \ |
78 | 'add files to repository' \ | |
5be60078 JH |
79 | 'find a -type f | xargs git update-index --add && |
80 | find a -type l | xargs git update-index --add && | |
81 | treeid=`git write-tree` && | |
d3d49c3d | 82 | echo $treeid >treeid && |
5be60078 JH |
83 | git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \ |
84 | git commit-tree $treeid </dev/null)' | |
d3d49c3d | 85 | |
ddff8563 CB |
86 | test_expect_success \ |
87 | 'create bare clone' \ | |
88 | 'git clone --bare . bare.git && | |
ad94657f | 89 | cp .git/info/attributes bare.git/info/attributes' |
ddff8563 | 90 | |
008d896d RS |
91 | test_expect_success \ |
92 | 'remove ignored file' \ | |
93 | 'rm a/ignored' | |
94 | ||
8ff21b1a | 95 | test_expect_success \ |
5be60078 JH |
96 | 'git archive' \ |
97 | 'git archive HEAD >b.tar' | |
8ff21b1a | 98 | |
d3d49c3d | 99 | test_expect_success \ |
5be60078 JH |
100 | 'git tar-tree' \ |
101 | 'git tar-tree HEAD >b2.tar' | |
8ff21b1a RS |
102 | |
103 | test_expect_success \ | |
5be60078 | 104 | 'git archive vs. git tar-tree' \ |
188c3827 | 105 | 'test_cmp b.tar b2.tar' |
d3d49c3d | 106 | |
5544049d NTND |
107 | test_expect_success 'git archive on large files' ' |
108 | test_config core.bigfilethreshold 1 && | |
109 | git archive HEAD >b3.tar && | |
110 | test_cmp b.tar b3.tar | |
111 | ' | |
112 | ||
ddff8563 CB |
113 | test_expect_success \ |
114 | 'git archive in a bare repo' \ | |
115 | '(cd bare.git && git archive HEAD) >b3.tar' | |
116 | ||
117 | test_expect_success \ | |
118 | 'git archive vs. the same in a bare repo' \ | |
119 | 'test_cmp b.tar b3.tar' | |
120 | ||
aec0c1bb CMDV |
121 | test_expect_success 'git archive with --output' \ |
122 | 'git archive --output=b4.tar HEAD && | |
123 | test_cmp b.tar b4.tar' | |
124 | ||
1bc01efe | 125 | test_expect_success 'git archive --remote' \ |
48139269 TR |
126 | 'git archive --remote=. HEAD >b5.tar && |
127 | test_cmp b.tar b5.tar' | |
128 | ||
d3d49c3d RS |
129 | test_expect_success \ |
130 | 'validate file modification time' \ | |
30684dfa | 131 | 'mkdir extract && |
bfce5087 | 132 | "$TAR" xf b.tar -C extract a/a && |
111539a3 | 133 | test-chmtime -v +0 extract/a/a |cut -f 1 >b.mtime && |
30684dfa | 134 | echo "1117231200" >expected.mtime && |
188c3827 | 135 | test_cmp expected.mtime b.mtime' |
d3d49c3d RS |
136 | |
137 | test_expect_success \ | |
5be60078 JH |
138 | 'git get-tar-commit-id' \ |
139 | 'git get-tar-commit-id <b.tar >b.commitid && | |
188c3827 | 140 | test_cmp .git/$(git symbolic-ref HEAD) b.commitid' |
d3d49c3d RS |
141 | |
142 | test_expect_success \ | |
143 | 'extract tar archive' \ | |
bfce5087 | 144 | '(cd b && "$TAR" xf -) <b.tar' |
d3d49c3d RS |
145 | |
146 | test_expect_success \ | |
147 | 'validate filenames' \ | |
148 | '(cd b/a && find .) | sort >b.lst && | |
188c3827 | 149 | test_cmp a.lst b.lst' |
d3d49c3d RS |
150 | |
151 | test_expect_success \ | |
152 | 'validate file contents' \ | |
153 | 'diff -r a b/a' | |
154 | ||
155 | test_expect_success \ | |
5be60078 JH |
156 | 'git tar-tree with prefix' \ |
157 | 'git tar-tree HEAD prefix >c.tar' | |
d3d49c3d RS |
158 | |
159 | test_expect_success \ | |
160 | 'extract tar archive with prefix' \ | |
bfce5087 | 161 | '(cd c && "$TAR" xf -) <c.tar' |
d3d49c3d RS |
162 | |
163 | test_expect_success \ | |
164 | 'validate filenames with prefix' \ | |
165 | '(cd c/prefix/a && find .) | sort >c.lst && | |
188c3827 | 166 | test_cmp a.lst c.lst' |
d3d49c3d RS |
167 | |
168 | test_expect_success \ | |
169 | 'validate file contents with prefix' \ | |
170 | 'diff -r a c/prefix/a' | |
171 | ||
8460b2fc | 172 | test_expect_success \ |
ac7fa277 | 173 | 'create archives with substfiles' \ |
ad94657f RS |
174 | 'cp .git/info/attributes .git/info/attributes.before && |
175 | echo "substfile?" export-subst >>.git/info/attributes && | |
8460b2fc | 176 | git archive HEAD >f.tar && |
ac7fa277 | 177 | git archive --prefix=prefix/ HEAD >g.tar && |
ad94657f | 178 | mv .git/info/attributes.before .git/info/attributes' |
8460b2fc RS |
179 | |
180 | test_expect_success \ | |
760da960 | 181 | 'extract substfiles' \ |
bfce5087 | 182 | '(mkdir f && cd f && "$TAR" xf -) <f.tar' |
8460b2fc RS |
183 | |
184 | test_expect_success \ | |
38c9c9b7 RS |
185 | 'validate substfile contents' \ |
186 | 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \ | |
760da960 | 187 | >f/a/substfile1.expected && |
188c3827 MV |
188 | test_cmp f/a/substfile1.expected f/a/substfile1 && |
189 | test_cmp a/substfile2 f/a/substfile2 | |
760da960 | 190 | ' |
8460b2fc | 191 | |
ac7fa277 RS |
192 | test_expect_success \ |
193 | 'extract substfiles from archive with prefix' \ | |
bfce5087 | 194 | '(mkdir g && cd g && "$TAR" xf -) <g.tar' |
ac7fa277 RS |
195 | |
196 | test_expect_success \ | |
197 | 'validate substfile contents from archive with prefix' \ | |
198 | 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \ | |
199 | >g/prefix/a/substfile1.expected && | |
188c3827 MV |
200 | test_cmp g/prefix/a/substfile1.expected g/prefix/a/substfile1 && |
201 | test_cmp a/substfile2 g/prefix/a/substfile2 | |
ac7fa277 RS |
202 | ' |
203 | ||
2dd42334 RS |
204 | $UNZIP -v >/dev/null 2>&1 |
205 | if [ $? -eq 127 ]; then | |
206 | say "Skipping ZIP tests, because unzip was not found" | |
207 | else | |
208 | test_set_prereq UNZIP | |
209 | fi | |
210 | ||
62cdce17 | 211 | test_expect_success \ |
5be60078 JH |
212 | 'git archive --format=zip' \ |
213 | 'git archive --format=zip HEAD >d.zip' | |
62cdce17 | 214 | |
2dd42334 RS |
215 | check_zip d |
216 | ||
ddff8563 CB |
217 | test_expect_success \ |
218 | 'git archive --format=zip in a bare repo' \ | |
219 | '(cd bare.git && git archive --format=zip HEAD) >d1.zip' | |
220 | ||
221 | test_expect_success \ | |
222 | 'git archive --format=zip vs. the same in a bare repo' \ | |
223 | 'test_cmp d.zip d1.zip' | |
224 | ||
aec0c1bb CMDV |
225 | test_expect_success 'git archive --format=zip with --output' \ |
226 | 'git archive --format=zip --output=d2.zip HEAD && | |
227 | test_cmp d.zip d2.zip' | |
228 | ||
fe12d8e8 RS |
229 | test_expect_success 'git archive with --output, inferring format' ' |
230 | git archive --output=d3.zip HEAD && | |
231 | test_cmp d.zip d3.zip | |
232 | ' | |
233 | ||
234 | test_expect_success 'git archive with --output, override inferred format' ' | |
235 | git archive --format=tar --output=d4.zip HEAD && | |
236 | test_cmp b.tar d4.zip | |
237 | ' | |
238 | ||
62cdce17 | 239 | test_expect_success \ |
5be60078 JH |
240 | 'git archive --format=zip with prefix' \ |
241 | 'git archive --format=zip --prefix=prefix/ HEAD >e.zip' | |
62cdce17 | 242 | |
2dd42334 | 243 | check_zip e prefix/ |
62cdce17 | 244 | |
2dd42334 RS |
245 | test_expect_success 'git archive -0 --format=zip on large files' ' |
246 | test_config core.bigfilethreshold 1 && | |
247 | git archive -0 --format=zip HEAD >large.zip | |
248 | ' | |
62cdce17 | 249 | |
2dd42334 | 250 | check_zip large |
62cdce17 | 251 | |
2dd42334 RS |
252 | test_expect_success 'git archive --format=zip on large files' ' |
253 | test_config core.bigfilethreshold 1 && | |
254 | git archive --format=zip HEAD >large-compressed.zip | |
2158f883 RS |
255 | ' |
256 | ||
2dd42334 | 257 | check_zip large-compressed |
c743c215 | 258 | |
265d5280 | 259 | test_expect_success \ |
5be60078 JH |
260 | 'git archive --list outside of a git repo' \ |
261 | 'GIT_DIR=some/non-existing/directory git archive --list' | |
265d5280 | 262 | |
ee27ca4a JK |
263 | test_expect_success 'clients cannot access unreachable commits' ' |
264 | test_commit unreachable && | |
265 | sha1=`git rev-parse HEAD` && | |
266 | git reset --hard HEAD^ && | |
267 | git archive $sha1 >remote.tar && | |
268 | test_must_fail git archive --remote=. $sha1 >remote.tar | |
269 | ' | |
270 | ||
ebfbdb34 RS |
271 | test_expect_success 'git-archive --prefix=olde-' ' |
272 | git archive --prefix=olde- >h.tar HEAD && | |
273 | ( | |
274 | mkdir h && | |
275 | cd h && | |
276 | "$TAR" xf - <../h.tar | |
277 | ) && | |
278 | test -d h/olde-a && | |
279 | test -d h/olde-a/bin && | |
280 | test -f h/olde-a/bin/sh | |
281 | ' | |
282 | ||
767cf457 JK |
283 | test_expect_success 'setup tar filters' ' |
284 | git config tar.tar.foo.command "tr ab ba" && | |
7b97730b JK |
285 | git config tar.bar.command "tr ab ba" && |
286 | git config tar.bar.remote true | |
767cf457 JK |
287 | ' |
288 | ||
289 | test_expect_success 'archive --list mentions user filter' ' | |
290 | git archive --list >output && | |
291 | grep "^tar\.foo\$" output && | |
292 | grep "^bar\$" output | |
293 | ' | |
294 | ||
1bc01efe | 295 | test_expect_success 'archive --list shows only enabled remote filters' ' |
767cf457 | 296 | git archive --list --remote=. >output && |
7b97730b | 297 | ! grep "^tar\.foo\$" output && |
767cf457 JK |
298 | grep "^bar\$" output |
299 | ' | |
300 | ||
301 | test_expect_success 'invoke tar filter by format' ' | |
302 | git archive --format=tar.foo HEAD >config.tar.foo && | |
303 | tr ab ba <config.tar.foo >config.tar && | |
304 | test_cmp b.tar config.tar && | |
305 | git archive --format=bar HEAD >config.bar && | |
306 | tr ab ba <config.bar >config.tar && | |
307 | test_cmp b.tar config.tar | |
308 | ' | |
309 | ||
310 | test_expect_success 'invoke tar filter by extension' ' | |
311 | git archive -o config-implicit.tar.foo HEAD && | |
312 | test_cmp config.tar.foo config-implicit.tar.foo && | |
313 | git archive -o config-implicit.bar HEAD && | |
314 | test_cmp config.tar.foo config-implicit.bar | |
315 | ' | |
316 | ||
317 | test_expect_success 'default output format remains tar' ' | |
318 | git archive -o config-implicit.baz HEAD && | |
319 | test_cmp b.tar config-implicit.baz | |
320 | ' | |
321 | ||
322 | test_expect_success 'extension matching requires dot' ' | |
323 | git archive -o config-implicittar.foo HEAD && | |
324 | test_cmp b.tar config-implicittar.foo | |
325 | ' | |
326 | ||
1bc01efe | 327 | test_expect_success 'only enabled filters are available remotely' ' |
7b97730b JK |
328 | test_must_fail git archive --remote=. --format=tar.foo HEAD \ |
329 | >remote.tar.foo && | |
330 | git archive --remote=. --format=bar >remote.bar HEAD && | |
331 | test_cmp remote.bar config.bar | |
332 | ' | |
333 | ||
0e804e09 JK |
334 | if $GZIP --version >/dev/null 2>&1; then |
335 | test_set_prereq GZIP | |
336 | else | |
337 | say "Skipping some tar.gz tests because gzip not found" | |
338 | fi | |
339 | ||
340 | test_expect_success GZIP 'git archive --format=tgz' ' | |
341 | git archive --format=tgz HEAD >j.tgz | |
342 | ' | |
343 | ||
344 | test_expect_success GZIP 'git archive --format=tar.gz' ' | |
345 | git archive --format=tar.gz HEAD >j1.tar.gz && | |
346 | test_cmp j.tgz j1.tar.gz | |
347 | ' | |
348 | ||
349 | test_expect_success GZIP 'infer tgz from .tgz filename' ' | |
350 | git archive --output=j2.tgz HEAD && | |
351 | test_cmp j.tgz j2.tgz | |
352 | ' | |
353 | ||
354 | test_expect_success GZIP 'infer tgz from .tar.gz filename' ' | |
355 | git archive --output=j3.tar.gz HEAD && | |
356 | test_cmp j.tgz j3.tar.gz | |
357 | ' | |
358 | ||
359 | if $GUNZIP --version >/dev/null 2>&1; then | |
360 | test_set_prereq GUNZIP | |
361 | else | |
362 | say "Skipping some tar.gz tests because gunzip was not found" | |
363 | fi | |
364 | ||
365 | test_expect_success GZIP,GUNZIP 'extract tgz file' ' | |
366 | $GUNZIP -c <j.tgz >j.tar && | |
367 | test_cmp b.tar j.tar | |
368 | ' | |
369 | ||
1bc01efe | 370 | test_expect_success GZIP 'remote tar.gz is allowed by default' ' |
7b97730b JK |
371 | git archive --remote=. --format=tar.gz HEAD >remote.tar.gz && |
372 | test_cmp j.tgz remote.tar.gz | |
373 | ' | |
374 | ||
1bc01efe | 375 | test_expect_success GZIP 'remote tar.gz can be disabled' ' |
7b97730b JK |
376 | git config tar.tar.gz.remote false && |
377 | test_must_fail git archive --remote=. --format=tar.gz HEAD \ | |
378 | >remote.tar.gz | |
379 | ' | |
380 | ||
d3d49c3d | 381 | test_done |