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
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 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
31 test_lazy_prereq TAR_NEEDS_PAX_FALLBACK
'
35 "$TAR" xf "$TEST_DIRECTORY"/t5000/pax.tar &&
36 test -f PaxHeaders.1791/file
40 test_lazy_prereq GZIP
'gzip --version'
48 if test "$len" = $
(echo "$len $rest" |
wc -c)
52 echo "${rest#$header}"
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' '
72 for header in *.paxheader
74 data=${header%.paxheader}.data &&
75 if test -h $data || test -e $data
77 path=$(get_pax_header $header path) &&
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
102 test_expect_success
" validate extra file $path_in_archive" '
103 diff -r $path_in_fs $dir/$path_in_archive
107 test_expect_success
'setup' '
108 test_oid_cache <<-EOF
109 obj sha1:19f9c8273ec45a8938e6999cb59b3ff66739902a
110 obj sha256:3c666f798798601571f5cec0adb57ce4aba8546875e7693177e0535f34d2c49b
114 test_expect_success \
117 echo simple textfile >a/a &&
118 ten=0123456789 && hundred=$ten$ten$ten$ten$ten$ten$ten$ten$ten$ten &&
119 echo long filename >a/four$hundred &&
121 test-tool genrandom "frotz" 500000 >a/bin/sh &&
122 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
123 printf "A not substituted O" >a/substfile2 &&
124 if test_have_prereq SYMLINKS; then
129 (p=long_path_to_a_file && cd a &&
130 for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
131 echo text >file_with_long_path) &&
132 (cd a && find .) | sort >a.lst'
134 test_expect_success \
136 'echo ignore me >a/ignored &&
137 echo ignored export-ignore >.git/info/attributes'
139 test_expect_success
'add files to repository' '
141 GIT_COMMITTER_DATE="2005-05-27 22:00" git commit -m initial
144 test_expect_success
'setup export-subst' '
145 echo "substfile?" export-subst >>.git/info/attributes &&
146 git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
150 test_expect_success \
151 'create bare clone' \
152 'git clone --bare . bare.git &&
153 cp .git/info/attributes bare.git/info/attributes'
155 test_expect_success \
156 'remove ignored file' \
159 test_expect_success \
161 'git archive HEAD >b.tar'
165 test_expect_success
'git archive --prefix=prefix/' '
166 git archive --prefix=prefix/ HEAD >with_prefix.tar
169 check_tar with_prefix prefix
/
171 test_expect_success
'git-archive --prefix=olde-' '
172 git archive --prefix=olde- HEAD >with_olde-prefix.tar
175 check_tar with_olde-prefix olde-
177 test_expect_success
'git archive --add-file' '
178 echo untracked >untracked &&
179 git archive --add-file=untracked HEAD >with_untracked.tar
182 check_tar with_untracked
183 check_added with_untracked untracked untracked
185 test_expect_success
'git archive --add-file twice' '
186 echo untracked >untracked &&
187 git archive --prefix=one/ --add-file=untracked \
188 --prefix=two/ --add-file=untracked \
189 --prefix= HEAD >with_untracked2.tar
192 check_tar with_untracked2
193 check_added with_untracked2 untracked one
/untracked
194 check_added with_untracked2 untracked two
/untracked
196 test_expect_success
'git archive on large files' '
197 test_config core.bigfilethreshold 1 &&
198 git archive HEAD >b3.tar &&
199 test_cmp_bin b.tar b3.tar
202 test_expect_success \
203 'git archive in a bare repo' \
204 '(cd bare.git && git archive HEAD) >b3.tar'
206 test_expect_success \
207 'git archive vs. the same in a bare repo' \
208 'test_cmp_bin b.tar b3.tar'
210 test_expect_success
'git archive with --output' \
211 'git archive --output=b4.tar HEAD &&
212 test_cmp_bin b.tar b4.tar'
214 test_expect_success
'git archive --remote' \
215 'git archive --remote=. HEAD >b5.tar &&
216 test_cmp_bin b.tar b5.tar'
218 test_expect_success
'git archive --remote with configured remote' '
219 git config remote.foo.url . &&
222 git archive --remote=foo --output=../b5-nick.tar HEAD
224 test_cmp_bin b.tar b5-nick.tar
227 test_expect_success \
228 'validate file modification time' \
230 "$TAR" xf b.tar -C extract a/a &&
231 test-tool chmtime --get extract/a/a >b.mtime &&
232 echo "1117231200" >expected.mtime &&
233 test_cmp expected.mtime b.mtime'
235 test_expect_success \
236 'git get-tar-commit-id' \
237 'git get-tar-commit-id <b.tar >b.commitid &&
238 test_cmp .git/$(git symbolic-ref HEAD) b.commitid'
240 test_expect_success
'git archive with --output, override inferred format' '
241 git archive --format=tar --output=d4.zip HEAD &&
242 test_cmp_bin b.tar d4.zip
245 test_expect_success GZIP
'git archive with --output and --remote creates .tgz' '
246 git archive --output=d5.tgz --remote=. HEAD &&
247 gzip -d -c <d5.tgz >d5.tar &&
248 test_cmp_bin b.tar d5.tar
251 test_expect_success
'git archive --list outside of a git repo' '
252 nongit git archive --list
255 test_expect_success
'git archive --remote outside of a git repo' '
256 git archive HEAD >expect.tar &&
257 nongit git archive --remote="$PWD" HEAD >actual.tar &&
258 test_cmp_bin expect.tar actual.tar
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
'upload-archive can allow unreachable commits' '
270 test_commit unreachable1 &&
271 sha1=$(git rev-parse HEAD) &&
272 git reset --hard HEAD^ &&
273 git archive $sha1 >remote.tar &&
274 test_config uploadarchive.allowUnreachable true &&
275 git archive --remote=. $sha1 >remote.tar
278 test_expect_success
'setup tar filters' '
279 git config tar.tar.foo.command "tr ab ba" &&
280 git config tar.bar.command "tr ab ba" &&
281 git config tar.bar.remote true &&
282 git config tar.invalid baz
285 test_expect_success
'archive --list mentions user filter' '
286 git archive --list >output &&
287 grep "^tar\.foo\$" output &&
291 test_expect_success
'archive --list shows only enabled remote filters' '
292 git archive --list --remote=. >output &&
293 ! grep "^tar\.foo\$" output &&
297 test_expect_success
'invoke tar filter by format' '
298 git archive --format=tar.foo HEAD >config.tar.foo &&
299 tr ab ba <config.tar.foo >config.tar &&
300 test_cmp_bin b.tar config.tar &&
301 git archive --format=bar HEAD >config.bar &&
302 tr ab ba <config.bar >config.tar &&
303 test_cmp_bin b.tar config.tar
306 test_expect_success
'invoke tar filter by extension' '
307 git archive -o config-implicit.tar.foo HEAD &&
308 test_cmp_bin config.tar.foo config-implicit.tar.foo &&
309 git archive -o config-implicit.bar HEAD &&
310 test_cmp_bin config.tar.foo config-implicit.bar
313 test_expect_success
'default output format remains tar' '
314 git archive -o config-implicit.baz HEAD &&
315 test_cmp_bin b.tar config-implicit.baz
318 test_expect_success
'extension matching requires dot' '
319 git archive -o config-implicittar.foo HEAD &&
320 test_cmp_bin b.tar config-implicittar.foo
323 test_expect_success
'only enabled filters are available remotely' '
324 test_must_fail git archive --remote=. --format=tar.foo HEAD \
326 git archive --remote=. --format=bar >remote.bar HEAD &&
327 test_cmp_bin remote.bar config.bar
330 test_expect_success GZIP
'git archive --format=tgz' '
331 git archive --format=tgz HEAD >j.tgz
334 test_expect_success GZIP
'git archive --format=tar.gz' '
335 git archive --format=tar.gz HEAD >j1.tar.gz &&
336 test_cmp_bin j.tgz j1.tar.gz
339 test_expect_success GZIP
'infer tgz from .tgz filename' '
340 git archive --output=j2.tgz HEAD &&
341 test_cmp_bin j.tgz j2.tgz
344 test_expect_success GZIP
'infer tgz from .tar.gz filename' '
345 git archive --output=j3.tar.gz HEAD &&
346 test_cmp_bin j.tgz j3.tar.gz
349 test_expect_success GZIP
'extract tgz file' '
350 gzip -d -c <j.tgz >j.tar &&
351 test_cmp_bin b.tar j.tar
354 test_expect_success GZIP
'remote tar.gz is allowed by default' '
355 git archive --remote=. --format=tar.gz HEAD >remote.tar.gz &&
356 test_cmp_bin j.tgz remote.tar.gz
359 test_expect_success GZIP
'remote tar.gz can be disabled' '
360 git config tar.tar.gz.remote false &&
361 test_must_fail git archive --remote=. --format=tar.gz HEAD \
365 test_expect_success
'archive and :(glob)' '
366 git archive -v HEAD -- ":(glob)**/sh" >/dev/null 2>actual &&
372 test_cmp expect actual
375 test_expect_success
'catch non-matching pathspec' '
376 test_must_fail git archive -v HEAD -- "*.abc" >/dev/null
379 # Pull the size and date of each entry in a tarfile using the system tar.
381 # We'll pull out only the year from the date; that avoids any question of
382 # timezones impacting the result (as long as we keep our test times away from a
383 # year boundary; our reference times are all in August).
385 # The output of tar_info is expected to be "<size> <year>", both in decimal. It
386 # ignores the return value of tar. We have to do this, because some of our test
387 # input is only partial (the real data is 64GB in some cases).
396 # See if our system tar can handle a tar file with huge sizes and dates far in
397 # the future, and that we can actually parse its output.
399 # The reference file was generated by GNU tar, and the magic time and size are
400 # both octal 01000000000001, which overflows normal ustar fields.
401 test_lazy_prereq TAR_HUGE
'
402 echo "68719476737 4147" >expect &&
403 tar_info "$TEST_DIRECTORY"/t5000/huge-and-future.tar >actual &&
404 test_cmp expect actual
407 test_expect_success LONG_IS_64BIT
'set up repository with huge blob' '
408 obj=$(test_oid obj) &&
409 path=$(test_oid_to_path $obj) &&
410 mkdir -p .git/objects/$(dirname $path) &&
411 cp "$TEST_DIRECTORY"/t5000/huge-object .git/objects/$path &&
413 git update-index --add --cacheinfo 100644,$obj,huge &&
417 # We expect git to die with SIGPIPE here (otherwise we
418 # would generate the whole 64GB).
419 test_expect_success LONG_IS_64BIT
'generate tar with huge size' '
423 } | test_copy_bytes 4096 >huge.tar &&
425 test_cmp expect exit-code
428 test_expect_success TAR_HUGE
,LONG_IS_64BIT
'system tar can read our huge size' '
429 echo 68719476737 >expect &&
430 tar_info huge.tar | cut -d" " -f1 >actual &&
431 test_cmp expect actual
434 test_expect_success TIME_IS_64BIT
'set up repository with far-future (2^34 - 1) commit' '
438 GIT_COMMITTER_DATE="@17179869183 +0000" \
439 git commit -m "tempori parendum"
442 test_expect_success TIME_IS_64BIT
'generate tar with far-future mtime' '
443 git archive HEAD >future.tar
446 test_expect_success TAR_HUGE
,TIME_IS_64BIT
,TIME_T_IS_64BIT
'system tar can read our future mtime' '
448 tar_info future.tar | cut -d" " -f2 >actual &&
449 test_cmp expect actual
452 test_expect_success TIME_IS_64BIT
'set up repository with far-far-future (2^36 + 1) commit' '
454 echo content >file &&
456 GIT_TEST_COMMIT_GRAPH=0 GIT_COMMITTER_DATE="@68719476737 +0000" \
457 git commit -m "tempori parendum"
460 test_expect_success TIME_IS_64BIT
'generate tar with far-far-future mtime' '
461 git archive HEAD >future.tar
464 test_expect_success TAR_HUGE
,TIME_IS_64BIT
,TIME_T_IS_64BIT
'system tar can read our future mtime' '
466 tar_info future.tar | cut -d" " -f2 >actual &&
467 test_cmp expect actual