3 # Copyright (C) 2005 Rene Scharfe
6 test_description
='git tar-tree and git get-tar-commit-id test
8 This test covers the topics of file contents, commit date handling and
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
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.
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
30 GUNZIP
=${GUNZIP:-gzip -d}
37 echo simple textfile >a/a &&
40 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
41 printf "A not substituted O" >a/substfile2 &&
42 if test_have_prereq SYMLINKS; then
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'
54 'echo ignore me >a/ignored &&
55 echo ignored export-ignore >.git/info/attributes'
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)'
68 'git clone --bare . bare.git &&
69 cp .git/info/attributes bare.git/info/attributes'
72 'remove ignored file' \
77 'git archive HEAD >b.tar'
81 'git tar-tree HEAD >b2.tar'
84 'git archive vs. git tar-tree' \
85 'test_cmp b.tar b2.tar'
87 test_expect_success
'git archive on large files' '
88 test_config core.bigfilethreshold 1 &&
89 git archive HEAD >b3.tar &&
94 'git archive in a bare repo' \
95 '(cd bare.git && git archive HEAD) >b3.tar'
98 'git archive vs. the same in a bare repo' \
99 'test_cmp b.tar b3.tar'
101 test_expect_success
'git archive with --output' \
102 'git archive --output=b4.tar HEAD &&
103 test_cmp b.tar b4.tar'
105 test_expect_success
'git archive --remote' \
106 'git archive --remote=. HEAD >b5.tar &&
107 test_cmp b.tar b5.tar'
109 test_expect_success \
110 'validate file modification time' \
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'
117 test_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'
122 test_expect_success \
123 'extract tar archive' \
124 '(cd b && "$TAR" xf -) <b.tar'
126 test_expect_success \
127 'validate filenames' \
128 '(cd b/a && find .) | sort >b.lst &&
129 test_cmp a.lst b.lst'
131 test_expect_success \
132 'validate file contents' \
135 test_expect_success \
136 'git tar-tree with prefix' \
137 'git tar-tree HEAD prefix >c.tar'
139 test_expect_success \
140 'extract tar archive with prefix' \
141 '(cd c && "$TAR" xf -) <c.tar'
143 test_expect_success \
144 'validate filenames with prefix' \
145 '(cd c/prefix/a && find .) | sort >c.lst &&
146 test_cmp a.lst c.lst'
148 test_expect_success \
149 'validate file contents with prefix' \
150 'diff -r a c/prefix/a'
152 test_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'
160 test_expect_success \
161 'extract substfiles' \
162 '(mkdir f && cd f && "$TAR" xf -) <f.tar'
164 test_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
172 test_expect_success \
173 'extract substfiles from archive with prefix' \
174 '(mkdir g && cd g && "$TAR" xf -) <g.tar'
176 test_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
184 test_expect_success \
185 'git archive --format=zip' \
186 'git archive --format=zip HEAD >d.zip'
188 test_expect_success \
189 'git archive --format=zip in a bare repo' \
190 '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
192 test_expect_success \
193 'git archive --format=zip vs. the same in a bare repo' \
194 'test_cmp d.zip d1.zip'
196 test_expect_success
'git archive --format=zip with --output' \
197 'git archive --format=zip --output=d2.zip HEAD &&
198 test_cmp d.zip d2.zip'
200 test_expect_success
'git archive with --output, inferring format' '
201 git archive --output=d3.zip HEAD &&
202 test_cmp d.zip d3.zip
205 test_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
210 $UNZIP -v >/dev
/null
2>&1
211 if [ $?
-eq 127 ]; then
212 say
"Skipping ZIP tests, because unzip was not found"
214 test_set_prereq UNZIP
217 test_expect_success UNZIP \
218 'extract ZIP archive' \
219 '(mkdir d && cd d && $UNZIP ../d.zip)'
221 test_expect_success UNZIP \
222 'validate filenames' \
223 '(cd d/a && find .) | sort >d.lst &&
224 test_cmp a.lst d.lst'
226 test_expect_success UNZIP \
227 'validate file contents' \
230 test_expect_success \
231 'git archive --format=zip with prefix' \
232 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
234 test_expect_success UNZIP \
235 'extract ZIP archive with prefix' \
236 '(mkdir e && cd e && $UNZIP ../e.zip)'
238 test_expect_success UNZIP \
239 'validate filenames with prefix' \
240 '(cd e/prefix/a && find .) | sort >e.lst &&
241 test_cmp a.lst e.lst'
243 test_expect_success UNZIP \
244 'validate file contents with prefix' \
245 'diff -r a e/prefix/a'
247 test_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)
253 test_expect_success UNZIP
'git archive --format=zip on large files' '
254 test_config core.bigfilethreshold 1 &&
255 git archive --format=zip HEAD >large-compressed.zip &&
256 (mkdir large-compressed && cd large-compressed && $UNZIP ../large-compressed.zip) &&
257 test_cmp large-compressed/a/bin/sh large/a/bin/sh
260 test_expect_success \
261 'git archive --list outside of a git repo' \
262 'GIT_DIR=some/non-existing/directory git archive --list'
264 test_expect_success
'clients cannot access unreachable commits' '
265 test_commit unreachable &&
266 sha1=`git rev-parse HEAD` &&
267 git reset --hard HEAD^ &&
268 git archive $sha1 >remote.tar &&
269 test_must_fail git archive --remote=. $sha1 >remote.tar
272 test_expect_success
'git-archive --prefix=olde-' '
273 git archive --prefix=olde- >h.tar HEAD &&
277 "$TAR" xf - <../h.tar
280 test -d h/olde-a/bin &&
281 test -f h/olde-a/bin/sh
284 test_expect_success
'setup tar filters' '
285 git config tar.tar.foo.command "tr ab ba" &&
286 git config tar.bar.command "tr ab ba" &&
287 git config tar.bar.remote true
290 test_expect_success
'archive --list mentions user filter' '
291 git archive --list >output &&
292 grep "^tar\.foo\$" output &&
296 test_expect_success
'archive --list shows only enabled remote filters' '
297 git archive --list --remote=. >output &&
298 ! grep "^tar\.foo\$" output &&
302 test_expect_success
'invoke tar filter by format' '
303 git archive --format=tar.foo HEAD >config.tar.foo &&
304 tr ab ba <config.tar.foo >config.tar &&
305 test_cmp b.tar config.tar &&
306 git archive --format=bar HEAD >config.bar &&
307 tr ab ba <config.bar >config.tar &&
308 test_cmp b.tar config.tar
311 test_expect_success
'invoke tar filter by extension' '
312 git archive -o config-implicit.tar.foo HEAD &&
313 test_cmp config.tar.foo config-implicit.tar.foo &&
314 git archive -o config-implicit.bar HEAD &&
315 test_cmp config.tar.foo config-implicit.bar
318 test_expect_success
'default output format remains tar' '
319 git archive -o config-implicit.baz HEAD &&
320 test_cmp b.tar config-implicit.baz
323 test_expect_success
'extension matching requires dot' '
324 git archive -o config-implicittar.foo HEAD &&
325 test_cmp b.tar config-implicittar.foo
328 test_expect_success
'only enabled filters are available remotely' '
329 test_must_fail git archive --remote=. --format=tar.foo HEAD \
331 git archive --remote=. --format=bar >remote.bar HEAD &&
332 test_cmp remote.bar config.bar
335 if $GZIP --version >/dev
/null
2>&1; then
338 say
"Skipping some tar.gz tests because gzip not found"
341 test_expect_success GZIP
'git archive --format=tgz' '
342 git archive --format=tgz HEAD >j.tgz
345 test_expect_success GZIP
'git archive --format=tar.gz' '
346 git archive --format=tar.gz HEAD >j1.tar.gz &&
347 test_cmp j.tgz j1.tar.gz
350 test_expect_success GZIP
'infer tgz from .tgz filename' '
351 git archive --output=j2.tgz HEAD &&
352 test_cmp j.tgz j2.tgz
355 test_expect_success GZIP
'infer tgz from .tar.gz filename' '
356 git archive --output=j3.tar.gz HEAD &&
357 test_cmp j.tgz j3.tar.gz
360 if $GUNZIP --version >/dev
/null
2>&1; then
361 test_set_prereq GUNZIP
363 say
"Skipping some tar.gz tests because gunzip was not found"
366 test_expect_success GZIP
,GUNZIP
'extract tgz file' '
367 $GUNZIP -c <j.tgz >j.tar &&
371 test_expect_success GZIP
'remote tar.gz is allowed by default' '
372 git archive --remote=. --format=tar.gz HEAD >remote.tar.gz &&
373 test_cmp j.tgz remote.tar.gz
376 test_expect_success GZIP
'remote tar.gz can be disabled' '
377 git config tar.tar.gz.remote false &&
378 test_must_fail git archive --remote=. --format=tar.gz HEAD \