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