Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t5003-archive-zip.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t5003-archive-zip.sh` 310 lines ยท 8894 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='git archive --format=zip test' 4 5 TEST_CREATE_REPO_NO_TEMPLATE=1 6 . ./test-lib.sh 7 8 SUBSTFORMAT=%H%n 9 10 test_lazy_prereq UNZIP_SYMLINKS ' 11 "$GIT_UNZIP" "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip && 12 test -h symlink 13 ' 14 15 test_lazy_prereq UNZIP_CONVERT ' 16 "$GIT_UNZIP" -a "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip 17 ' 18 19 check_zip() { 20 zipfile=$1.zip 21 listfile=$1.lst 22 dir=$1 23 dir_with_prefix=$dir/$2 24 25 test_expect_success UNZIP " extract ZIP archive" ' 26 (mkdir $dir && cd $dir && "$GIT_UNZIP" ../$zipfile) 27 ' 28 29 test_expect_success UNZIP " validate filenames" " 30 (cd ${dir_with_prefix}a && find .) | sort >$listfile && 31 test_cmp a.lst $listfile 32 " 33 34 test_expect_success UNZIP " validate file contents" " 35 diff -r a ${dir_with_prefix}a 36 " 37 38 dir=eol_$1 39 dir_with_prefix=$dir/$2 40 extracted=${dir_with_prefix}a 41 original=a 42 43 test_expect_success UNZIP_CONVERT " extract ZIP archive with EOL conversion" ' 44 (mkdir $dir && cd $dir && "$GIT_UNZIP" -a ../$zipfile) 45 ' 46 47 test_expect_success UNZIP_CONVERT " validate that text files are converted" " 48 test_cmp_bin $extracted/text.cr $extracted/text.crlf && 49 test_cmp_bin $extracted/text.cr $extracted/text.lf 50 " 51 52 test_expect_success UNZIP_CONVERT " validate that binary files are unchanged" " 53 test_cmp_bin $original/binary.cr $extracted/binary.cr && 54 test_cmp_bin $original/binary.crlf $extracted/binary.crlf && 55 test_cmp_bin $original/binary.lf $extracted/binary.lf 56 " 57 58 test_expect_success UNZIP_CONVERT " validate that diff files are converted" " 59 test_cmp_bin $extracted/diff.cr $extracted/diff.crlf && 60 test_cmp_bin $extracted/diff.cr $extracted/diff.lf 61 " 62 63 test_expect_success UNZIP_CONVERT " validate that -diff files are unchanged" " 64 test_cmp_bin $original/nodiff.cr $extracted/nodiff.cr && 65 test_cmp_bin $original/nodiff.crlf $extracted/nodiff.crlf && 66 test_cmp_bin $original/nodiff.lf $extracted/nodiff.lf 67 " 68 69 test_expect_success UNZIP_CONVERT " validate that custom diff is unchanged " " 70 test_cmp_bin $original/custom.cr $extracted/custom.cr && 71 test_cmp_bin $original/custom.crlf $extracted/custom.crlf && 72 test_cmp_bin $original/custom.lf $extracted/custom.lf 73 " 74 } 75 76 check_added() { 77 dir=$1 78 path_in_fs=$2 79 path_in_archive=$3 80 81 test_expect_success UNZIP " validate extra file $path_in_archive" ' 82 diff -r $path_in_fs $dir/$path_in_archive 83 ' 84 } 85 86 test_expect_success \ 87 'populate workdir' \ 88 'mkdir a && 89 echo simple textfile >a/a && 90 mkdir a/bin && 91 cp /bin/sh a/bin && 92 printf "text\r" >a/text.cr && 93 printf "text\r\n" >a/text.crlf && 94 printf "text\n" >a/text.lf && 95 printf "text\r" >a/nodiff.cr && 96 printf "text\r\n" >a/nodiff.crlf && 97 printf "text\n" >a/nodiff.lf && 98 printf "text\r" >a/custom.cr && 99 printf "text\r\n" >a/custom.crlf && 100 printf "text\n" >a/custom.lf && 101 printf "\0\r" >a/binary.cr && 102 printf "\0\r\n" >a/binary.crlf && 103 printf "\0\n" >a/binary.lf && 104 printf "\0\r" >a/diff.cr && 105 printf "\0\r\n" >a/diff.crlf && 106 printf "\0\n" >a/diff.lf && 107 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 && 108 printf "A not substituted O" >a/substfile2 && 109 (p=long_path_to_a_file && cd a && 110 for depth in 1 2 3 4 5; do mkdir $p && cd $p || exit 1; done && 111 echo text >file_with_long_path) 112 ' 113 114 test_expect_success SYMLINKS,UNZIP_SYMLINKS 'add symlink' ' 115 ln -s a a/symlink_to_a 116 ' 117 118 test_expect_success 'prepare file list' ' 119 (cd a && find .) | sort >a.lst 120 ' 121 122 test_expect_success \ 123 'add ignored file' \ 124 'echo ignore me >a/ignored && 125 mkdir .git/info && 126 echo ignored export-ignore >.git/info/attributes' 127 128 test_expect_success 'add files to repository' ' 129 git add a && 130 GIT_COMMITTER_DATE="2005-05-27 22:00" git commit -m initial 131 ' 132 133 test_expect_success 'setup export-subst and diff attributes' ' 134 echo "a/nodiff.* -diff" >>.git/info/attributes && 135 echo "a/diff.* diff" >>.git/info/attributes && 136 echo "a/custom.* diff=custom" >>.git/info/attributes && 137 git config diff.custom.binary true && 138 echo "substfile?" export-subst >>.git/info/attributes && 139 git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \ 140 >a/substfile1 141 ' 142 143 test_expect_success 'create bare clone' ' 144 git clone --template= --bare . bare.git && 145 mkdir bare.git/info && 146 cp .git/info/attributes bare.git/info/attributes && 147 # Recreate our changes to .git/config rather than just copying it, as 148 # we do not want to clobber core.bare or other settings. 149 git -C bare.git config diff.custom.binary true 150 ' 151 152 test_expect_success \ 153 'remove ignored file' \ 154 'rm a/ignored' 155 156 test_expect_success \ 157 'git archive --format=zip' \ 158 'git archive --format=zip HEAD >d.zip' 159 160 check_zip d 161 162 test_expect_success \ 163 'git archive --format=zip in a bare repo' \ 164 '(cd bare.git && git archive --format=zip HEAD) >d1.zip' 165 166 test_expect_success \ 167 'git archive --format=zip vs. the same in a bare repo' \ 168 'test_cmp_bin d.zip d1.zip' 169 170 test_expect_success 'git archive --format=zip with --output' \ 171 'git archive --format=zip --output=d2.zip HEAD && 172 test_cmp_bin d.zip d2.zip' 173 174 test_expect_success 'git archive with --output, inferring format (local)' ' 175 git archive --output=d3.zip HEAD && 176 test_cmp_bin d.zip d3.zip 177 ' 178 179 test_expect_success 'git archive with --output, inferring format (remote)' ' 180 git archive --remote=. --output=d4.zip HEAD && 181 test_cmp_bin d.zip d4.zip 182 ' 183 184 test_expect_success \ 185 'git archive --format=zip with prefix' \ 186 'git archive --format=zip --prefix=prefix/ HEAD >e.zip' 187 188 check_zip e prefix/ 189 190 test_expect_success 'git archive -0 --format=zip on large files' ' 191 test_config core.bigfilethreshold 1 && 192 git archive -0 --format=zip HEAD >large.zip 193 ' 194 195 check_zip large 196 197 test_expect_success 'git archive --format=zip on large files' ' 198 test_config core.bigfilethreshold 1 && 199 git archive --format=zip HEAD >large-compressed.zip 200 ' 201 202 check_zip large-compressed 203 204 test_expect_success 'git archive --format=zip --add-file' ' 205 echo untracked >untracked && 206 git archive --format=zip --add-file=untracked HEAD >with_untracked.zip 207 ' 208 209 check_zip with_untracked 210 check_added with_untracked untracked untracked 211 212 test_expect_success UNZIP 'git archive --format=zip --add-virtual-file' ' 213 if test_have_prereq FUNNYNAMES 214 then 215 PATHNAME="pathname with : colon" 216 else 217 PATHNAME="pathname without colon" 218 fi && 219 git archive --format=zip >with_file_with_content.zip \ 220 --add-virtual-file=\""$PATHNAME"\": \ 221 --add-virtual-file=hello:world $EMPTY_TREE && 222 test_when_finished "rm -rf tmp-unpack" && 223 mkdir tmp-unpack && ( 224 cd tmp-unpack && 225 "$GIT_UNZIP" ../with_file_with_content.zip && 226 test_path_is_file hello && 227 test_path_is_file "$PATHNAME" && 228 test world = $(cat hello) 229 ) 230 ' 231 232 test_expect_success 'git archive --format=zip --add-file twice' ' 233 echo untracked >untracked && 234 git archive --format=zip --prefix=one/ --add-file=untracked \ 235 --prefix=two/ --add-file=untracked \ 236 --prefix= HEAD >with_untracked2.zip 237 ' 238 check_zip with_untracked2 239 check_added with_untracked2 untracked one/untracked 240 check_added with_untracked2 untracked two/untracked 241 242 test_expect_success 'git-archive --format=zip with bigFile delta chains' ' 243 test_when_finished rm -rf repo && 244 git init repo && 245 ( 246 cd repo && 247 test-tool genrandom foo 100000 >base && 248 { 249 cat base && 250 echo "trailing data" 251 } >delta-1 && 252 { 253 cat delta-1 && 254 echo "trailing data" 255 } >delta-2 && 256 git add . && 257 git commit -m "blobs" && 258 git repack -Ad && 259 git verify-pack -v .git/objects/pack/pack-*.idx >stats && 260 test_grep "chain length = 1: 1 object" stats && 261 test_grep "chain length = 2: 1 object" stats && 262 263 git -c core.bigFileThreshold=1k archive --format=zip HEAD >archive.zip && 264 if test_have_prereq UNZIP 265 then 266 mkdir unpack && 267 cd unpack && 268 "$GIT_UNZIP" ../archive.zip && 269 test_cmp base ../base && 270 test_cmp delta-1 ../delta-1 && 271 test_cmp delta-2 ../delta-2 272 fi 273 ) 274 ' 275 276 # Test remote archive over HTTP protocol. 277 # 278 # Note: this should be the last part of this test suite, because 279 # by including lib-httpd.sh, the test may end early if httpd tests 280 # should not be run. 281 # 282 . "$TEST_DIRECTORY"/lib-httpd.sh 283 start_httpd 284 285 test_expect_success "setup for HTTP protocol" ' 286 cp -R bare.git "$HTTPD_DOCUMENT_ROOT_PATH/bare.git" && 287 git -C "$HTTPD_DOCUMENT_ROOT_PATH/bare.git" \ 288 config http.uploadpack true && 289 set_askpass user@host pass@host 290 ' 291 292 setup_askpass_helper 293 294 test_expect_success 'remote archive does not work with protocol v1' ' 295 test_must_fail git -c protocol.version=1 archive \ 296 --remote="$HTTPD_URL/auth/smart/bare.git" \ 297 --output=remote-http.zip HEAD >actual 2>&1 && 298 cat >expect <<-EOF && 299 fatal: can${SQ}t connect to subservice git-upload-archive 300 EOF 301 test_cmp expect actual 302 ' 303 304 test_expect_success 'archive remote http repository' ' 305 git archive --remote="$HTTPD_URL/auth/smart/bare.git" \ 306 --output=remote-http.zip HEAD && 307 test_cmp_bin d.zip remote-http.zip 308 ' 309 310 test_done