]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5003-archive-zip.sh
Merge branch 'wb/fsmonitor-bitmap-fix'
[thirdparty/git.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 (
11 mkdir unzip-symlinks &&
12 cd unzip-symlinks &&
13 "$GIT_UNZIP" "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip &&
14 test -h symlink
15 )
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 " extract ZIP archive with EOL conversion" '
43 (mkdir $dir && cd $dir && "$GIT_UNZIP" -a ../$zipfile)
44 '
45
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
49 "
50
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
55 "
56
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
60 "
61
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
66 "
67
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
72 "
73 }
74
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)
101 '
102
103 test_expect_success SYMLINKS,UNZIP_SYMLINKS 'add symlink' '
104 ln -s a a/symlink_to_a
105 '
106
107 test_expect_success 'prepare file list' '
108 (cd a && find .) | sort >a.lst
109 '
110
111 test_expect_success \
112 'add ignored file' \
113 'echo ignore me >a/ignored &&
114 echo ignored export-ignore >.git/info/attributes'
115
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
119 '
120
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
129 '
130
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
137 '
138
139 test_expect_success \
140 'remove ignored file' \
141 'rm a/ignored'
142
143 test_expect_success \
144 'git archive --format=zip' \
145 'git archive --format=zip HEAD >d.zip'
146
147 check_zip d
148
149 test_expect_success \
150 'git archive --format=zip in a bare repo' \
151 '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
152
153 test_expect_success \
154 'git archive --format=zip vs. the same in a bare repo' \
155 'test_cmp_bin d.zip d1.zip'
156
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'
160
161 test_expect_success 'git archive with --output, inferring format (local)' '
162 git archive --output=d3.zip HEAD &&
163 test_cmp_bin d.zip d3.zip
164 '
165
166 test_expect_success 'git archive with --output, inferring format (remote)' '
167 git archive --remote=. --output=d4.zip HEAD &&
168 test_cmp_bin d.zip d4.zip
169 '
170
171 test_expect_success \
172 'git archive --format=zip with prefix' \
173 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
174
175 check_zip e prefix/
176
177 test_expect_success 'git archive -0 --format=zip on large files' '
178 test_config core.bigfilethreshold 1 &&
179 git archive -0 --format=zip HEAD >large.zip
180 '
181
182 check_zip large
183
184 test_expect_success 'git archive --format=zip on large files' '
185 test_config core.bigfilethreshold 1 &&
186 git archive --format=zip HEAD >large-compressed.zip
187 '
188
189 check_zip large-compressed
190
191 test_done