builtin/gc.c: ignore cruft packs with `--keep-largest-pack`
[alt-git.git] / t / t5003-archive-zip.sh
blobfc499cdff01d01a6079221e78b50a7924e5ecb71
1 #!/bin/sh
3 test_description='git archive --format=zip test'
5 TEST_CREATE_REPO_NO_TEMPLATE=1
6 . ./test-lib.sh
8 SUBSTFORMAT=%H%n
10 test_lazy_prereq UNZIP_SYMLINKS '
11 "$GIT_UNZIP" "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip &&
12 test -h symlink
15 test_lazy_prereq UNZIP_CONVERT '
16 "$GIT_UNZIP" -a "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip
19 check_zip() {
20 zipfile=$1.zip
21 listfile=$1.lst
22 dir=$1
23 dir_with_prefix=$dir/$2
25 test_expect_success UNZIP " extract ZIP archive" '
26 (mkdir $dir && cd $dir && "$GIT_UNZIP" ../$zipfile)
29 test_expect_success UNZIP " validate filenames" "
30 (cd ${dir_with_prefix}a && find .) | sort >$listfile &&
31 test_cmp a.lst $listfile
34 test_expect_success UNZIP " validate file contents" "
35 diff -r a ${dir_with_prefix}a
38 dir=eol_$1
39 dir_with_prefix=$dir/$2
40 extracted=${dir_with_prefix}a
41 original=a
43 test_expect_success UNZIP_CONVERT " extract ZIP archive with EOL conversion" '
44 (mkdir $dir && cd $dir && "$GIT_UNZIP" -a ../$zipfile)
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
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
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
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
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
76 check_added() {
77 dir=$1
78 path_in_fs=$2
79 path_in_archive=$3
81 test_expect_success UNZIP " validate extra file $path_in_archive" '
82 diff -r $path_in_fs $dir/$path_in_archive
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)
114 test_expect_success SYMLINKS,UNZIP_SYMLINKS 'add symlink' '
115 ln -s a a/symlink_to_a
118 test_expect_success 'prepare file list' '
119 (cd a && find .) | sort >a.lst
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'
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
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
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
152 test_expect_success \
153 'remove ignored file' \
154 'rm a/ignored'
156 test_expect_success \
157 'git archive --format=zip' \
158 'git archive --format=zip HEAD >d.zip'
160 check_zip d
162 test_expect_success \
163 'git archive --format=zip in a bare repo' \
164 '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
166 test_expect_success \
167 'git archive --format=zip vs. the same in a bare repo' \
168 'test_cmp_bin d.zip d1.zip'
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'
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
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
184 test_expect_success \
185 'git archive --format=zip with prefix' \
186 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
188 check_zip e prefix/
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
195 check_zip large
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
202 check_zip large-compressed
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
209 check_zip with_untracked
210 check_added with_untracked untracked untracked
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)
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
238 check_zip with_untracked2
239 check_added with_untracked2 untracked one/untracked
240 check_added with_untracked2 untracked two/untracked
242 test_done