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