commit-graph: when incompatible with graphs, indicate why
[git] / t / t5003-archive-zip.sh
1 #!/bin/sh
2
3 test_description='git archive --format=zip test'
4
5 . ./test-lib.sh
6
7 SUBSTFORMAT=%H%n
8
9 test_lazy_prereq UNZIP_SYMLINKS '
10         "$GIT_UNZIP" "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip &&
11         test -h symlink
12 '
13
14 test_lazy_prereq UNZIP_CONVERT '
15         "$GIT_UNZIP" -a "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip
16 '
17
18 check_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         "
36
37         dir=eol_$1
38         dir_with_prefix=$dir/$2
39         extracted=${dir_with_prefix}a
40         original=a
41
42         test_expect_success UNZIP_CONVERT " extract ZIP archive with EOL conversion" '
43                 (mkdir $dir && cd $dir && "$GIT_UNZIP" -a ../$zipfile)
44         '
45
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
49         "
50
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
55         "
56
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
60         "
61
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
66         "
67
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
72         "
73 }
74
75 check_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
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)
111 '
112
113 test_expect_success SYMLINKS,UNZIP_SYMLINKS 'add symlink' '
114         ln -s a a/symlink_to_a
115 '
116
117 test_expect_success 'prepare file list' '
118         (cd a && find .) | sort >a.lst
119 '
120
121 test_expect_success \
122     'add ignored file' \
123     'echo ignore me >a/ignored &&
124      echo ignored export-ignore >.git/info/attributes'
125
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
129 '
130
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
139 '
140
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
147 '
148
149 test_expect_success \
150     'remove ignored file' \
151     'rm a/ignored'
152
153 test_expect_success \
154     'git archive --format=zip' \
155     'git archive --format=zip HEAD >d.zip'
156
157 check_zip d
158
159 test_expect_success \
160     'git archive --format=zip in a bare repo' \
161     '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
162
163 test_expect_success \
164     'git archive --format=zip vs. the same in a bare repo' \
165     'test_cmp_bin d.zip d1.zip'
166
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'
170
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
174 '
175
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
179 '
180
181 test_expect_success \
182     'git archive --format=zip with prefix' \
183     'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
184
185 check_zip e prefix/
186
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
190 '
191
192 check_zip large
193
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
197 '
198
199 check_zip large-compressed
200
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
204 '
205
206 check_zip with_untracked
207 check_added with_untracked untracked untracked
208
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
214 '
215 check_zip with_untracked2
216 check_added with_untracked2 untracked one/untracked
217 check_added with_untracked2 untracked two/untracked
218
219 test_done