t/README: add missing value for GIT_TEST_DEFAULT_REF_FORMAT
[git/gitster.git] / t / t5003-archive-zip.sh
blob01f591c99b962fced8c5b6e0b1538ad847f814d7
1 #!/bin/sh
3 test_description='git archive --format=zip test'
5 TEST_CREATE_REPO_NO_TEMPLATE=1
6 TEST_PASSES_SANITIZE_LEAK=true
7 . ./test-lib.sh
9 SUBSTFORMAT=%H%n
11 test_lazy_prereq UNZIP_SYMLINKS '
12 "$GIT_UNZIP" "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip &&
13 test -h symlink
16 test_lazy_prereq UNZIP_CONVERT '
17 "$GIT_UNZIP" -a "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip
20 check_zip() {
21 zipfile=$1.zip
22 listfile=$1.lst
23 dir=$1
24 dir_with_prefix=$dir/$2
26 test_expect_success UNZIP " extract ZIP archive" '
27 (mkdir $dir && cd $dir && "$GIT_UNZIP" ../$zipfile)
30 test_expect_success UNZIP " validate filenames" "
31 (cd ${dir_with_prefix}a && find .) | sort >$listfile &&
32 test_cmp a.lst $listfile
35 test_expect_success UNZIP " validate file contents" "
36 diff -r a ${dir_with_prefix}a
39 dir=eol_$1
40 dir_with_prefix=$dir/$2
41 extracted=${dir_with_prefix}a
42 original=a
44 test_expect_success UNZIP_CONVERT " extract ZIP archive with EOL conversion" '
45 (mkdir $dir && cd $dir && "$GIT_UNZIP" -a ../$zipfile)
48 test_expect_success UNZIP_CONVERT " validate that text files are converted" "
49 test_cmp_bin $extracted/text.cr $extracted/text.crlf &&
50 test_cmp_bin $extracted/text.cr $extracted/text.lf
53 test_expect_success UNZIP_CONVERT " validate that binary files are unchanged" "
54 test_cmp_bin $original/binary.cr $extracted/binary.cr &&
55 test_cmp_bin $original/binary.crlf $extracted/binary.crlf &&
56 test_cmp_bin $original/binary.lf $extracted/binary.lf
59 test_expect_success UNZIP_CONVERT " validate that diff files are converted" "
60 test_cmp_bin $extracted/diff.cr $extracted/diff.crlf &&
61 test_cmp_bin $extracted/diff.cr $extracted/diff.lf
64 test_expect_success UNZIP_CONVERT " validate that -diff files are unchanged" "
65 test_cmp_bin $original/nodiff.cr $extracted/nodiff.cr &&
66 test_cmp_bin $original/nodiff.crlf $extracted/nodiff.crlf &&
67 test_cmp_bin $original/nodiff.lf $extracted/nodiff.lf
70 test_expect_success UNZIP_CONVERT " validate that custom diff is unchanged " "
71 test_cmp_bin $original/custom.cr $extracted/custom.cr &&
72 test_cmp_bin $original/custom.crlf $extracted/custom.crlf &&
73 test_cmp_bin $original/custom.lf $extracted/custom.lf
77 check_added() {
78 dir=$1
79 path_in_fs=$2
80 path_in_archive=$3
82 test_expect_success UNZIP " validate extra file $path_in_archive" '
83 diff -r $path_in_fs $dir/$path_in_archive
87 test_expect_success \
88 'populate workdir' \
89 'mkdir a &&
90 echo simple textfile >a/a &&
91 mkdir a/bin &&
92 cp /bin/sh a/bin &&
93 printf "text\r" >a/text.cr &&
94 printf "text\r\n" >a/text.crlf &&
95 printf "text\n" >a/text.lf &&
96 printf "text\r" >a/nodiff.cr &&
97 printf "text\r\n" >a/nodiff.crlf &&
98 printf "text\n" >a/nodiff.lf &&
99 printf "text\r" >a/custom.cr &&
100 printf "text\r\n" >a/custom.crlf &&
101 printf "text\n" >a/custom.lf &&
102 printf "\0\r" >a/binary.cr &&
103 printf "\0\r\n" >a/binary.crlf &&
104 printf "\0\n" >a/binary.lf &&
105 printf "\0\r" >a/diff.cr &&
106 printf "\0\r\n" >a/diff.crlf &&
107 printf "\0\n" >a/diff.lf &&
108 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
109 printf "A not substituted O" >a/substfile2 &&
110 (p=long_path_to_a_file && cd a &&
111 for depth in 1 2 3 4 5; do mkdir $p && cd $p || exit 1; done &&
112 echo text >file_with_long_path)
115 test_expect_success SYMLINKS,UNZIP_SYMLINKS 'add symlink' '
116 ln -s a a/symlink_to_a
119 test_expect_success 'prepare file list' '
120 (cd a && find .) | sort >a.lst
123 test_expect_success \
124 'add ignored file' \
125 'echo ignore me >a/ignored &&
126 mkdir .git/info &&
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 and diff attributes' '
135 echo "a/nodiff.* -diff" >>.git/info/attributes &&
136 echo "a/diff.* diff" >>.git/info/attributes &&
137 echo "a/custom.* diff=custom" >>.git/info/attributes &&
138 git config diff.custom.binary true &&
139 echo "substfile?" export-subst >>.git/info/attributes &&
140 git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
141 >a/substfile1
144 test_expect_success 'create bare clone' '
145 git clone --template= --bare . bare.git &&
146 mkdir bare.git/info &&
147 cp .git/info/attributes bare.git/info/attributes &&
148 # Recreate our changes to .git/config rather than just copying it, as
149 # we do not want to clobber core.bare or other settings.
150 git -C bare.git config diff.custom.binary true
153 test_expect_success \
154 'remove ignored file' \
155 'rm a/ignored'
157 test_expect_success \
158 'git archive --format=zip' \
159 'git archive --format=zip HEAD >d.zip'
161 check_zip d
163 test_expect_success \
164 'git archive --format=zip in a bare repo' \
165 '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
167 test_expect_success \
168 'git archive --format=zip vs. the same in a bare repo' \
169 'test_cmp_bin d.zip d1.zip'
171 test_expect_success 'git archive --format=zip with --output' \
172 'git archive --format=zip --output=d2.zip HEAD &&
173 test_cmp_bin d.zip d2.zip'
175 test_expect_success 'git archive with --output, inferring format (local)' '
176 git archive --output=d3.zip HEAD &&
177 test_cmp_bin d.zip d3.zip
180 test_expect_success 'git archive with --output, inferring format (remote)' '
181 git archive --remote=. --output=d4.zip HEAD &&
182 test_cmp_bin d.zip d4.zip
185 test_expect_success \
186 'git archive --format=zip with prefix' \
187 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
189 check_zip e prefix/
191 test_expect_success 'git archive -0 --format=zip on large files' '
192 test_config core.bigfilethreshold 1 &&
193 git archive -0 --format=zip HEAD >large.zip
196 check_zip large
198 test_expect_success 'git archive --format=zip on large files' '
199 test_config core.bigfilethreshold 1 &&
200 git archive --format=zip HEAD >large-compressed.zip
203 check_zip large-compressed
205 test_expect_success 'git archive --format=zip --add-file' '
206 echo untracked >untracked &&
207 git archive --format=zip --add-file=untracked HEAD >with_untracked.zip
210 check_zip with_untracked
211 check_added with_untracked untracked untracked
213 test_expect_success UNZIP 'git archive --format=zip --add-virtual-file' '
214 if test_have_prereq FUNNYNAMES
215 then
216 PATHNAME="pathname with : colon"
217 else
218 PATHNAME="pathname without colon"
219 fi &&
220 git archive --format=zip >with_file_with_content.zip \
221 --add-virtual-file=\""$PATHNAME"\": \
222 --add-virtual-file=hello:world $EMPTY_TREE &&
223 test_when_finished "rm -rf tmp-unpack" &&
224 mkdir tmp-unpack && (
225 cd tmp-unpack &&
226 "$GIT_UNZIP" ../with_file_with_content.zip &&
227 test_path_is_file hello &&
228 test_path_is_file "$PATHNAME" &&
229 test world = $(cat hello)
233 test_expect_success 'git archive --format=zip --add-file twice' '
234 echo untracked >untracked &&
235 git archive --format=zip --prefix=one/ --add-file=untracked \
236 --prefix=two/ --add-file=untracked \
237 --prefix= HEAD >with_untracked2.zip
239 check_zip with_untracked2
240 check_added with_untracked2 untracked one/untracked
241 check_added with_untracked2 untracked two/untracked
243 # Test remote archive over HTTP protocol.
245 # Note: this should be the last part of this test suite, because
246 # by including lib-httpd.sh, the test may end early if httpd tests
247 # should not be run.
249 . "$TEST_DIRECTORY"/lib-httpd.sh
250 start_httpd
252 test_expect_success "setup for HTTP protocol" '
253 cp -R bare.git "$HTTPD_DOCUMENT_ROOT_PATH/bare.git" &&
254 git -C "$HTTPD_DOCUMENT_ROOT_PATH/bare.git" \
255 config http.uploadpack true &&
256 set_askpass user@host pass@host
259 setup_askpass_helper
261 test_expect_success 'remote archive does not work with protocol v1' '
262 test_must_fail git -c protocol.version=1 archive \
263 --remote="$HTTPD_URL/auth/smart/bare.git" \
264 --output=remote-http.zip HEAD >actual 2>&1 &&
265 cat >expect <<-EOF &&
266 fatal: can${SQ}t connect to subservice git-upload-archive
268 test_cmp expect actual
271 test_expect_success 'archive remote http repository' '
272 git archive --remote="$HTTPD_URL/auth/smart/bare.git" \
273 --output=remote-http.zip HEAD &&
274 test_cmp_bin d.zip remote-http.zip
277 test_done