]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5000-tar-tree.sh
archive-tar: write extended headers for far-future mtime
[thirdparty/git.git] / t / t5000-tar-tree.sh
CommitLineData
d3d49c3d
RS
1#!/bin/sh
2#
3# Copyright (C) 2005 Rene Scharfe
4#
5
925ceccf 6test_description='git archive and git get-tar-commit-id test
d3d49c3d 7
5b860406
RS
8This test covers the topics of file contents, commit date handling and
9commit id embedding:
d3d49c3d
RS
10
11 The contents of the repository is compared to the extracted tar
12 archive. The repository contains simple text files, symlinks and a
3dff5379 13 binary file (/bin/sh). Only paths shorter than 99 characters are
5b860406 14 used.
d3d49c3d 15
925ceccf 16 git archive applies the commit date to every file in the archive it
d3d49c3d
RS
17 creates. The test sets the commit date to a specific value and checks
18 if the tar archive contains that value.
19
925ceccf 20 When giving git archive a commit id (in contrast to a tree id) it
d3d49c3d 21 embeds this commit id into the tar archive as a comment. The test
5be60078 22 checks the ability of git get-tar-commit-id to figure it out from the
d3d49c3d
RS
23 tar file.
24
25'
26
27. ./test-lib.sh
28
38c9c9b7 29SUBSTFORMAT=%H%n
8460b2fc 30
9bf1ac41
RS
31test_lazy_prereq TAR_NEEDS_PAX_FALLBACK '
32 (
33 mkdir pax &&
34 cd pax &&
35 "$TAR" xf "$TEST_DIRECTORY"/t5000/pax.tar &&
36 test -f PaxHeaders.1791/file
37 )
38'
39
96174145
JK
40test_lazy_prereq GZIP 'gzip --version'
41
9bf1ac41
RS
42get_pax_header() {
43 file=$1
44 header=$2=
45
46 while read len rest
47 do
48 if test "$len" = $(echo "$len $rest" | wc -c)
49 then
50 case "$rest" in
51 $header*)
52 echo "${rest#$header}"
53 ;;
54 esac
55 fi
56 done <"$file"
57}
58
deb9c8ed
RS
59check_tar() {
60 tarfile=$1.tar
61 listfile=$1.lst
62 dir=$1
63 dir_with_prefix=$dir/$2
64
65 test_expect_success ' extract tar archive' '
66 (mkdir $dir && cd $dir && "$TAR" xf -) <$tarfile
67 '
68
9bf1ac41
RS
69 test_expect_success TAR_NEEDS_PAX_FALLBACK ' interpret pax headers' '
70 (
71 cd $dir &&
72 for header in *.paxheader
73 do
74 data=${header%.paxheader}.data &&
d0b30a3d 75 if test -h $data || test -e $data
9bf1ac41
RS
76 then
77 path=$(get_pax_header $header path) &&
78 if test -n "$path"
79 then
80 mv "$data" "$path"
81 fi
82 fi
83 done
84 )
85 '
86
deb9c8ed
RS
87 test_expect_success ' validate filenames' '
88 (cd ${dir_with_prefix}a && find .) | sort >$listfile &&
89 test_cmp a.lst $listfile
90 '
91
92 test_expect_success ' validate file contents' '
93 diff -r a ${dir_with_prefix}a
94 '
95}
96
d3d49c3d
RS
97test_expect_success \
98 'populate workdir' \
1355241b 99 'mkdir a &&
d3d49c3d 100 echo simple textfile >a/a &&
9bf1ac41
RS
101 ten=0123456789 && hundred=$ten$ten$ten$ten$ten$ten$ten$ten$ten$ten &&
102 echo long filename >a/four$hundred &&
d3d49c3d 103 mkdir a/bin &&
bba5fccc 104 test-genrandom "frotz" 500000 >a/bin/sh &&
760da960
RS
105 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
106 printf "A not substituted O" >a/substfile2 &&
704a3143
JS
107 if test_have_prereq SYMLINKS; then
108 ln -s a a/l1
109 else
110 printf %s a > a/l1
111 fi &&
4c691724
RS
112 (p=long_path_to_a_file && cd a &&
113 for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
114 echo text >file_with_long_path) &&
d3d49c3d
RS
115 (cd a && find .) | sort >a.lst'
116
008d896d
RS
117test_expect_success \
118 'add ignored file' \
119 'echo ignore me >a/ignored &&
ad94657f 120 echo ignored export-ignore >.git/info/attributes'
008d896d 121
21711ca4
RS
122test_expect_success 'add files to repository' '
123 git add a &&
124 GIT_COMMITTER_DATE="2005-05-27 22:00" git commit -m initial
125'
d3d49c3d 126
c420df7b
RS
127test_expect_success 'setup export-subst' '
128 echo "substfile?" export-subst >>.git/info/attributes &&
129 git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
130 >a/substfile1
131'
132
ddff8563
CB
133test_expect_success \
134 'create bare clone' \
135 'git clone --bare . bare.git &&
ad94657f 136 cp .git/info/attributes bare.git/info/attributes'
ddff8563 137
008d896d
RS
138test_expect_success \
139 'remove ignored file' \
140 'rm a/ignored'
141
8ff21b1a 142test_expect_success \
5be60078
JH
143 'git archive' \
144 'git archive HEAD >b.tar'
8ff21b1a 145
deb9c8ed
RS
146check_tar b
147
03d9bc56
RS
148test_expect_success 'git archive --prefix=prefix/' '
149 git archive --prefix=prefix/ HEAD >with_prefix.tar
150'
151
152check_tar with_prefix prefix/
153
154test_expect_success 'git-archive --prefix=olde-' '
155 git archive --prefix=olde- HEAD >with_olde-prefix.tar
156'
157
158check_tar with_olde-prefix olde-
159
5544049d
NTND
160test_expect_success 'git archive on large files' '
161 test_config core.bigfilethreshold 1 &&
162 git archive HEAD >b3.tar &&
b93e6e36 163 test_cmp_bin b.tar b3.tar
5544049d
NTND
164'
165
ddff8563
CB
166test_expect_success \
167 'git archive in a bare repo' \
168 '(cd bare.git && git archive HEAD) >b3.tar'
169
170test_expect_success \
171 'git archive vs. the same in a bare repo' \
b93e6e36 172 'test_cmp_bin b.tar b3.tar'
ddff8563 173
aec0c1bb
CMDV
174test_expect_success 'git archive with --output' \
175 'git archive --output=b4.tar HEAD &&
b93e6e36 176 test_cmp_bin b.tar b4.tar'
aec0c1bb 177
1bc01efe 178test_expect_success 'git archive --remote' \
48139269 179 'git archive --remote=. HEAD >b5.tar &&
b93e6e36 180 test_cmp_bin b.tar b5.tar'
48139269 181
d3d49c3d
RS
182test_expect_success \
183 'validate file modification time' \
30684dfa 184 'mkdir extract &&
bfce5087 185 "$TAR" xf b.tar -C extract a/a &&
111539a3 186 test-chmtime -v +0 extract/a/a |cut -f 1 >b.mtime &&
30684dfa 187 echo "1117231200" >expected.mtime &&
188c3827 188 test_cmp expected.mtime b.mtime'
d3d49c3d
RS
189
190test_expect_success \
5be60078
JH
191 'git get-tar-commit-id' \
192 'git get-tar-commit-id <b.tar >b.commitid &&
188c3827 193 test_cmp .git/$(git symbolic-ref HEAD) b.commitid'
d3d49c3d 194
fe12d8e8
RS
195test_expect_success 'git archive with --output, override inferred format' '
196 git archive --format=tar --output=d4.zip HEAD &&
b93e6e36 197 test_cmp_bin b.tar d4.zip
fe12d8e8
RS
198'
199
265d5280 200test_expect_success \
5be60078
JH
201 'git archive --list outside of a git repo' \
202 'GIT_DIR=some/non-existing/directory git archive --list'
265d5280 203
ee27ca4a
JK
204test_expect_success 'clients cannot access unreachable commits' '
205 test_commit unreachable &&
f5efd519 206 sha1=$(git rev-parse HEAD) &&
ee27ca4a
JK
207 git reset --hard HEAD^ &&
208 git archive $sha1 >remote.tar &&
209 test_must_fail git archive --remote=. $sha1 >remote.tar
210'
211
7671b632
SG
212test_expect_success 'upload-archive can allow unreachable commits' '
213 test_commit unreachable1 &&
f5efd519 214 sha1=$(git rev-parse HEAD) &&
7671b632
SG
215 git reset --hard HEAD^ &&
216 git archive $sha1 >remote.tar &&
217 test_config uploadarchive.allowUnreachable true &&
218 git archive --remote=. $sha1 >remote.tar
219'
220
767cf457
JK
221test_expect_success 'setup tar filters' '
222 git config tar.tar.foo.command "tr ab ba" &&
7b97730b 223 git config tar.bar.command "tr ab ba" &&
785a0429
JK
224 git config tar.bar.remote true &&
225 git config tar.invalid baz
767cf457
JK
226'
227
228test_expect_success 'archive --list mentions user filter' '
229 git archive --list >output &&
230 grep "^tar\.foo\$" output &&
231 grep "^bar\$" output
232'
233
1bc01efe 234test_expect_success 'archive --list shows only enabled remote filters' '
767cf457 235 git archive --list --remote=. >output &&
7b97730b 236 ! grep "^tar\.foo\$" output &&
767cf457
JK
237 grep "^bar\$" output
238'
239
240test_expect_success 'invoke tar filter by format' '
241 git archive --format=tar.foo HEAD >config.tar.foo &&
242 tr ab ba <config.tar.foo >config.tar &&
b93e6e36 243 test_cmp_bin b.tar config.tar &&
767cf457
JK
244 git archive --format=bar HEAD >config.bar &&
245 tr ab ba <config.bar >config.tar &&
b93e6e36 246 test_cmp_bin b.tar config.tar
767cf457
JK
247'
248
249test_expect_success 'invoke tar filter by extension' '
250 git archive -o config-implicit.tar.foo HEAD &&
b93e6e36 251 test_cmp_bin config.tar.foo config-implicit.tar.foo &&
767cf457 252 git archive -o config-implicit.bar HEAD &&
b93e6e36 253 test_cmp_bin config.tar.foo config-implicit.bar
767cf457
JK
254'
255
256test_expect_success 'default output format remains tar' '
257 git archive -o config-implicit.baz HEAD &&
b93e6e36 258 test_cmp_bin b.tar config-implicit.baz
767cf457
JK
259'
260
261test_expect_success 'extension matching requires dot' '
262 git archive -o config-implicittar.foo HEAD &&
b93e6e36 263 test_cmp_bin b.tar config-implicittar.foo
767cf457
JK
264'
265
1bc01efe 266test_expect_success 'only enabled filters are available remotely' '
7b97730b
JK
267 test_must_fail git archive --remote=. --format=tar.foo HEAD \
268 >remote.tar.foo &&
269 git archive --remote=. --format=bar >remote.bar HEAD &&
b93e6e36 270 test_cmp_bin remote.bar config.bar
7b97730b
JK
271'
272
0e804e09
JK
273test_expect_success GZIP 'git archive --format=tgz' '
274 git archive --format=tgz HEAD >j.tgz
275'
276
277test_expect_success GZIP 'git archive --format=tar.gz' '
278 git archive --format=tar.gz HEAD >j1.tar.gz &&
b93e6e36 279 test_cmp_bin j.tgz j1.tar.gz
0e804e09
JK
280'
281
282test_expect_success GZIP 'infer tgz from .tgz filename' '
283 git archive --output=j2.tgz HEAD &&
b93e6e36 284 test_cmp_bin j.tgz j2.tgz
0e804e09
JK
285'
286
287test_expect_success GZIP 'infer tgz from .tar.gz filename' '
288 git archive --output=j3.tar.gz HEAD &&
b93e6e36 289 test_cmp_bin j.tgz j3.tar.gz
0e804e09
JK
290'
291
96174145
JK
292test_expect_success GZIP 'extract tgz file' '
293 gzip -d -c <j.tgz >j.tar &&
b93e6e36 294 test_cmp_bin b.tar j.tar
0e804e09
JK
295'
296
1bc01efe 297test_expect_success GZIP 'remote tar.gz is allowed by default' '
7b97730b 298 git archive --remote=. --format=tar.gz HEAD >remote.tar.gz &&
b93e6e36 299 test_cmp_bin j.tgz remote.tar.gz
7b97730b
JK
300'
301
1bc01efe 302test_expect_success GZIP 'remote tar.gz can be disabled' '
7b97730b
JK
303 git config tar.tar.gz.remote false &&
304 test_must_fail git archive --remote=. --format=tar.gz HEAD \
305 >remote.tar.gz
306'
307
ed22b417
NTND
308test_expect_success 'archive and :(glob)' '
309 git archive -v HEAD -- ":(glob)**/sh" >/dev/null 2>actual &&
310 cat >expect <<EOF &&
311a/
312a/bin/
313a/bin/sh
314EOF
315 test_cmp expect actual
316'
317
318test_expect_success 'catch non-matching pathspec' '
319 test_must_fail git archive -v HEAD -- "*.abc" >/dev/null
320'
321
e51217e1
JK
322# Pull the size and date of each entry in a tarfile using the system tar.
323#
324# We'll pull out only the year from the date; that avoids any question of
325# timezones impacting the result (as long as we keep our test times away from a
326# year boundary; our reference times are all in August).
327#
328# The output of tar_info is expected to be "<size> <year>", both in decimal. It
329# ignores the return value of tar. We have to do this, because some of our test
330# input is only partial (the real data is 64GB in some cases).
331tar_info () {
332 "$TAR" tvf "$1" |
333 awk '{
334 split($4, date, "-")
335 print $3 " " date[1]
336 }'
337}
338
339# See if our system tar can handle a tar file with huge sizes and dates far in
340# the future, and that we can actually parse its output.
341#
342# The reference file was generated by GNU tar, and the magic time and size are
343# both octal 01000000000001, which overflows normal ustar fields.
344test_lazy_prereq TAR_HUGE '
345 echo "68719476737 4147" >expect &&
346 tar_info "$TEST_DIRECTORY"/t5000/huge-and-future.tar >actual &&
347 test_cmp expect actual
348'
349
350test_expect_success 'set up repository with huge blob' '
351 obj_d=19 &&
352 obj_f=f9c8273ec45a8938e6999cb59b3ff66739902a &&
353 obj=${obj_d}${obj_f} &&
354 mkdir -p .git/objects/$obj_d &&
355 cp "$TEST_DIRECTORY"/t5000/$obj .git/objects/$obj_d/$obj_f &&
356 rm -f .git/index &&
357 git update-index --add --cacheinfo 100644,$obj,huge &&
358 git commit -m huge
359'
360
361# We expect git to die with SIGPIPE here (otherwise we
362# would generate the whole 64GB).
d1657b57 363test_expect_success 'generate tar with huge size' '
e51217e1
JK
364 {
365 git archive HEAD
366 echo $? >exit-code
367 } | test_copy_bytes 4096 >huge.tar &&
368 echo 141 >expect &&
369 test_cmp expect exit-code
370'
371
d1657b57 372test_expect_success TAR_HUGE 'system tar can read our huge size' '
e51217e1
JK
373 echo 68719476737 >expect &&
374 tar_info huge.tar | cut -d" " -f1 >actual &&
375 test_cmp expect actual
376'
377
378test_expect_success 'set up repository with far-future commit' '
379 rm -f .git/index &&
380 echo content >file &&
381 git add file &&
382 GIT_COMMITTER_DATE="@68719476737 +0000" \
383 git commit -m "tempori parendum"
384'
385
6e8e0991 386test_expect_success 'generate tar with future mtime' '
e51217e1
JK
387 git archive HEAD >future.tar
388'
389
6e8e0991 390test_expect_success TAR_HUGE 'system tar can read our future mtime' '
e51217e1
JK
391 echo 4147 >expect &&
392 tar_info future.tar | cut -d" " -f2 >actual &&
393 test_cmp expect actual
394'
395
d3d49c3d 396test_done