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}
38 dir_with_prefix
=$dir/$2
40 test_expect_success UNZIP
" extract ZIP archive" "
41 (mkdir $dir && cd $dir && $UNZIP ../$zipfile)
44 test_expect_success UNZIP
" validate filenames" "
45 (cd ${dir_with_prefix}a && find .) | sort >$listfile &&
46 test_cmp a.lst $listfile
49 test_expect_success UNZIP
" validate file contents" "
50 diff -r a ${dir_with_prefix}a
57 echo simple textfile >a/a &&
60 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
61 printf "A not substituted O" >a/substfile2 &&
62 if test_have_prereq SYMLINKS; then
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) &&
70 (cd a && find .) | sort >a.lst'
74 'echo ignore me >a/ignored &&
75 echo ignored export-ignore >.git/info/attributes'
78 'add files to repository' \
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` &&
82 echo $treeid >treeid &&
83 git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
84 git commit-tree $treeid </dev/null)'
88 'git clone --bare . bare.git &&
89 cp .git/info/attributes bare.git/info/attributes'
92 'remove ignored file' \
97 'git archive HEAD >b.tar'
101 'git tar-tree HEAD >b2.tar'
103 test_expect_success \
104 'git archive vs. git tar-tree' \
105 'test_cmp b.tar b2.tar'
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
113 test_expect_success \
114 'git archive in a bare repo' \
115 '(cd bare.git && git archive HEAD) >b3.tar'
117 test_expect_success \
118 'git archive vs. the same in a bare repo' \
119 'test_cmp b.tar b3.tar'
121 test_expect_success
'git archive with --output' \
122 'git archive --output=b4.tar HEAD &&
123 test_cmp b.tar b4.tar'
125 test_expect_success
'git archive --remote' \
126 'git archive --remote=. HEAD >b5.tar &&
127 test_cmp b.tar b5.tar'
129 test_expect_success \
130 'validate file modification time' \
132 "$TAR" xf b.tar -C extract a/a &&
133 test-chmtime -v +0 extract/a/a |cut -f 1 >b.mtime &&
134 echo "1117231200" >expected.mtime &&
135 test_cmp expected.mtime b.mtime'
137 test_expect_success \
138 'git get-tar-commit-id' \
139 'git get-tar-commit-id <b.tar >b.commitid &&
140 test_cmp .git/$(git symbolic-ref HEAD) b.commitid'
142 test_expect_success \
143 'extract tar archive' \
144 '(cd b && "$TAR" xf -) <b.tar'
146 test_expect_success \
147 'validate filenames' \
148 '(cd b/a && find .) | sort >b.lst &&
149 test_cmp a.lst b.lst'
151 test_expect_success \
152 'validate file contents' \
155 test_expect_success \
156 'git tar-tree with prefix' \
157 'git tar-tree HEAD prefix >c.tar'
159 test_expect_success \
160 'extract tar archive with prefix' \
161 '(cd c && "$TAR" xf -) <c.tar'
163 test_expect_success \
164 'validate filenames with prefix' \
165 '(cd c/prefix/a && find .) | sort >c.lst &&
166 test_cmp a.lst c.lst'
168 test_expect_success \
169 'validate file contents with prefix' \
170 'diff -r a c/prefix/a'
172 test_expect_success \
173 'create archives with substfiles' \
174 'cp .git/info/attributes .git/info/attributes.before &&
175 echo "substfile?" export-subst >>.git/info/attributes &&
176 git archive HEAD >f.tar &&
177 git archive --prefix=prefix/ HEAD >g.tar &&
178 mv .git/info/attributes.before .git/info/attributes'
180 test_expect_success \
181 'extract substfiles' \
182 '(mkdir f && cd f && "$TAR" xf -) <f.tar'
184 test_expect_success \
185 'validate substfile contents' \
186 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
187 >f/a/substfile1.expected &&
188 test_cmp f/a/substfile1.expected f/a/substfile1 &&
189 test_cmp a/substfile2 f/a/substfile2
192 test_expect_success \
193 'extract substfiles from archive with prefix' \
194 '(mkdir g && cd g && "$TAR" xf -) <g.tar'
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 &&
200 test_cmp g/prefix/a/substfile1.expected g/prefix/a/substfile1 &&
201 test_cmp a/substfile2 g/prefix/a/substfile2
204 $UNZIP -v >/dev
/null
2>&1
205 if [ $?
-eq 127 ]; then
206 say
"Skipping ZIP tests, because unzip was not found"
208 test_set_prereq UNZIP
211 test_expect_success \
212 'git archive --format=zip' \
213 'git archive --format=zip HEAD >d.zip'
217 test_expect_success \
218 'git archive --format=zip in a bare repo' \
219 '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
221 test_expect_success \
222 'git archive --format=zip vs. the same in a bare repo' \
223 'test_cmp d.zip d1.zip'
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'
229 test_expect_success
'git archive with --output, inferring format' '
230 git archive --output=d3.zip HEAD &&
231 test_cmp d.zip d3.zip
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
239 test_expect_success \
240 'git archive --format=zip with prefix' \
241 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
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
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
257 check_zip large-compressed
259 test_expect_success \
260 'git archive --list outside of a git repo' \
261 'GIT_DIR=some/non-existing/directory git archive --list'
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
271 test_expect_success
'git-archive --prefix=olde-' '
272 git archive --prefix=olde- >h.tar HEAD &&
276 "$TAR" xf - <../h.tar
279 test -d h/olde-a/bin &&
280 test -f h/olde-a/bin/sh
283 test_expect_success
'setup tar filters' '
284 git config tar.tar.foo.command "tr ab ba" &&
285 git config tar.bar.command "tr ab ba" &&
286 git config tar.bar.remote true
289 test_expect_success
'archive --list mentions user filter' '
290 git archive --list >output &&
291 grep "^tar\.foo\$" output &&
295 test_expect_success
'archive --list shows only enabled remote filters' '
296 git archive --list --remote=. >output &&
297 ! grep "^tar\.foo\$" output &&
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
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
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
322 test_expect_success
'extension matching requires dot' '
323 git archive -o config-implicittar.foo HEAD &&
324 test_cmp b.tar config-implicittar.foo
327 test_expect_success
'only enabled filters are available remotely' '
328 test_must_fail git archive --remote=. --format=tar.foo HEAD \
330 git archive --remote=. --format=bar >remote.bar HEAD &&
331 test_cmp remote.bar config.bar
334 if $GZIP --version >/dev
/null
2>&1; then
337 say
"Skipping some tar.gz tests because gzip not found"
340 test_expect_success GZIP
'git archive --format=tgz' '
341 git archive --format=tgz HEAD >j.tgz
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
349 test_expect_success GZIP
'infer tgz from .tgz filename' '
350 git archive --output=j2.tgz HEAD &&
351 test_cmp j.tgz j2.tgz
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
359 if $GUNZIP --version >/dev
/null
2>&1; then
360 test_set_prereq GUNZIP
362 say
"Skipping some tar.gz tests because gunzip was not found"
365 test_expect_success GZIP
,GUNZIP
'extract tgz file' '
366 $GUNZIP -c <j.tgz >j.tar &&
370 test_expect_success GZIP
'remote tar.gz is allowed by default' '
371 git archive --remote=. --format=tar.gz HEAD >remote.tar.gz &&
372 test_cmp j.tgz remote.tar.gz
375 test_expect_success GZIP
'remote tar.gz can be disabled' '
376 git config tar.tar.gz.remote false &&
377 test_must_fail git archive --remote=. --format=tar.gz HEAD \