pull: don't warn if pull.ff has been set
[git/debian.git] / t / t5000-tar-tree.sh
blob37655a237cb783142400364be845bf7279cc2758
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 || test -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 'setup' '
98 test_oid_cache <<-EOF
99 obj sha1:19f9c8273ec45a8938e6999cb59b3ff66739902a
100 obj sha256:3c666f798798601571f5cec0adb57ce4aba8546875e7693177e0535f34d2c49b
104 test_expect_success \
105 'populate workdir' \
106 'mkdir a &&
107 echo simple textfile >a/a &&
108 ten=0123456789 && hundred=$ten$ten$ten$ten$ten$ten$ten$ten$ten$ten &&
109 echo long filename >a/four$hundred &&
110 mkdir a/bin &&
111 test-tool genrandom "frotz" 500000 >a/bin/sh &&
112 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
113 printf "A not substituted O" >a/substfile2 &&
114 if test_have_prereq SYMLINKS; then
115 ln -s a a/l1
116 else
117 printf %s a > a/l1
118 fi &&
119 (p=long_path_to_a_file && cd a &&
120 for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
121 echo text >file_with_long_path) &&
122 (cd a && find .) | sort >a.lst'
124 test_expect_success \
125 'add ignored file' \
126 'echo ignore me >a/ignored &&
127 echo ignored export-ignore >.git/info/attributes'
129 test_expect_success 'add files to repository' '
130 git add a &&
131 GIT_COMMITTER_DATE="2005-05-27 22:00" git commit -m initial
134 test_expect_success 'setup export-subst' '
135 echo "substfile?" export-subst >>.git/info/attributes &&
136 git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
137 >a/substfile1
140 test_expect_success \
141 'create bare clone' \
142 'git clone --bare . bare.git &&
143 cp .git/info/attributes bare.git/info/attributes'
145 test_expect_success \
146 'remove ignored file' \
147 'rm a/ignored'
149 test_expect_success \
150 'git archive' \
151 'git archive HEAD >b.tar'
153 check_tar b
155 test_expect_success 'git archive --prefix=prefix/' '
156 git archive --prefix=prefix/ HEAD >with_prefix.tar
159 check_tar with_prefix prefix/
161 test_expect_success 'git-archive --prefix=olde-' '
162 git archive --prefix=olde- HEAD >with_olde-prefix.tar
165 check_tar with_olde-prefix olde-
167 test_expect_success 'git archive on large files' '
168 test_config core.bigfilethreshold 1 &&
169 git archive HEAD >b3.tar &&
170 test_cmp_bin b.tar b3.tar
173 test_expect_success \
174 'git archive in a bare repo' \
175 '(cd bare.git && git archive HEAD) >b3.tar'
177 test_expect_success \
178 'git archive vs. the same in a bare repo' \
179 'test_cmp_bin b.tar b3.tar'
181 test_expect_success 'git archive with --output' \
182 'git archive --output=b4.tar HEAD &&
183 test_cmp_bin b.tar b4.tar'
185 test_expect_success 'git archive --remote' \
186 'git archive --remote=. HEAD >b5.tar &&
187 test_cmp_bin b.tar b5.tar'
189 test_expect_success 'git archive --remote with configured remote' '
190 git config remote.foo.url . &&
192 cd a &&
193 git archive --remote=foo --output=../b5-nick.tar HEAD
194 ) &&
195 test_cmp_bin b.tar b5-nick.tar
198 test_expect_success \
199 'validate file modification time' \
200 'mkdir extract &&
201 "$TAR" xf b.tar -C extract a/a &&
202 test-tool chmtime --get extract/a/a >b.mtime &&
203 echo "1117231200" >expected.mtime &&
204 test_cmp expected.mtime b.mtime'
206 test_expect_success \
207 'git get-tar-commit-id' \
208 'git get-tar-commit-id <b.tar >b.commitid &&
209 test_cmp .git/$(git symbolic-ref HEAD) b.commitid'
211 test_expect_success 'git archive with --output, override inferred format' '
212 git archive --format=tar --output=d4.zip HEAD &&
213 test_cmp_bin b.tar d4.zip
216 test_expect_success GZIP 'git archive with --output and --remote creates .tgz' '
217 git archive --output=d5.tgz --remote=. HEAD &&
218 gzip -d -c <d5.tgz >d5.tar &&
219 test_cmp_bin b.tar d5.tar
222 test_expect_success 'git archive --list outside of a git repo' '
223 nongit git archive --list
226 test_expect_success 'git archive --remote outside of a git repo' '
227 git archive HEAD >expect.tar &&
228 nongit git archive --remote="$PWD" HEAD >actual.tar &&
229 test_cmp_bin expect.tar actual.tar
232 test_expect_success 'clients cannot access unreachable commits' '
233 test_commit unreachable &&
234 sha1=$(git rev-parse HEAD) &&
235 git reset --hard HEAD^ &&
236 git archive $sha1 >remote.tar &&
237 test_must_fail git archive --remote=. $sha1 >remote.tar
240 test_expect_success 'upload-archive can allow unreachable commits' '
241 test_commit unreachable1 &&
242 sha1=$(git rev-parse HEAD) &&
243 git reset --hard HEAD^ &&
244 git archive $sha1 >remote.tar &&
245 test_config uploadarchive.allowUnreachable true &&
246 git archive --remote=. $sha1 >remote.tar
249 test_expect_success 'setup tar filters' '
250 git config tar.tar.foo.command "tr ab ba" &&
251 git config tar.bar.command "tr ab ba" &&
252 git config tar.bar.remote true &&
253 git config tar.invalid baz
256 test_expect_success 'archive --list mentions user filter' '
257 git archive --list >output &&
258 grep "^tar\.foo\$" output &&
259 grep "^bar\$" output
262 test_expect_success 'archive --list shows only enabled remote filters' '
263 git archive --list --remote=. >output &&
264 ! grep "^tar\.foo\$" output &&
265 grep "^bar\$" output
268 test_expect_success 'invoke tar filter by format' '
269 git archive --format=tar.foo HEAD >config.tar.foo &&
270 tr ab ba <config.tar.foo >config.tar &&
271 test_cmp_bin b.tar config.tar &&
272 git archive --format=bar HEAD >config.bar &&
273 tr ab ba <config.bar >config.tar &&
274 test_cmp_bin b.tar config.tar
277 test_expect_success 'invoke tar filter by extension' '
278 git archive -o config-implicit.tar.foo HEAD &&
279 test_cmp_bin config.tar.foo config-implicit.tar.foo &&
280 git archive -o config-implicit.bar HEAD &&
281 test_cmp_bin config.tar.foo config-implicit.bar
284 test_expect_success 'default output format remains tar' '
285 git archive -o config-implicit.baz HEAD &&
286 test_cmp_bin b.tar config-implicit.baz
289 test_expect_success 'extension matching requires dot' '
290 git archive -o config-implicittar.foo HEAD &&
291 test_cmp_bin b.tar config-implicittar.foo
294 test_expect_success 'only enabled filters are available remotely' '
295 test_must_fail git archive --remote=. --format=tar.foo HEAD \
296 >remote.tar.foo &&
297 git archive --remote=. --format=bar >remote.bar HEAD &&
298 test_cmp_bin remote.bar config.bar
301 test_expect_success GZIP 'git archive --format=tgz' '
302 git archive --format=tgz HEAD >j.tgz
305 test_expect_success GZIP 'git archive --format=tar.gz' '
306 git archive --format=tar.gz HEAD >j1.tar.gz &&
307 test_cmp_bin j.tgz j1.tar.gz
310 test_expect_success GZIP 'infer tgz from .tgz filename' '
311 git archive --output=j2.tgz HEAD &&
312 test_cmp_bin j.tgz j2.tgz
315 test_expect_success GZIP 'infer tgz from .tar.gz filename' '
316 git archive --output=j3.tar.gz HEAD &&
317 test_cmp_bin j.tgz j3.tar.gz
320 test_expect_success GZIP 'extract tgz file' '
321 gzip -d -c <j.tgz >j.tar &&
322 test_cmp_bin b.tar j.tar
325 test_expect_success GZIP 'remote tar.gz is allowed by default' '
326 git archive --remote=. --format=tar.gz HEAD >remote.tar.gz &&
327 test_cmp_bin j.tgz remote.tar.gz
330 test_expect_success GZIP 'remote tar.gz can be disabled' '
331 git config tar.tar.gz.remote false &&
332 test_must_fail git archive --remote=. --format=tar.gz HEAD \
333 >remote.tar.gz
336 test_expect_success 'archive and :(glob)' '
337 git archive -v HEAD -- ":(glob)**/sh" >/dev/null 2>actual &&
338 cat >expect <<EOF &&
340 a/bin/
341 a/bin/sh
343 test_cmp expect actual
346 test_expect_success 'catch non-matching pathspec' '
347 test_must_fail git archive -v HEAD -- "*.abc" >/dev/null
350 # Pull the size and date of each entry in a tarfile using the system tar.
352 # We'll pull out only the year from the date; that avoids any question of
353 # timezones impacting the result (as long as we keep our test times away from a
354 # year boundary; our reference times are all in August).
356 # The output of tar_info is expected to be "<size> <year>", both in decimal. It
357 # ignores the return value of tar. We have to do this, because some of our test
358 # input is only partial (the real data is 64GB in some cases).
359 tar_info () {
360 "$TAR" tvf "$1" |
361 awk '{
362 split($4, date, "-")
363 print $3 " " date[1]
367 # See if our system tar can handle a tar file with huge sizes and dates far in
368 # the future, and that we can actually parse its output.
370 # The reference file was generated by GNU tar, and the magic time and size are
371 # both octal 01000000000001, which overflows normal ustar fields.
372 test_lazy_prereq TAR_HUGE '
373 echo "68719476737 4147" >expect &&
374 tar_info "$TEST_DIRECTORY"/t5000/huge-and-future.tar >actual &&
375 test_cmp expect actual
378 test_expect_success LONG_IS_64BIT 'set up repository with huge blob' '
379 obj=$(test_oid obj) &&
380 path=$(test_oid_to_path $obj) &&
381 mkdir -p .git/objects/$(dirname $path) &&
382 cp "$TEST_DIRECTORY"/t5000/huge-object .git/objects/$path &&
383 rm -f .git/index &&
384 git update-index --add --cacheinfo 100644,$obj,huge &&
385 git commit -m huge
388 # We expect git to die with SIGPIPE here (otherwise we
389 # would generate the whole 64GB).
390 test_expect_success LONG_IS_64BIT 'generate tar with huge size' '
392 git archive HEAD
393 echo $? >exit-code
394 } | test_copy_bytes 4096 >huge.tar &&
395 echo 141 >expect &&
396 test_cmp expect exit-code
399 test_expect_success TAR_HUGE,LONG_IS_64BIT 'system tar can read our huge size' '
400 echo 68719476737 >expect &&
401 tar_info huge.tar | cut -d" " -f1 >actual &&
402 test_cmp expect actual
405 test_expect_success TIME_IS_64BIT 'set up repository with far-future commit' '
406 rm -f .git/index &&
407 echo content >file &&
408 git add file &&
409 GIT_COMMITTER_DATE="@68719476737 +0000" \
410 git commit -m "tempori parendum"
413 test_expect_success TIME_IS_64BIT 'generate tar with future mtime' '
414 git archive HEAD >future.tar
417 test_expect_success TAR_HUGE,TIME_IS_64BIT,TIME_T_IS_64BIT 'system tar can read our future mtime' '
418 echo 4147 >expect &&
419 tar_info future.tar | cut -d" " -f2 >actual &&
420 test_cmp expect actual
423 test_done