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
28 GIT_UNZIP
=${GIT_UNZIP:-unzip}
30 GUNZIP
=${GUNZIP:-gzip -d}
34 test_lazy_prereq UNZIP
'
43 dir_with_prefix
=$dir/$2
45 test_expect_success UNZIP
" extract ZIP archive" '
46 (mkdir $dir && cd $dir && "$GIT_UNZIP" ../$zipfile)
49 test_expect_success UNZIP
" validate filenames" "
50 (cd ${dir_with_prefix}a && find .) | sort >$listfile &&
51 test_cmp a.lst $listfile
54 test_expect_success UNZIP
" validate file contents" "
55 diff -r a ${dir_with_prefix}a
62 echo simple textfile >a/a &&
65 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
66 printf "A not substituted O" >a/substfile2 &&
67 if test_have_prereq SYMLINKS; then
72 (p=long_path_to_a_file && cd a &&
73 for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
74 echo text >file_with_long_path) &&
75 (cd a && find .) | sort >a.lst'
79 'echo ignore me >a/ignored &&
80 echo ignored export-ignore >.git/info/attributes'
83 'add files to repository' \
84 'find a -type f | xargs git update-index --add &&
85 find a -type l | xargs git update-index --add &&
86 treeid=`git write-tree` &&
87 echo $treeid >treeid &&
88 git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
89 git commit-tree $treeid </dev/null)'
93 'git clone --bare . bare.git &&
94 cp .git/info/attributes bare.git/info/attributes'
97 'remove ignored file' \
100 test_expect_success \
102 'git archive HEAD >b.tar'
104 test_expect_success \
106 'git tar-tree HEAD >b2.tar'
108 test_expect_success \
109 'git archive vs. git tar-tree' \
110 'test_cmp b.tar b2.tar'
112 test_expect_success
'git archive on large files' '
113 test_config core.bigfilethreshold 1 &&
114 git archive HEAD >b3.tar &&
115 test_cmp b.tar b3.tar
118 test_expect_success \
119 'git archive in a bare repo' \
120 '(cd bare.git && git archive HEAD) >b3.tar'
122 test_expect_success \
123 'git archive vs. the same in a bare repo' \
124 'test_cmp b.tar b3.tar'
126 test_expect_success
'git archive with --output' \
127 'git archive --output=b4.tar HEAD &&
128 test_cmp b.tar b4.tar'
130 test_expect_success
'git archive --remote' \
131 'git archive --remote=. HEAD >b5.tar &&
132 test_cmp b.tar b5.tar'
134 test_expect_success \
135 'validate file modification time' \
137 "$TAR" xf b.tar -C extract a/a &&
138 test-chmtime -v +0 extract/a/a |cut -f 1 >b.mtime &&
139 echo "1117231200" >expected.mtime &&
140 test_cmp expected.mtime b.mtime'
142 test_expect_success \
143 'git get-tar-commit-id' \
144 'git get-tar-commit-id <b.tar >b.commitid &&
145 test_cmp .git/$(git symbolic-ref HEAD) b.commitid'
147 test_expect_success \
148 'extract tar archive' \
149 '(cd b && "$TAR" xf -) <b.tar'
151 test_expect_success \
152 'validate filenames' \
153 '(cd b/a && find .) | sort >b.lst &&
154 test_cmp a.lst b.lst'
156 test_expect_success \
157 'validate file contents' \
160 test_expect_success \
161 'git tar-tree with prefix' \
162 'git tar-tree HEAD prefix >c.tar'
164 test_expect_success \
165 'extract tar archive with prefix' \
166 '(cd c && "$TAR" xf -) <c.tar'
168 test_expect_success \
169 'validate filenames with prefix' \
170 '(cd c/prefix/a && find .) | sort >c.lst &&
171 test_cmp a.lst c.lst'
173 test_expect_success \
174 'validate file contents with prefix' \
175 'diff -r a c/prefix/a'
177 test_expect_success \
178 'create archives with substfiles' \
179 'cp .git/info/attributes .git/info/attributes.before &&
180 echo "substfile?" export-subst >>.git/info/attributes &&
181 git archive HEAD >f.tar &&
182 git archive --prefix=prefix/ HEAD >g.tar &&
183 mv .git/info/attributes.before .git/info/attributes'
185 test_expect_success \
186 'extract substfiles' \
187 '(mkdir f && cd f && "$TAR" xf -) <f.tar'
189 test_expect_success \
190 'validate substfile contents' \
191 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
192 >f/a/substfile1.expected &&
193 test_cmp f/a/substfile1.expected f/a/substfile1 &&
194 test_cmp a/substfile2 f/a/substfile2
197 test_expect_success \
198 'extract substfiles from archive with prefix' \
199 '(mkdir g && cd g && "$TAR" xf -) <g.tar'
201 test_expect_success \
202 'validate substfile contents from archive with prefix' \
203 'git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
204 >g/prefix/a/substfile1.expected &&
205 test_cmp g/prefix/a/substfile1.expected g/prefix/a/substfile1 &&
206 test_cmp a/substfile2 g/prefix/a/substfile2
209 test_expect_success \
210 'git archive --format=zip' \
211 'git archive --format=zip HEAD >d.zip'
215 test_expect_success \
216 'git archive --format=zip in a bare repo' \
217 '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
219 test_expect_success \
220 'git archive --format=zip vs. the same in a bare repo' \
221 'test_cmp d.zip d1.zip'
223 test_expect_success
'git archive --format=zip with --output' \
224 'git archive --format=zip --output=d2.zip HEAD &&
225 test_cmp d.zip d2.zip'
227 test_expect_success
'git archive with --output, inferring format' '
228 git archive --output=d3.zip HEAD &&
229 test_cmp d.zip d3.zip
232 test_expect_success
'git archive with --output, override inferred format' '
233 git archive --format=tar --output=d4.zip HEAD &&
234 test_cmp b.tar d4.zip
237 test_expect_success \
238 'git archive --format=zip with prefix' \
239 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
243 test_expect_success
'git archive -0 --format=zip on large files' '
244 test_config core.bigfilethreshold 1 &&
245 git archive -0 --format=zip HEAD >large.zip
250 test_expect_success
'git archive --format=zip on large files' '
251 test_config core.bigfilethreshold 1 &&
252 git archive --format=zip HEAD >large-compressed.zip
255 check_zip large-compressed
257 test_expect_success \
258 'git archive --list outside of a git repo' \
259 'GIT_DIR=some/non-existing/directory git archive --list'
261 test_expect_success
'clients cannot access unreachable commits' '
262 test_commit unreachable &&
263 sha1=`git rev-parse HEAD` &&
264 git reset --hard HEAD^ &&
265 git archive $sha1 >remote.tar &&
266 test_must_fail git archive --remote=. $sha1 >remote.tar
269 test_expect_success
'git-archive --prefix=olde-' '
270 git archive --prefix=olde- >h.tar HEAD &&
274 "$TAR" xf - <../h.tar
277 test -d h/olde-a/bin &&
278 test -f h/olde-a/bin/sh
281 test_expect_success
'setup tar filters' '
282 git config tar.tar.foo.command "tr ab ba" &&
283 git config tar.bar.command "tr ab ba" &&
284 git config tar.bar.remote true
287 test_expect_success
'archive --list mentions user filter' '
288 git archive --list >output &&
289 grep "^tar\.foo\$" output &&
293 test_expect_success
'archive --list shows only enabled remote filters' '
294 git archive --list --remote=. >output &&
295 ! grep "^tar\.foo\$" output &&
299 test_expect_success
'invoke tar filter by format' '
300 git archive --format=tar.foo HEAD >config.tar.foo &&
301 tr ab ba <config.tar.foo >config.tar &&
302 test_cmp b.tar config.tar &&
303 git archive --format=bar HEAD >config.bar &&
304 tr ab ba <config.bar >config.tar &&
305 test_cmp b.tar config.tar
308 test_expect_success
'invoke tar filter by extension' '
309 git archive -o config-implicit.tar.foo HEAD &&
310 test_cmp config.tar.foo config-implicit.tar.foo &&
311 git archive -o config-implicit.bar HEAD &&
312 test_cmp config.tar.foo config-implicit.bar
315 test_expect_success
'default output format remains tar' '
316 git archive -o config-implicit.baz HEAD &&
317 test_cmp b.tar config-implicit.baz
320 test_expect_success
'extension matching requires dot' '
321 git archive -o config-implicittar.foo HEAD &&
322 test_cmp b.tar config-implicittar.foo
325 test_expect_success
'only enabled filters are available remotely' '
326 test_must_fail git archive --remote=. --format=tar.foo HEAD \
328 git archive --remote=. --format=bar >remote.bar HEAD &&
329 test_cmp remote.bar config.bar
332 if $GZIP --version >/dev
/null
2>&1; then
335 say
"Skipping some tar.gz tests because gzip not found"
338 test_expect_success GZIP
'git archive --format=tgz' '
339 git archive --format=tgz HEAD >j.tgz
342 test_expect_success GZIP
'git archive --format=tar.gz' '
343 git archive --format=tar.gz HEAD >j1.tar.gz &&
344 test_cmp j.tgz j1.tar.gz
347 test_expect_success GZIP
'infer tgz from .tgz filename' '
348 git archive --output=j2.tgz HEAD &&
349 test_cmp j.tgz j2.tgz
352 test_expect_success GZIP
'infer tgz from .tar.gz filename' '
353 git archive --output=j3.tar.gz HEAD &&
354 test_cmp j.tgz j3.tar.gz
357 if $GUNZIP --version >/dev
/null
2>&1; then
358 test_set_prereq GUNZIP
360 say
"Skipping some tar.gz tests because gunzip was not found"
363 test_expect_success GZIP
,GUNZIP
'extract tgz file' '
364 $GUNZIP -c <j.tgz >j.tar &&
368 test_expect_success GZIP
'remote tar.gz is allowed by default' '
369 git archive --remote=. --format=tar.gz HEAD >remote.tar.gz &&
370 test_cmp j.tgz remote.tar.gz
373 test_expect_success GZIP
'remote tar.gz can be disabled' '
374 git config tar.tar.gz.remote false &&
375 test_must_fail git archive --remote=. --format=tar.gz HEAD \