Use a strbuf in symlink
[git/mingw/4msysgit.git] / t / t5000-tar-tree.sh
blobeaf22aa5f9a6da726df100f3523c942656518264
1 #!/bin/sh
3 # Copyright (C) 2005 Rene Scharfe
6 test_description='git archive and git get-tar-commit-id test
8 This test covers the topics of file contents, commit date handling and
9 commit id embedding:
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.
16 git archive 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 archive 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.
27 . ./test-lib.sh
29 SUBSTFORMAT=%H%n
31 test_lazy_prereq TAR_NEEDS_PAX_FALLBACK '
33 mkdir pax &&
34 cd pax &&
35 "$TAR" xf "$TEST_DIRECTORY"/t5000/pax.tar &&
36 test -f PaxHeaders.1791/file
40 test_lazy_prereq GZIP 'gzip --version'
42 get_pax_header() {
43 file=$1
44 header=$2=
46 while read len rest
48 if test "$len" = $(echo "$len $rest" | wc -c)
49 then
50 case "$rest" in
51 $header*)
52 echo "${rest#$header}"
54 esac
56 done <"$file"
59 check_tar() {
60 tarfile=$1.tar
61 listfile=$1.lst
62 dir=$1
63 dir_with_prefix=$dir/$2
65 test_expect_success ' extract tar archive' '
66 (mkdir $dir && cd $dir && "$TAR" xf -) <$tarfile
69 test_expect_success TAR_NEEDS_PAX_FALLBACK ' interpret pax headers' '
71 cd $dir &&
72 for header in *.paxheader
74 data=${header%.paxheader}.data &&
75 if test -h $data -o -e $data
76 then
77 path=$(get_pax_header $header path) &&
78 if test -n "$path"
79 then
80 mv "$data" "$path"
83 done
87 test_expect_success ' validate filenames' '
88 (cd ${dir_with_prefix}a && find .) | sort >$listfile &&
89 test_cmp a.lst $listfile
92 test_expect_success ' validate file contents' '
93 diff -r a ${dir_with_prefix}a
97 test_expect_success \
98 'populate workdir' \
99 'mkdir a &&
100 echo simple textfile >a/a &&
101 ten=0123456789 && hundred=$ten$ten$ten$ten$ten$ten$ten$ten$ten$ten &&
102 echo long filename >a/four$hundred &&
103 mkdir a/bin &&
104 cp /bin/sh a/bin &&
105 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
106 printf "A not substituted O" >a/substfile2 &&
107 if test_have_prereq SYMLINKS; then
108 > a/a
109 ln -s a a/l1
110 else
111 printf %s a > a/l1
112 fi &&
113 (p=long_path_to_a_file && cd a &&
114 for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
115 echo text >file_with_long_path) &&
116 (cd a && find .) | sort >a.lst'
118 test_expect_success \
119 'add ignored file' \
120 'echo ignore me >a/ignored &&
121 echo ignored export-ignore >.git/info/attributes'
123 test_expect_success \
124 'add files to repository' \
125 'find a -type f | xargs git update-index --add &&
126 find a -type l | xargs git update-index --add &&
127 treeid=`git write-tree` &&
128 echo $treeid >treeid &&
129 git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \
130 git commit-tree $treeid </dev/null)'
132 test_expect_success 'setup export-subst' '
133 echo "substfile?" export-subst >>.git/info/attributes &&
134 git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
135 >a/substfile1
138 test_expect_success \
139 'create bare clone' \
140 'git clone --bare . bare.git &&
141 cp .git/info/attributes bare.git/info/attributes'
143 test_expect_success \
144 'remove ignored file' \
145 'rm a/ignored'
147 test_expect_success \
148 'git archive' \
149 'git archive HEAD >b.tar'
151 check_tar b
153 test_expect_success 'git archive --prefix=prefix/' '
154 git archive --prefix=prefix/ HEAD >with_prefix.tar
157 check_tar with_prefix prefix/
159 test_expect_success 'git-archive --prefix=olde-' '
160 git archive --prefix=olde- HEAD >with_olde-prefix.tar
163 check_tar with_olde-prefix olde-
165 test_expect_success 'git archive on large files' '
166 test_config core.bigfilethreshold 1 &&
167 git archive HEAD >b3.tar &&
168 test_cmp_bin b.tar b3.tar
171 test_expect_success \
172 'git archive in a bare repo' \
173 '(cd bare.git && git archive HEAD) >b3.tar'
175 test_expect_success \
176 'git archive vs. the same in a bare repo' \
177 'test_cmp_bin b.tar b3.tar'
179 test_expect_success 'git archive with --output' \
180 'git archive --output=b4.tar HEAD &&
181 test_cmp_bin b.tar b4.tar'
183 test_expect_success 'git archive --remote' \
184 'git archive --remote=. HEAD >b5.tar &&
185 test_cmp_bin b.tar b5.tar'
187 test_expect_success \
188 'validate file modification time' \
189 'mkdir extract &&
190 "$TAR" xf b.tar -C extract a/a &&
191 test-chmtime -v +0 extract/a/a |cut -f 1 >b.mtime &&
192 echo "1117231200" >expected.mtime &&
193 test_cmp expected.mtime b.mtime'
195 test_expect_success \
196 'git get-tar-commit-id' \
197 'git get-tar-commit-id <b.tar >b.commitid &&
198 test_cmp .git/$(git symbolic-ref HEAD) b.commitid'
200 test_expect_success 'git archive with --output, override inferred format' '
201 git archive --format=tar --output=d4.zip HEAD &&
202 test_cmp_bin b.tar d4.zip
205 test_expect_success \
206 'git archive --list outside of a git repo' \
207 'GIT_DIR=some/non-existing/directory git archive --list'
209 test_expect_success 'clients cannot access unreachable commits' '
210 test_commit unreachable &&
211 sha1=`git rev-parse HEAD` &&
212 git reset --hard HEAD^ &&
213 git archive $sha1 >remote.tar &&
214 test_must_fail git archive --remote=. $sha1 >remote.tar
217 test_expect_success 'upload-archive can allow unreachable commits' '
218 test_commit unreachable1 &&
219 sha1=`git rev-parse HEAD` &&
220 git reset --hard HEAD^ &&
221 git archive $sha1 >remote.tar &&
222 test_config uploadarchive.allowUnreachable true &&
223 git archive --remote=. $sha1 >remote.tar
226 test_expect_success 'setup tar filters' '
227 git config tar.tar.foo.command "tr ab ba" &&
228 git config tar.bar.command "tr ab ba" &&
229 git config tar.bar.remote true &&
230 git config tar.invalid baz
233 test_expect_success 'archive --list mentions user filter' '
234 git archive --list >output &&
235 grep "^tar\.foo\$" output &&
236 grep "^bar\$" output
239 test_expect_success 'archive --list shows only enabled remote filters' '
240 git archive --list --remote=. >output &&
241 ! grep "^tar\.foo\$" output &&
242 grep "^bar\$" output
245 test_expect_success 'invoke tar filter by format' '
246 git archive --format=tar.foo HEAD >config.tar.foo &&
247 tr ab ba <config.tar.foo >config.tar &&
248 test_cmp_bin b.tar config.tar &&
249 git archive --format=bar HEAD >config.bar &&
250 tr ab ba <config.bar >config.tar &&
251 test_cmp_bin b.tar config.tar
254 test_expect_success 'invoke tar filter by extension' '
255 git archive -o config-implicit.tar.foo HEAD &&
256 test_cmp_bin config.tar.foo config-implicit.tar.foo &&
257 git archive -o config-implicit.bar HEAD &&
258 test_cmp_bin config.tar.foo config-implicit.bar
261 test_expect_success 'default output format remains tar' '
262 git archive -o config-implicit.baz HEAD &&
263 test_cmp_bin b.tar config-implicit.baz
266 test_expect_success 'extension matching requires dot' '
267 git archive -o config-implicittar.foo HEAD &&
268 test_cmp_bin b.tar config-implicittar.foo
271 test_expect_success 'only enabled filters are available remotely' '
272 test_must_fail git archive --remote=. --format=tar.foo HEAD \
273 >remote.tar.foo &&
274 git archive --remote=. --format=bar >remote.bar HEAD &&
275 test_cmp_bin remote.bar config.bar
278 test_expect_success GZIP 'git archive --format=tgz' '
279 git archive --format=tgz HEAD >j.tgz
282 test_expect_success GZIP 'git archive --format=tar.gz' '
283 git archive --format=tar.gz HEAD >j1.tar.gz &&
284 test_cmp_bin j.tgz j1.tar.gz
287 test_expect_success GZIP 'infer tgz from .tgz filename' '
288 git archive --output=j2.tgz HEAD &&
289 test_cmp_bin j.tgz j2.tgz
292 test_expect_success GZIP 'infer tgz from .tar.gz filename' '
293 git archive --output=j3.tar.gz HEAD &&
294 test_cmp_bin j.tgz j3.tar.gz
297 test_expect_success GZIP 'extract tgz file' '
298 gzip -d -c <j.tgz >j.tar &&
299 test_cmp_bin b.tar j.tar
302 test_expect_success GZIP 'remote tar.gz is allowed by default' '
303 git archive --remote=. --format=tar.gz HEAD >remote.tar.gz &&
304 test_cmp_bin j.tgz remote.tar.gz
307 test_expect_success GZIP 'remote tar.gz can be disabled' '
308 git config tar.tar.gz.remote false &&
309 test_must_fail git archive --remote=. --format=tar.gz HEAD \
310 >remote.tar.gz
313 test_done