pickaxe tests: refactor to use test_commit --append --printf
[git/debian.git] / t / t5003-archive-zip.sh
blob1e6d18b140e5193d1eb046adbbbbba8c20cb63b1
1 #!/bin/sh
3 test_description='git archive --format=zip test'
5 . ./test-lib.sh
7 SUBSTFORMAT=%H%n
9 test_lazy_prereq UNZIP_SYMLINKS '
10 "$GIT_UNZIP" "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip &&
11 test -h symlink
14 test_lazy_prereq UNZIP_CONVERT '
15 "$GIT_UNZIP" -a "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip
18 check_zip() {
19 zipfile=$1.zip
20 listfile=$1.lst
21 dir=$1
22 dir_with_prefix=$dir/$2
24 test_expect_success UNZIP " extract ZIP archive" '
25 (mkdir $dir && cd $dir && "$GIT_UNZIP" ../$zipfile)
28 test_expect_success UNZIP " validate filenames" "
29 (cd ${dir_with_prefix}a && find .) | sort >$listfile &&
30 test_cmp a.lst $listfile
33 test_expect_success UNZIP " validate file contents" "
34 diff -r a ${dir_with_prefix}a
37 dir=eol_$1
38 dir_with_prefix=$dir/$2
39 extracted=${dir_with_prefix}a
40 original=a
42 test_expect_success UNZIP_CONVERT " extract ZIP archive with EOL conversion" '
43 (mkdir $dir && cd $dir && "$GIT_UNZIP" -a ../$zipfile)
46 test_expect_success UNZIP_CONVERT " validate that text files are converted" "
47 test_cmp_bin $extracted/text.cr $extracted/text.crlf &&
48 test_cmp_bin $extracted/text.cr $extracted/text.lf
51 test_expect_success UNZIP_CONVERT " validate that binary files are unchanged" "
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
57 test_expect_success UNZIP_CONVERT " validate that diff files are converted" "
58 test_cmp_bin $extracted/diff.cr $extracted/diff.crlf &&
59 test_cmp_bin $extracted/diff.cr $extracted/diff.lf
62 test_expect_success UNZIP_CONVERT " validate that -diff files are unchanged" "
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
68 test_expect_success UNZIP_CONVERT " validate that custom diff is unchanged " "
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
75 check_added() {
76 dir=$1
77 path_in_fs=$2
78 path_in_archive=$3
80 test_expect_success UNZIP " validate extra file $path_in_archive" '
81 diff -r $path_in_fs $dir/$path_in_archive
85 test_expect_success \
86 'populate workdir' \
87 'mkdir a &&
88 echo simple textfile >a/a &&
89 mkdir a/bin &&
90 cp /bin/sh a/bin &&
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 &&
97 printf "text\r" >a/custom.cr &&
98 printf "text\r\n" >a/custom.crlf &&
99 printf "text\n" >a/custom.lf &&
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 &&
106 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
107 printf "A not substituted O" >a/substfile2 &&
108 (p=long_path_to_a_file && cd a &&
109 for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
110 echo text >file_with_long_path)
113 test_expect_success SYMLINKS,UNZIP_SYMLINKS 'add symlink' '
114 ln -s a a/symlink_to_a
117 test_expect_success 'prepare file list' '
118 (cd a && find .) | sort >a.lst
121 test_expect_success \
122 'add ignored file' \
123 'echo ignore me >a/ignored &&
124 echo ignored export-ignore >.git/info/attributes'
126 test_expect_success 'add files to repository' '
127 git add a &&
128 GIT_COMMITTER_DATE="2005-05-27 22:00" git commit -m initial
131 test_expect_success 'setup export-subst and diff attributes' '
132 echo "a/nodiff.* -diff" >>.git/info/attributes &&
133 echo "a/diff.* diff" >>.git/info/attributes &&
134 echo "a/custom.* diff=custom" >>.git/info/attributes &&
135 git config diff.custom.binary true &&
136 echo "substfile?" export-subst >>.git/info/attributes &&
137 git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
138 >a/substfile1
141 test_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
149 test_expect_success \
150 'remove ignored file' \
151 'rm a/ignored'
153 test_expect_success \
154 'git archive --format=zip' \
155 'git archive --format=zip HEAD >d.zip'
157 check_zip d
159 test_expect_success \
160 'git archive --format=zip in a bare repo' \
161 '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
163 test_expect_success \
164 'git archive --format=zip vs. the same in a bare repo' \
165 'test_cmp_bin d.zip d1.zip'
167 test_expect_success 'git archive --format=zip with --output' \
168 'git archive --format=zip --output=d2.zip HEAD &&
169 test_cmp_bin d.zip d2.zip'
171 test_expect_success 'git archive with --output, inferring format (local)' '
172 git archive --output=d3.zip HEAD &&
173 test_cmp_bin d.zip d3.zip
176 test_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
181 test_expect_success \
182 'git archive --format=zip with prefix' \
183 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
185 check_zip e prefix/
187 test_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
192 check_zip large
194 test_expect_success 'git archive --format=zip on large files' '
195 test_config core.bigfilethreshold 1 &&
196 git archive --format=zip HEAD >large-compressed.zip
199 check_zip large-compressed
201 test_expect_success 'git archive --format=zip --add-file' '
202 echo untracked >untracked &&
203 git archive --format=zip --add-file=untracked HEAD >with_untracked.zip
206 check_zip with_untracked
207 check_added with_untracked untracked untracked
209 test_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
215 check_zip with_untracked2
216 check_added with_untracked2 untracked one/untracked
217 check_added with_untracked2 untracked two/untracked
219 test_done