Seventh batch for 2.20
[git/debian.git] / t / t5003-archive-zip.sh
blob55c78709978ff75cdbd794ee4c816dfd1eb55ef0
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 '
11 mkdir unzip-symlinks &&
12 cd unzip-symlinks &&
13 "$GIT_UNZIP" "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip &&
14 test -h symlink
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 " extract ZIP archive with EOL conversion" '
43 (mkdir $dir && cd $dir && "$GIT_UNZIP" -a ../$zipfile)
46 test_expect_success UNZIP " 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 " 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 " 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 " 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 " 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 test_expect_success \
76 'populate workdir' \
77 'mkdir a &&
78 echo simple textfile >a/a &&
79 mkdir a/bin &&
80 cp /bin/sh a/bin &&
81 printf "text\r" >a/text.cr &&
82 printf "text\r\n" >a/text.crlf &&
83 printf "text\n" >a/text.lf &&
84 printf "text\r" >a/nodiff.cr &&
85 printf "text\r\n" >a/nodiff.crlf &&
86 printf "text\n" >a/nodiff.lf &&
87 printf "text\r" >a/custom.cr &&
88 printf "text\r\n" >a/custom.crlf &&
89 printf "text\n" >a/custom.lf &&
90 printf "\0\r" >a/binary.cr &&
91 printf "\0\r\n" >a/binary.crlf &&
92 printf "\0\n" >a/binary.lf &&
93 printf "\0\r" >a/diff.cr &&
94 printf "\0\r\n" >a/diff.crlf &&
95 printf "\0\n" >a/diff.lf &&
96 printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
97 printf "A not substituted O" >a/substfile2 &&
98 (p=long_path_to_a_file && cd a &&
99 for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
100 echo text >file_with_long_path)
103 test_expect_success SYMLINKS,UNZIP_SYMLINKS 'add symlink' '
104 ln -s a a/symlink_to_a
107 test_expect_success 'prepare file list' '
108 (cd a && find .) | sort >a.lst
111 test_expect_success \
112 'add ignored file' \
113 'echo ignore me >a/ignored &&
114 echo ignored export-ignore >.git/info/attributes'
116 test_expect_success 'add files to repository' '
117 git add a &&
118 GIT_COMMITTER_DATE="2005-05-27 22:00" git commit -m initial
121 test_expect_success 'setup export-subst and diff attributes' '
122 echo "a/nodiff.* -diff" >>.git/info/attributes &&
123 echo "a/diff.* diff" >>.git/info/attributes &&
124 echo "a/custom.* diff=custom" >>.git/info/attributes &&
125 git config diff.custom.binary true &&
126 echo "substfile?" export-subst >>.git/info/attributes &&
127 git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
128 >a/substfile1
131 test_expect_success 'create bare clone' '
132 git clone --bare . bare.git &&
133 cp .git/info/attributes bare.git/info/attributes &&
134 # Recreate our changes to .git/config rather than just copying it, as
135 # we do not want to clobber core.bare or other settings.
136 git -C bare.git config diff.custom.binary true
139 test_expect_success \
140 'remove ignored file' \
141 'rm a/ignored'
143 test_expect_success \
144 'git archive --format=zip' \
145 'git archive --format=zip HEAD >d.zip'
147 check_zip d
149 test_expect_success \
150 'git archive --format=zip in a bare repo' \
151 '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
153 test_expect_success \
154 'git archive --format=zip vs. the same in a bare repo' \
155 'test_cmp_bin d.zip d1.zip'
157 test_expect_success 'git archive --format=zip with --output' \
158 'git archive --format=zip --output=d2.zip HEAD &&
159 test_cmp_bin d.zip d2.zip'
161 test_expect_success 'git archive with --output, inferring format' '
162 git archive --output=d3.zip HEAD &&
163 test_cmp_bin d.zip d3.zip
166 test_expect_success \
167 'git archive --format=zip with prefix' \
168 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
170 check_zip e prefix/
172 test_expect_success 'git archive -0 --format=zip on large files' '
173 test_config core.bigfilethreshold 1 &&
174 git archive -0 --format=zip HEAD >large.zip
177 check_zip large
179 test_expect_success 'git archive --format=zip on large files' '
180 test_config core.bigfilethreshold 1 &&
181 git archive --format=zip HEAD >large-compressed.zip
184 check_zip large-compressed
186 test_done