]>
Commit | Line | Data |
---|---|---|
e9882c80 RS |
1 | #!/bin/sh |
2 | ||
3 | test_description='git archive --format=zip test' | |
4 | ||
8da0b02d | 5 | TEST_CREATE_REPO_NO_TEMPLATE=1 |
e9882c80 | 6 | . ./test-lib.sh |
e9882c80 RS |
7 | |
8 | SUBSTFORMAT=%H%n | |
9 | ||
55292ea2 | 10 | test_lazy_prereq UNZIP_SYMLINKS ' |
6e45972c ĐTCD |
11 | "$GIT_UNZIP" "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip && |
12 | test -h symlink | |
55292ea2 RS |
13 | ' |
14 | ||
ff0dab33 ĐTCD |
15 | test_lazy_prereq UNZIP_CONVERT ' |
16 | "$GIT_UNZIP" -a "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip | |
17 | ' | |
18 | ||
e9882c80 RS |
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 | " | |
4aff646d RS |
37 | |
38 | dir=eol_$1 | |
39 | dir_with_prefix=$dir/$2 | |
40 | extracted=${dir_with_prefix}a | |
41 | original=a | |
42 | ||
ff0dab33 | 43 | test_expect_success UNZIP_CONVERT " extract ZIP archive with EOL conversion" ' |
4aff646d RS |
44 | (mkdir $dir && cd $dir && "$GIT_UNZIP" -a ../$zipfile) |
45 | ' | |
46 | ||
ff0dab33 | 47 | test_expect_success UNZIP_CONVERT " validate that text files are converted" " |
4aff646d RS |
48 | test_cmp_bin $extracted/text.cr $extracted/text.crlf && |
49 | test_cmp_bin $extracted/text.cr $extracted/text.lf | |
50 | " | |
51 | ||
ff0dab33 | 52 | test_expect_success UNZIP_CONVERT " validate that binary files are unchanged" " |
4aff646d RS |
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 | ||
ff0dab33 | 58 | test_expect_success UNZIP_CONVERT " validate that diff files are converted" " |
4aff646d RS |
59 | test_cmp_bin $extracted/diff.cr $extracted/diff.crlf && |
60 | test_cmp_bin $extracted/diff.cr $extracted/diff.lf | |
61 | " | |
62 | ||
ff0dab33 | 63 | test_expect_success UNZIP_CONVERT " validate that -diff files are unchanged" " |
4aff646d RS |
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 | " | |
965cba2e | 68 | |
ff0dab33 | 69 | test_expect_success UNZIP_CONVERT " validate that custom diff is unchanged " " |
965cba2e JK |
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 | " | |
e9882c80 RS |
74 | } |
75 | ||
2947a793 RS |
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 | ||
e9882c80 RS |
86 | test_expect_success \ |
87 | 'populate workdir' \ | |
1355241b | 88 | 'mkdir a && |
e9882c80 RS |
89 | echo simple textfile >a/a && |
90 | mkdir a/bin && | |
91 | cp /bin/sh a/bin && | |
4aff646d RS |
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 && | |
965cba2e JK |
98 | printf "text\r" >a/custom.cr && |
99 | printf "text\r\n" >a/custom.crlf && | |
100 | printf "text\n" >a/custom.lf && | |
4aff646d RS |
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 && | |
e9882c80 RS |
107 | printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 && |
108 | printf "A not substituted O" >a/substfile2 && | |
e9882c80 | 109 | (p=long_path_to_a_file && cd a && |
d0fd9931 | 110 | for depth in 1 2 3 4 5; do mkdir $p && cd $p || exit 1; done && |
55292ea2 RS |
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 | ' | |
e9882c80 RS |
121 | |
122 | test_expect_success \ | |
123 | 'add ignored file' \ | |
124 | 'echo ignore me >a/ignored && | |
8da0b02d | 125 | mkdir .git/info && |
e9882c80 RS |
126 | echo ignored export-ignore >.git/info/attributes' |
127 | ||
21711ca4 RS |
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 | ' | |
e9882c80 | 132 | |
4aff646d RS |
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 && | |
965cba2e JK |
136 | echo "a/custom.* diff=custom" >>.git/info/attributes && |
137 | git config diff.custom.binary true && | |
d3c1472f RS |
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 | ||
965cba2e | 143 | test_expect_success 'create bare clone' ' |
8da0b02d ÆAB |
144 | git clone --template= --bare . bare.git && |
145 | mkdir bare.git/info && | |
965cba2e JK |
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 | ' | |
e9882c80 RS |
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' \ | |
b93e6e36 | 168 | 'test_cmp_bin d.zip d1.zip' |
e9882c80 RS |
169 | |
170 | test_expect_success 'git archive --format=zip with --output' \ | |
171 | 'git archive --format=zip --output=d2.zip HEAD && | |
b93e6e36 | 172 | test_cmp_bin d.zip d2.zip' |
e9882c80 | 173 | |
00436bf1 | 174 | test_expect_success 'git archive with --output, inferring format (local)' ' |
e9882c80 | 175 | git archive --output=d3.zip HEAD && |
b93e6e36 | 176 | test_cmp_bin d.zip d3.zip |
e9882c80 RS |
177 | ' |
178 | ||
00436bf1 JS |
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 | ||
e9882c80 RS |
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 | ||
2947a793 RS |
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 | ||
237a1d13 | 212 | test_expect_success UNZIP 'git archive --format=zip --add-virtual-file' ' |
de1f68a9 JS |
213 | if test_have_prereq FUNNYNAMES |
214 | then | |
215 | PATHNAME="pathname with : colon" | |
216 | else | |
217 | PATHNAME="pathname without colon" | |
218 | fi && | |
237a1d13 | 219 | git archive --format=zip >with_file_with_content.zip \ |
de1f68a9 | 220 | --add-virtual-file=\""$PATHNAME"\": \ |
237a1d13 JS |
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 && | |
de1f68a9 | 227 | test_path_is_file "$PATHNAME" && |
237a1d13 JS |
228 | test world = $(cat hello) |
229 | ) | |
230 | ' | |
231 | ||
2947a793 RS |
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 | ||
e9882c80 | 242 | test_done |