]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5003-archive-zip.sh
Merge branch 'en/fetch-negotiation-default-fix'
[thirdparty/git.git] / t / t5003-archive-zip.sh
CommitLineData
e9882c80
RS
1#!/bin/sh
2
3test_description='git archive --format=zip test'
4
5. ./test-lib.sh
e9882c80
RS
6
7SUBSTFORMAT=%H%n
8
55292ea2 9test_lazy_prereq UNZIP_SYMLINKS '
6e45972c
ĐTCD
10 "$GIT_UNZIP" "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip &&
11 test -h symlink
55292ea2
RS
12'
13
ff0dab33
ĐTCD
14test_lazy_prereq UNZIP_CONVERT '
15 "$GIT_UNZIP" -a "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip
16'
17
e9882c80
RS
18check_zip() {
19 zipfile=$1.zip
20 listfile=$1.lst
21 dir=$1
22 dir_with_prefix=$dir/$2
23
24 test_expect_success UNZIP " extract ZIP archive" '
25 (mkdir $dir && cd $dir && "$GIT_UNZIP" ../$zipfile)
26 '
27
28 test_expect_success UNZIP " validate filenames" "
29 (cd ${dir_with_prefix}a && find .) | sort >$listfile &&
30 test_cmp a.lst $listfile
31 "
32
33 test_expect_success UNZIP " validate file contents" "
34 diff -r a ${dir_with_prefix}a
35 "
4aff646d
RS
36
37 dir=eol_$1
38 dir_with_prefix=$dir/$2
39 extracted=${dir_with_prefix}a
40 original=a
41
ff0dab33 42 test_expect_success UNZIP_CONVERT " extract ZIP archive with EOL conversion" '
4aff646d
RS
43 (mkdir $dir && cd $dir && "$GIT_UNZIP" -a ../$zipfile)
44 '
45
ff0dab33 46 test_expect_success UNZIP_CONVERT " validate that text files are converted" "
4aff646d
RS
47 test_cmp_bin $extracted/text.cr $extracted/text.crlf &&
48 test_cmp_bin $extracted/text.cr $extracted/text.lf
49 "
50
ff0dab33 51 test_expect_success UNZIP_CONVERT " validate that binary files are unchanged" "
4aff646d
RS
52 test_cmp_bin $original/binary.cr $extracted/binary.cr &&
53 test_cmp_bin $original/binary.crlf $extracted/binary.crlf &&
54 test_cmp_bin $original/binary.lf $extracted/binary.lf
55 "
56
ff0dab33 57 test_expect_success UNZIP_CONVERT " validate that diff files are converted" "
4aff646d
RS
58 test_cmp_bin $extracted/diff.cr $extracted/diff.crlf &&
59 test_cmp_bin $extracted/diff.cr $extracted/diff.lf
60 "
61
ff0dab33 62 test_expect_success UNZIP_CONVERT " validate that -diff files are unchanged" "
4aff646d
RS
63 test_cmp_bin $original/nodiff.cr $extracted/nodiff.cr &&
64 test_cmp_bin $original/nodiff.crlf $extracted/nodiff.crlf &&
65 test_cmp_bin $original/nodiff.lf $extracted/nodiff.lf
66 "
965cba2e 67
ff0dab33 68 test_expect_success UNZIP_CONVERT " validate that custom diff is unchanged " "
965cba2e
JK
69 test_cmp_bin $original/custom.cr $extracted/custom.cr &&
70 test_cmp_bin $original/custom.crlf $extracted/custom.crlf &&
71 test_cmp_bin $original/custom.lf $extracted/custom.lf
72 "
e9882c80
RS
73}
74
2947a793
RS
75check_added() {
76 dir=$1
77 path_in_fs=$2
78 path_in_archive=$3
79
80 test_expect_success UNZIP " validate extra file $path_in_archive" '
81 diff -r $path_in_fs $dir/$path_in_archive
82 '
83}
84
e9882c80
RS
85test_expect_success \
86 'populate workdir' \
1355241b 87 'mkdir a &&
e9882c80
RS
88 echo simple textfile >a/a &&
89 mkdir a/bin &&
90 cp /bin/sh a/bin &&
4aff646d
RS
91 printf "text\r" >a/text.cr &&
92 printf "text\r\n" >a/text.crlf &&
93 printf "text\n" >a/text.lf &&
94 printf "text\r" >a/nodiff.cr &&
95 printf "text\r\n" >a/nodiff.crlf &&
96 printf "text\n" >a/nodiff.lf &&
965cba2e
JK
97 printf "text\r" >a/custom.cr &&
98 printf "text\r\n" >a/custom.crlf &&
99 printf "text\n" >a/custom.lf &&
4aff646d
RS
100 printf "\0\r" >a/binary.cr &&
101 printf "\0\r\n" >a/binary.crlf &&
102 printf "\0\n" >a/binary.lf &&
103 printf "\0\r" >a/diff.cr &&
104 printf "\0\r\n" >a/diff.crlf &&
105 printf "\0\n" >a/diff.lf &&
e9882c80
RS
106 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
107 printf "A not substituted O" >a/substfile2 &&
e9882c80 108 (p=long_path_to_a_file && cd a &&
d0fd9931 109 for depth in 1 2 3 4 5; do mkdir $p && cd $p || exit 1; done &&
55292ea2
RS
110 echo text >file_with_long_path)
111'
112
113test_expect_success SYMLINKS,UNZIP_SYMLINKS 'add symlink' '
114 ln -s a a/symlink_to_a
115'
116
117test_expect_success 'prepare file list' '
118 (cd a && find .) | sort >a.lst
119'
e9882c80
RS
120
121test_expect_success \
122 'add ignored file' \
123 'echo ignore me >a/ignored &&
124 echo ignored export-ignore >.git/info/attributes'
125
21711ca4
RS
126test_expect_success 'add files to repository' '
127 git add a &&
128 GIT_COMMITTER_DATE="2005-05-27 22:00" git commit -m initial
129'
e9882c80 130
4aff646d
RS
131test_expect_success 'setup export-subst and diff attributes' '
132 echo "a/nodiff.* -diff" >>.git/info/attributes &&
133 echo "a/diff.* diff" >>.git/info/attributes &&
965cba2e
JK
134 echo "a/custom.* diff=custom" >>.git/info/attributes &&
135 git config diff.custom.binary true &&
d3c1472f
RS
136 echo "substfile?" export-subst >>.git/info/attributes &&
137 git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
138 >a/substfile1
139'
140
965cba2e
JK
141test_expect_success 'create bare clone' '
142 git clone --bare . bare.git &&
143 cp .git/info/attributes bare.git/info/attributes &&
144 # Recreate our changes to .git/config rather than just copying it, as
145 # we do not want to clobber core.bare or other settings.
146 git -C bare.git config diff.custom.binary true
147'
e9882c80
RS
148
149test_expect_success \
150 'remove ignored file' \
151 'rm a/ignored'
152
153test_expect_success \
154 'git archive --format=zip' \
155 'git archive --format=zip HEAD >d.zip'
156
157check_zip d
158
159test_expect_success \
160 'git archive --format=zip in a bare repo' \
161 '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
162
163test_expect_success \
164 'git archive --format=zip vs. the same in a bare repo' \
b93e6e36 165 'test_cmp_bin d.zip d1.zip'
e9882c80
RS
166
167test_expect_success 'git archive --format=zip with --output' \
168 'git archive --format=zip --output=d2.zip HEAD &&
b93e6e36 169 test_cmp_bin d.zip d2.zip'
e9882c80 170
00436bf1 171test_expect_success 'git archive with --output, inferring format (local)' '
e9882c80 172 git archive --output=d3.zip HEAD &&
b93e6e36 173 test_cmp_bin d.zip d3.zip
e9882c80
RS
174'
175
00436bf1
JS
176test_expect_success 'git archive with --output, inferring format (remote)' '
177 git archive --remote=. --output=d4.zip HEAD &&
178 test_cmp_bin d.zip d4.zip
179'
180
e9882c80
RS
181test_expect_success \
182 'git archive --format=zip with prefix' \
183 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
184
185check_zip e prefix/
186
187test_expect_success 'git archive -0 --format=zip on large files' '
188 test_config core.bigfilethreshold 1 &&
189 git archive -0 --format=zip HEAD >large.zip
190'
191
192check_zip large
193
194test_expect_success 'git archive --format=zip on large files' '
195 test_config core.bigfilethreshold 1 &&
196 git archive --format=zip HEAD >large-compressed.zip
197'
198
199check_zip large-compressed
200
2947a793
RS
201test_expect_success 'git archive --format=zip --add-file' '
202 echo untracked >untracked &&
203 git archive --format=zip --add-file=untracked HEAD >with_untracked.zip
204'
205
206check_zip with_untracked
207check_added with_untracked untracked untracked
208
209test_expect_success 'git archive --format=zip --add-file twice' '
210 echo untracked >untracked &&
211 git archive --format=zip --prefix=one/ --add-file=untracked \
212 --prefix=two/ --add-file=untracked \
213 --prefix= HEAD >with_untracked2.zip
214'
215check_zip with_untracked2
216check_added with_untracked2 untracked one/untracked
217check_added with_untracked2 untracked two/untracked
218
e9882c80 219test_done