Rene Scharfe | d3d49c3 | 2005-06-02 22:50:17 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (C) 2005 Rene Scharfe |
| 4 | # |
| 5 | |
John Keeping | 925cecc | 2013-11-10 15:47:29 +0000 | [diff] [blame] | 6 | test_description='git archive and git get-tar-commit-id test |
Rene Scharfe | d3d49c3 | 2005-06-02 22:50:17 +0200 | [diff] [blame] | 7 | |
Rene Scharfe | 5b86040 | 2005-06-03 18:21:23 +0200 | [diff] [blame] | 8 | This test covers the topics of file contents, commit date handling and |
| 9 | commit id embedding: |
Rene Scharfe | d3d49c3 | 2005-06-02 22:50:17 +0200 | [diff] [blame] | 10 | |
| 11 | The contents of the repository is compared to the extracted tar |
| 12 | archive. The repository contains simple text files, symlinks and a |
Pavel Roskin | 3dff537 | 2007-02-03 23:49:16 -0500 | [diff] [blame] | 13 | binary file (/bin/sh). Only paths shorter than 99 characters are |
Rene Scharfe | 5b86040 | 2005-06-03 18:21:23 +0200 | [diff] [blame] | 14 | used. |
Rene Scharfe | d3d49c3 | 2005-06-02 22:50:17 +0200 | [diff] [blame] | 15 | |
John Keeping | 925cecc | 2013-11-10 15:47:29 +0000 | [diff] [blame] | 16 | git archive applies the commit date to every file in the archive it |
Rene Scharfe | d3d49c3 | 2005-06-02 22:50:17 +0200 | [diff] [blame] | 17 | creates. The test sets the commit date to a specific value and checks |
| 18 | if the tar archive contains that value. |
| 19 | |
John Keeping | 925cecc | 2013-11-10 15:47:29 +0000 | [diff] [blame] | 20 | When giving git archive a commit id (in contrast to a tree id) it |
Rene Scharfe | d3d49c3 | 2005-06-02 22:50:17 +0200 | [diff] [blame] | 21 | embeds this commit id into the tar archive as a comment. The test |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 22 | checks the ability of git get-tar-commit-id to figure it out from the |
Rene Scharfe | d3d49c3 | 2005-06-02 22:50:17 +0200 | [diff] [blame] | 23 | tar file. |
| 24 | |
| 25 | ' |
| 26 | |
| 27 | . ./test-lib.sh |
| 28 | |
René Scharfe | 38c9c9b | 2007-09-06 18:51:11 +0200 | [diff] [blame] | 29 | SUBSTFORMAT=%H%n |
René Scharfe | 8460b2f | 2007-09-03 20:07:01 +0200 | [diff] [blame] | 30 | |
René Scharfe | 9bf1ac4 | 2013-05-20 11:58:29 +0200 | [diff] [blame] | 31 | test_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 | |
Jeff King | 9617414 | 2013-12-03 08:21:40 -0500 | [diff] [blame] | 40 | test_lazy_prereq GZIP 'gzip --version' |
| 41 | |
René Scharfe | 9bf1ac4 | 2013-05-20 11:58:29 +0200 | [diff] [blame] | 42 | get_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 | |
René Scharfe | deb9c8e | 2013-05-20 11:58:26 +0200 | [diff] [blame] | 59 | check_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 | |
René Scharfe | 9bf1ac4 | 2013-05-20 11:58:29 +0200 | [diff] [blame] | 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 && |
Elia Pinto | d0b30a3 | 2014-06-06 07:55:58 -0700 | [diff] [blame] | 75 | if test -h $data || test -e $data |
René Scharfe | 9bf1ac4 | 2013-05-20 11:58:29 +0200 | [diff] [blame] | 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 | |
René Scharfe | deb9c8e | 2013-05-20 11:58:26 +0200 | [diff] [blame] | 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 | |
René Scharfe | 2947a79 | 2020-09-19 23:23:42 +0200 | [diff] [blame] | 97 | check_added() { |
| 98 | dir=$1 |
| 99 | path_in_fs=$2 |
| 100 | path_in_archive=$3 |
| 101 | |
| 102 | test_expect_success " validate extra file $path_in_archive" ' |
| 103 | diff -r $path_in_fs $dir/$path_in_archive |
| 104 | ' |
| 105 | } |
| 106 | |
brian m. carlson | 0b78a1b | 2019-06-28 22:59:22 +0000 | [diff] [blame] | 107 | test_expect_success 'setup' ' |
| 108 | test_oid_cache <<-EOF |
| 109 | obj sha1:19f9c8273ec45a8938e6999cb59b3ff66739902a |
| 110 | obj sha256:3c666f798798601571f5cec0adb57ce4aba8546875e7693177e0535f34d2c49b |
| 111 | EOF |
| 112 | ' |
| 113 | |
Han-Wen Nienhuys | 9c8e7e9 | 2021-05-31 16:56:24 +0000 | [diff] [blame] | 114 | test_expect_success 'populate workdir' ' |
| 115 | mkdir a && |
| 116 | echo simple textfile >a/a && |
| 117 | ten=0123456789 && |
| 118 | hundred="$ten$ten$ten$ten$ten$ten$ten$ten$ten$ten" && |
| 119 | echo long filename >"a/four$hundred" && |
| 120 | mkdir a/bin && |
| 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 |
| 125 | then |
| 126 | ln -s a a/l1 |
| 127 | else |
| 128 | printf %s a >a/l1 |
| 129 | fi && |
| 130 | ( |
| 131 | p=long_path_to_a_file && |
| 132 | cd a && |
| 133 | for depth in 1 2 3 4 5 |
| 134 | do |
| 135 | mkdir $p && |
| 136 | cd $p |
| 137 | done && |
| 138 | echo text >file_with_long_path |
| 139 | ) && |
| 140 | (cd a && find .) | sort >a.lst |
| 141 | ' |
Rene Scharfe | d3d49c3 | 2005-06-02 22:50:17 +0200 | [diff] [blame] | 142 | |
| 143 | test_expect_success \ |
René Scharfe | 008d896 | 2008-06-08 18:42:33 +0200 | [diff] [blame] | 144 | 'add ignored file' \ |
| 145 | 'echo ignore me >a/ignored && |
René Scharfe | ad94657 | 2009-04-18 00:17:49 +0200 | [diff] [blame] | 146 | echo ignored export-ignore >.git/info/attributes' |
René Scharfe | 008d896 | 2008-06-08 18:42:33 +0200 | [diff] [blame] | 147 | |
René Scharfe | 21711ca | 2014-07-05 21:35:01 +0200 | [diff] [blame] | 148 | test_expect_success 'add files to repository' ' |
| 149 | git add a && |
| 150 | GIT_COMMITTER_DATE="2005-05-27 22:00" git commit -m initial |
| 151 | ' |
Rene Scharfe | d3d49c3 | 2005-06-02 22:50:17 +0200 | [diff] [blame] | 152 | |
René Scharfe | c420df7 | 2013-05-20 11:58:24 +0200 | [diff] [blame] | 153 | test_expect_success 'setup export-subst' ' |
| 154 | echo "substfile?" export-subst >>.git/info/attributes && |
| 155 | git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \ |
| 156 | >a/substfile1 |
| 157 | ' |
| 158 | |
Han-Wen Nienhuys | 9c8e7e9 | 2021-05-31 16:56:24 +0000 | [diff] [blame] | 159 | test_expect_success 'create bare clone' ' |
| 160 | git clone --bare . bare.git && |
| 161 | cp .git/info/attributes bare.git/info/attributes |
| 162 | ' |
Charles Bailey | ddff856 | 2008-10-25 11:38:14 -0400 | [diff] [blame] | 163 | |
Han-Wen Nienhuys | 9c8e7e9 | 2021-05-31 16:56:24 +0000 | [diff] [blame] | 164 | test_expect_success 'remove ignored file' ' |
| 165 | rm a/ignored |
| 166 | ' |
René Scharfe | 008d896 | 2008-06-08 18:42:33 +0200 | [diff] [blame] | 167 | |
Han-Wen Nienhuys | 9c8e7e9 | 2021-05-31 16:56:24 +0000 | [diff] [blame] | 168 | test_expect_success 'git archive' ' |
| 169 | git archive HEAD >b.tar |
| 170 | ' |
René Scharfe | 8ff21b1 | 2007-04-09 17:12:53 +0200 | [diff] [blame] | 171 | |
René Scharfe | deb9c8e | 2013-05-20 11:58:26 +0200 | [diff] [blame] | 172 | check_tar b |
| 173 | |
René Scharfe | 03d9bc5 | 2013-05-20 11:58:27 +0200 | [diff] [blame] | 174 | test_expect_success 'git archive --prefix=prefix/' ' |
| 175 | git archive --prefix=prefix/ HEAD >with_prefix.tar |
| 176 | ' |
| 177 | |
| 178 | check_tar with_prefix prefix/ |
| 179 | |
| 180 | test_expect_success 'git-archive --prefix=olde-' ' |
| 181 | git archive --prefix=olde- HEAD >with_olde-prefix.tar |
| 182 | ' |
| 183 | |
| 184 | check_tar with_olde-prefix olde- |
| 185 | |
René Scharfe | 2947a79 | 2020-09-19 23:23:42 +0200 | [diff] [blame] | 186 | test_expect_success 'git archive --add-file' ' |
| 187 | echo untracked >untracked && |
| 188 | git archive --add-file=untracked HEAD >with_untracked.tar |
| 189 | ' |
| 190 | |
| 191 | check_tar with_untracked |
| 192 | check_added with_untracked untracked untracked |
| 193 | |
| 194 | test_expect_success 'git archive --add-file twice' ' |
| 195 | echo untracked >untracked && |
| 196 | git archive --prefix=one/ --add-file=untracked \ |
| 197 | --prefix=two/ --add-file=untracked \ |
| 198 | --prefix= HEAD >with_untracked2.tar |
| 199 | ' |
| 200 | |
| 201 | check_tar with_untracked2 |
| 202 | check_added with_untracked2 untracked one/untracked |
| 203 | check_added with_untracked2 untracked two/untracked |
| 204 | |
Nguyễn Thái Ngọc Duy | 5544049 | 2012-05-03 08:51:04 +0700 | [diff] [blame] | 205 | test_expect_success 'git archive on large files' ' |
Han-Wen Nienhuys | 9c8e7e9 | 2021-05-31 16:56:24 +0000 | [diff] [blame] | 206 | test_config core.bigfilethreshold 1 && |
| 207 | git archive HEAD >b3.tar && |
| 208 | test_cmp_bin b.tar b3.tar |
Nguyễn Thái Ngọc Duy | 5544049 | 2012-05-03 08:51:04 +0700 | [diff] [blame] | 209 | ' |
| 210 | |
Han-Wen Nienhuys | 9c8e7e9 | 2021-05-31 16:56:24 +0000 | [diff] [blame] | 211 | test_expect_success 'git archive in a bare repo' ' |
| 212 | git --git-dir bare.git archive HEAD >b3.tar |
| 213 | ' |
Charles Bailey | ddff856 | 2008-10-25 11:38:14 -0400 | [diff] [blame] | 214 | |
Han-Wen Nienhuys | 9c8e7e9 | 2021-05-31 16:56:24 +0000 | [diff] [blame] | 215 | test_expect_success 'git archive vs. the same in a bare repo' ' |
| 216 | test_cmp_bin b.tar b3.tar |
| 217 | ' |
Charles Bailey | ddff856 | 2008-10-25 11:38:14 -0400 | [diff] [blame] | 218 | |
Han-Wen Nienhuys | 9c8e7e9 | 2021-05-31 16:56:24 +0000 | [diff] [blame] | 219 | test_expect_success 'git archive with --output' ' |
| 220 | git archive --output=b4.tar HEAD && |
| 221 | test_cmp_bin b.tar b4.tar |
| 222 | ' |
Carlos Manuel Duclos Vergara | aec0c1b | 2009-02-16 18:20:25 +0100 | [diff] [blame] | 223 | |
Han-Wen Nienhuys | 9c8e7e9 | 2021-05-31 16:56:24 +0000 | [diff] [blame] | 224 | test_expect_success 'git archive --remote' ' |
| 225 | git archive --remote=. HEAD >b5.tar && |
| 226 | test_cmp_bin b.tar b5.tar |
| 227 | ' |
Thomas Rast | 4813926 | 2009-06-27 20:47:43 +0200 | [diff] [blame] | 228 | |
Junio C Hamano | eb0224c | 2016-11-22 13:37:04 -0800 | [diff] [blame] | 229 | test_expect_success 'git archive --remote with configured remote' ' |
| 230 | git config remote.foo.url . && |
| 231 | ( |
| 232 | cd a && |
| 233 | git archive --remote=foo --output=../b5-nick.tar HEAD |
| 234 | ) && |
| 235 | test_cmp_bin b.tar b5-nick.tar |
| 236 | ' |
| 237 | |
Han-Wen Nienhuys | 9c8e7e9 | 2021-05-31 16:56:24 +0000 | [diff] [blame] | 238 | test_expect_success 'validate file modification time' ' |
| 239 | mkdir extract && |
| 240 | "$TAR" xf b.tar -C extract a/a && |
| 241 | test-tool chmtime --get extract/a/a >b.mtime && |
| 242 | echo "1117231200" >expected.mtime && |
| 243 | test_cmp expected.mtime b.mtime |
| 244 | ' |
Rene Scharfe | d3d49c3 | 2005-06-02 22:50:17 +0200 | [diff] [blame] | 245 | |
Han-Wen Nienhuys | f1ed224 | 2021-05-31 16:56:25 +0000 | [diff] [blame] | 246 | test_expect_success 'git get-tar-commit-id' ' |
| 247 | git get-tar-commit-id <b.tar >actual && |
| 248 | git rev-parse HEAD >expect && |
| 249 | test_cmp expect actual |
| 250 | ' |
Rene Scharfe | d3d49c3 | 2005-06-02 22:50:17 +0200 | [diff] [blame] | 251 | |
René Scharfe | fe12d8e | 2010-02-08 00:30:20 +0100 | [diff] [blame] | 252 | test_expect_success 'git archive with --output, override inferred format' ' |
| 253 | git archive --format=tar --output=d4.zip HEAD && |
Stepan Kasal | b93e6e3 | 2014-06-04 17:57:52 +0200 | [diff] [blame] | 254 | test_cmp_bin b.tar d4.zip |
René Scharfe | fe12d8e | 2010-02-08 00:30:20 +0100 | [diff] [blame] | 255 | ' |
| 256 | |
Josh Steadmon | 00436bf | 2018-10-25 13:32:14 -0700 | [diff] [blame] | 257 | test_expect_success GZIP 'git archive with --output and --remote creates .tgz' ' |
| 258 | git archive --output=d5.tgz --remote=. HEAD && |
| 259 | gzip -d -c <d5.tgz >d5.tar && |
| 260 | test_cmp_bin b.tar d5.tar |
| 261 | ' |
| 262 | |
Junio C Hamano | eb0224c | 2016-11-22 13:37:04 -0800 | [diff] [blame] | 263 | test_expect_success 'git archive --list outside of a git repo' ' |
| 264 | nongit git archive --list |
| 265 | ' |
| 266 | |
| 267 | test_expect_success 'git archive --remote outside of a git repo' ' |
| 268 | git archive HEAD >expect.tar && |
| 269 | nongit git archive --remote="$PWD" HEAD >actual.tar && |
| 270 | test_cmp_bin expect.tar actual.tar |
| 271 | ' |
René Scharfe | 265d528 | 2007-04-05 22:55:43 +0200 | [diff] [blame] | 272 | |
Jeff King | ee27ca4 | 2011-11-17 18:04:22 -0500 | [diff] [blame] | 273 | test_expect_success 'clients cannot access unreachable commits' ' |
| 274 | test_commit unreachable && |
Elia Pinto | f5efd51 | 2014-04-30 09:23:07 -0700 | [diff] [blame] | 275 | sha1=$(git rev-parse HEAD) && |
Jeff King | ee27ca4 | 2011-11-17 18:04:22 -0500 | [diff] [blame] | 276 | git reset --hard HEAD^ && |
| 277 | git archive $sha1 >remote.tar && |
| 278 | test_must_fail git archive --remote=. $sha1 >remote.tar |
| 279 | ' |
| 280 | |
Scott J. Goldman | 7671b63 | 2014-02-28 05:04:19 -0500 | [diff] [blame] | 281 | test_expect_success 'upload-archive can allow unreachable commits' ' |
| 282 | test_commit unreachable1 && |
Elia Pinto | f5efd51 | 2014-04-30 09:23:07 -0700 | [diff] [blame] | 283 | sha1=$(git rev-parse HEAD) && |
Scott J. Goldman | 7671b63 | 2014-02-28 05:04:19 -0500 | [diff] [blame] | 284 | git reset --hard HEAD^ && |
| 285 | git archive $sha1 >remote.tar && |
| 286 | test_config uploadarchive.allowUnreachable true && |
| 287 | git archive --remote=. $sha1 >remote.tar |
| 288 | ' |
| 289 | |
Jeff King | 767cf45 | 2011-06-21 21:26:31 -0400 | [diff] [blame] | 290 | test_expect_success 'setup tar filters' ' |
| 291 | git config tar.tar.foo.command "tr ab ba" && |
Jeff King | 7b97730 | 2011-06-21 23:17:35 -0400 | [diff] [blame] | 292 | git config tar.bar.command "tr ab ba" && |
Jeff King | 785a042 | 2013-01-23 01:23:27 -0500 | [diff] [blame] | 293 | git config tar.bar.remote true && |
| 294 | git config tar.invalid baz |
Jeff King | 767cf45 | 2011-06-21 21:26:31 -0400 | [diff] [blame] | 295 | ' |
| 296 | |
| 297 | test_expect_success 'archive --list mentions user filter' ' |
| 298 | git archive --list >output && |
| 299 | grep "^tar\.foo\$" output && |
| 300 | grep "^bar\$" output |
| 301 | ' |
| 302 | |
Jeff King | 1bc01ef | 2011-11-19 02:40:04 -0500 | [diff] [blame] | 303 | test_expect_success 'archive --list shows only enabled remote filters' ' |
Jeff King | 767cf45 | 2011-06-21 21:26:31 -0400 | [diff] [blame] | 304 | git archive --list --remote=. >output && |
Jeff King | 7b97730 | 2011-06-21 23:17:35 -0400 | [diff] [blame] | 305 | ! grep "^tar\.foo\$" output && |
Jeff King | 767cf45 | 2011-06-21 21:26:31 -0400 | [diff] [blame] | 306 | grep "^bar\$" output |
| 307 | ' |
| 308 | |
| 309 | test_expect_success 'invoke tar filter by format' ' |
| 310 | git archive --format=tar.foo HEAD >config.tar.foo && |
| 311 | tr ab ba <config.tar.foo >config.tar && |
Stepan Kasal | b93e6e3 | 2014-06-04 17:57:52 +0200 | [diff] [blame] | 312 | test_cmp_bin b.tar config.tar && |
Jeff King | 767cf45 | 2011-06-21 21:26:31 -0400 | [diff] [blame] | 313 | git archive --format=bar HEAD >config.bar && |
| 314 | tr ab ba <config.bar >config.tar && |
Stepan Kasal | b93e6e3 | 2014-06-04 17:57:52 +0200 | [diff] [blame] | 315 | test_cmp_bin b.tar config.tar |
Jeff King | 767cf45 | 2011-06-21 21:26:31 -0400 | [diff] [blame] | 316 | ' |
| 317 | |
| 318 | test_expect_success 'invoke tar filter by extension' ' |
| 319 | git archive -o config-implicit.tar.foo HEAD && |
Stepan Kasal | b93e6e3 | 2014-06-04 17:57:52 +0200 | [diff] [blame] | 320 | test_cmp_bin config.tar.foo config-implicit.tar.foo && |
Jeff King | 767cf45 | 2011-06-21 21:26:31 -0400 | [diff] [blame] | 321 | git archive -o config-implicit.bar HEAD && |
Stepan Kasal | b93e6e3 | 2014-06-04 17:57:52 +0200 | [diff] [blame] | 322 | test_cmp_bin config.tar.foo config-implicit.bar |
Jeff King | 767cf45 | 2011-06-21 21:26:31 -0400 | [diff] [blame] | 323 | ' |
| 324 | |
| 325 | test_expect_success 'default output format remains tar' ' |
| 326 | git archive -o config-implicit.baz HEAD && |
Stepan Kasal | b93e6e3 | 2014-06-04 17:57:52 +0200 | [diff] [blame] | 327 | test_cmp_bin b.tar config-implicit.baz |
Jeff King | 767cf45 | 2011-06-21 21:26:31 -0400 | [diff] [blame] | 328 | ' |
| 329 | |
| 330 | test_expect_success 'extension matching requires dot' ' |
| 331 | git archive -o config-implicittar.foo HEAD && |
Stepan Kasal | b93e6e3 | 2014-06-04 17:57:52 +0200 | [diff] [blame] | 332 | test_cmp_bin b.tar config-implicittar.foo |
Jeff King | 767cf45 | 2011-06-21 21:26:31 -0400 | [diff] [blame] | 333 | ' |
| 334 | |
Jeff King | 1bc01ef | 2011-11-19 02:40:04 -0500 | [diff] [blame] | 335 | test_expect_success 'only enabled filters are available remotely' ' |
Jeff King | 7b97730 | 2011-06-21 23:17:35 -0400 | [diff] [blame] | 336 | test_must_fail git archive --remote=. --format=tar.foo HEAD \ |
| 337 | >remote.tar.foo && |
| 338 | git archive --remote=. --format=bar >remote.bar HEAD && |
Stepan Kasal | b93e6e3 | 2014-06-04 17:57:52 +0200 | [diff] [blame] | 339 | test_cmp_bin remote.bar config.bar |
Jeff King | 7b97730 | 2011-06-21 23:17:35 -0400 | [diff] [blame] | 340 | ' |
| 341 | |
Jeff King | 0e804e0 | 2011-06-21 21:27:35 -0400 | [diff] [blame] | 342 | test_expect_success GZIP 'git archive --format=tgz' ' |
| 343 | git archive --format=tgz HEAD >j.tgz |
| 344 | ' |
| 345 | |
| 346 | test_expect_success GZIP 'git archive --format=tar.gz' ' |
| 347 | git archive --format=tar.gz HEAD >j1.tar.gz && |
Stepan Kasal | b93e6e3 | 2014-06-04 17:57:52 +0200 | [diff] [blame] | 348 | test_cmp_bin j.tgz j1.tar.gz |
Jeff King | 0e804e0 | 2011-06-21 21:27:35 -0400 | [diff] [blame] | 349 | ' |
| 350 | |
| 351 | test_expect_success GZIP 'infer tgz from .tgz filename' ' |
| 352 | git archive --output=j2.tgz HEAD && |
Stepan Kasal | b93e6e3 | 2014-06-04 17:57:52 +0200 | [diff] [blame] | 353 | test_cmp_bin j.tgz j2.tgz |
Jeff King | 0e804e0 | 2011-06-21 21:27:35 -0400 | [diff] [blame] | 354 | ' |
| 355 | |
| 356 | test_expect_success GZIP 'infer tgz from .tar.gz filename' ' |
| 357 | git archive --output=j3.tar.gz HEAD && |
Stepan Kasal | b93e6e3 | 2014-06-04 17:57:52 +0200 | [diff] [blame] | 358 | test_cmp_bin j.tgz j3.tar.gz |
Jeff King | 0e804e0 | 2011-06-21 21:27:35 -0400 | [diff] [blame] | 359 | ' |
| 360 | |
Jeff King | 9617414 | 2013-12-03 08:21:40 -0500 | [diff] [blame] | 361 | test_expect_success GZIP 'extract tgz file' ' |
| 362 | gzip -d -c <j.tgz >j.tar && |
Stepan Kasal | b93e6e3 | 2014-06-04 17:57:52 +0200 | [diff] [blame] | 363 | test_cmp_bin b.tar j.tar |
Jeff King | 0e804e0 | 2011-06-21 21:27:35 -0400 | [diff] [blame] | 364 | ' |
| 365 | |
Jeff King | 1bc01ef | 2011-11-19 02:40:04 -0500 | [diff] [blame] | 366 | test_expect_success GZIP 'remote tar.gz is allowed by default' ' |
Jeff King | 7b97730 | 2011-06-21 23:17:35 -0400 | [diff] [blame] | 367 | git archive --remote=. --format=tar.gz HEAD >remote.tar.gz && |
Stepan Kasal | b93e6e3 | 2014-06-04 17:57:52 +0200 | [diff] [blame] | 368 | test_cmp_bin j.tgz remote.tar.gz |
Jeff King | 7b97730 | 2011-06-21 23:17:35 -0400 | [diff] [blame] | 369 | ' |
| 370 | |
Jeff King | 1bc01ef | 2011-11-19 02:40:04 -0500 | [diff] [blame] | 371 | test_expect_success GZIP 'remote tar.gz can be disabled' ' |
Jeff King | 7b97730 | 2011-06-21 23:17:35 -0400 | [diff] [blame] | 372 | git config tar.tar.gz.remote false && |
| 373 | test_must_fail git archive --remote=. --format=tar.gz HEAD \ |
| 374 | >remote.tar.gz |
| 375 | ' |
| 376 | |
Nguyễn Thái Ngọc Duy | ed22b41 | 2014-09-21 10:55:06 +0700 | [diff] [blame] | 377 | test_expect_success 'archive and :(glob)' ' |
| 378 | git archive -v HEAD -- ":(glob)**/sh" >/dev/null 2>actual && |
| 379 | cat >expect <<EOF && |
| 380 | a/ |
| 381 | a/bin/ |
| 382 | a/bin/sh |
| 383 | EOF |
| 384 | test_cmp expect actual |
| 385 | ' |
| 386 | |
| 387 | test_expect_success 'catch non-matching pathspec' ' |
| 388 | test_must_fail git archive -v HEAD -- "*.abc" >/dev/null |
| 389 | ' |
| 390 | |
Jeff King | e51217e | 2016-06-30 05:08:57 -0400 | [diff] [blame] | 391 | # Pull the size and date of each entry in a tarfile using the system tar. |
| 392 | # |
| 393 | # We'll pull out only the year from the date; that avoids any question of |
| 394 | # timezones impacting the result (as long as we keep our test times away from a |
| 395 | # year boundary; our reference times are all in August). |
| 396 | # |
| 397 | # The output of tar_info is expected to be "<size> <year>", both in decimal. It |
| 398 | # ignores the return value of tar. We have to do this, because some of our test |
| 399 | # input is only partial (the real data is 64GB in some cases). |
| 400 | tar_info () { |
| 401 | "$TAR" tvf "$1" | |
| 402 | awk '{ |
| 403 | split($4, date, "-") |
| 404 | print $3 " " date[1] |
| 405 | }' |
| 406 | } |
| 407 | |
| 408 | # See if our system tar can handle a tar file with huge sizes and dates far in |
| 409 | # the future, and that we can actually parse its output. |
| 410 | # |
| 411 | # The reference file was generated by GNU tar, and the magic time and size are |
| 412 | # both octal 01000000000001, which overflows normal ustar fields. |
| 413 | test_lazy_prereq TAR_HUGE ' |
| 414 | echo "68719476737 4147" >expect && |
| 415 | tar_info "$TEST_DIRECTORY"/t5000/huge-and-future.tar >actual && |
| 416 | test_cmp expect actual |
| 417 | ' |
| 418 | |
Junio C Hamano | 2949358 | 2016-07-14 13:04:43 -0700 | [diff] [blame] | 419 | test_expect_success LONG_IS_64BIT 'set up repository with huge blob' ' |
brian m. carlson | 0b78a1b | 2019-06-28 22:59:22 +0000 | [diff] [blame] | 420 | obj=$(test_oid obj) && |
| 421 | path=$(test_oid_to_path $obj) && |
| 422 | mkdir -p .git/objects/$(dirname $path) && |
| 423 | cp "$TEST_DIRECTORY"/t5000/huge-object .git/objects/$path && |
Jeff King | e51217e | 2016-06-30 05:08:57 -0400 | [diff] [blame] | 424 | rm -f .git/index && |
| 425 | git update-index --add --cacheinfo 100644,$obj,huge && |
| 426 | git commit -m huge |
| 427 | ' |
| 428 | |
| 429 | # We expect git to die with SIGPIPE here (otherwise we |
| 430 | # would generate the whole 64GB). |
Junio C Hamano | 2949358 | 2016-07-14 13:04:43 -0700 | [diff] [blame] | 431 | test_expect_success LONG_IS_64BIT 'generate tar with huge size' ' |
Jeff King | e51217e | 2016-06-30 05:08:57 -0400 | [diff] [blame] | 432 | { |
| 433 | git archive HEAD |
| 434 | echo $? >exit-code |
| 435 | } | test_copy_bytes 4096 >huge.tar && |
| 436 | echo 141 >expect && |
| 437 | test_cmp expect exit-code |
| 438 | ' |
| 439 | |
Junio C Hamano | 2949358 | 2016-07-14 13:04:43 -0700 | [diff] [blame] | 440 | test_expect_success TAR_HUGE,LONG_IS_64BIT 'system tar can read our huge size' ' |
Jeff King | e51217e | 2016-06-30 05:08:57 -0400 | [diff] [blame] | 441 | echo 68719476737 >expect && |
| 442 | tar_info huge.tar | cut -d" " -f1 >actual && |
| 443 | test_cmp expect actual |
| 444 | ' |
| 445 | |
Abhishek Kumar | f90fca6 | 2021-01-16 18:11:10 +0000 | [diff] [blame] | 446 | test_expect_success TIME_IS_64BIT 'set up repository with far-future (2^34 - 1) commit' ' |
Jeff King | e51217e | 2016-06-30 05:08:57 -0400 | [diff] [blame] | 447 | rm -f .git/index && |
Abhishek Kumar | f90fca6 | 2021-01-16 18:11:10 +0000 | [diff] [blame] | 448 | echo foo >file && |
Jeff King | e51217e | 2016-06-30 05:08:57 -0400 | [diff] [blame] | 449 | git add file && |
Abhishek Kumar | f90fca6 | 2021-01-16 18:11:10 +0000 | [diff] [blame] | 450 | GIT_COMMITTER_DATE="@17179869183 +0000" \ |
Jeff King | e51217e | 2016-06-30 05:08:57 -0400 | [diff] [blame] | 451 | git commit -m "tempori parendum" |
| 452 | ' |
| 453 | |
Abhishek Kumar | f90fca6 | 2021-01-16 18:11:10 +0000 | [diff] [blame] | 454 | test_expect_success TIME_IS_64BIT 'generate tar with far-future mtime' ' |
| 455 | git archive HEAD >future.tar |
| 456 | ' |
| 457 | |
| 458 | test_expect_success TAR_HUGE,TIME_IS_64BIT,TIME_T_IS_64BIT 'system tar can read our future mtime' ' |
| 459 | echo 2514 >expect && |
| 460 | tar_info future.tar | cut -d" " -f2 >actual && |
| 461 | test_cmp expect actual |
| 462 | ' |
| 463 | |
| 464 | test_expect_success TIME_IS_64BIT 'set up repository with far-far-future (2^36 + 1) commit' ' |
| 465 | rm -f .git/index && |
| 466 | echo content >file && |
| 467 | git add file && |
| 468 | GIT_TEST_COMMIT_GRAPH=0 GIT_COMMITTER_DATE="@68719476737 +0000" \ |
| 469 | git commit -m "tempori parendum" |
| 470 | ' |
| 471 | |
| 472 | test_expect_success TIME_IS_64BIT 'generate tar with far-far-future mtime' ' |
Jeff King | e51217e | 2016-06-30 05:08:57 -0400 | [diff] [blame] | 473 | git archive HEAD >future.tar |
| 474 | ' |
| 475 | |
Johannes Schindelin | efac8ac | 2017-04-20 22:58:21 +0200 | [diff] [blame] | 476 | test_expect_success TAR_HUGE,TIME_IS_64BIT,TIME_T_IS_64BIT 'system tar can read our future mtime' ' |
Jeff King | e51217e | 2016-06-30 05:08:57 -0400 | [diff] [blame] | 477 | echo 4147 >expect && |
| 478 | tar_info future.tar | cut -d" " -f2 >actual && |
| 479 | test_cmp expect actual |
| 480 | ' |
| 481 | |
Rene Scharfe | d3d49c3 | 2005-06-02 22:50:17 +0200 | [diff] [blame] | 482 | test_done |