Clarify and correct -z
[git/dscho.git] / t / t9401-git-cvsserver-crlf.sh
blobaca40c1b1ff0f957652f75383625367d85242c14
1 #!/bin/sh
3 # Copyright (c) 2008 Matthew Ogilvie
4 # Parts adapted from other tests.
7 test_description='git-cvsserver -kb modes
9 tests -kb mode for binary files when accessing a git
10 repository using cvs CLI client via git-cvsserver server'
12 . ./test-lib.sh
14 q_to_nul () {
15 perl -pe 'y/Q/\000/'
18 q_to_cr () {
19 tr Q '\015'
22 marked_as () {
23 foundEntry="$(grep "^/$2/" "$1/CVS/Entries")"
24 if [ x"$foundEntry" = x"" ] ; then
25 echo "NOT FOUND: $1 $2 1 $3" >> "${WORKDIR}/marked.log"
26 return 1
28 test x"$(grep "^/$2/" "$1/CVS/Entries" | cut -d/ -f5)" = x"$3"
29 stat=$?
30 echo "$1 $2 $stat '$3'" >> "${WORKDIR}/marked.log"
31 return $stat
34 not_present() {
35 foundEntry="$(grep "^/$2/" "$1/CVS/Entries")"
36 if [ -r "$1/$2" ] ; then
37 echo "Error: File still exists: $1 $2" >> "${WORKDIR}/marked.log"
38 return 1;
40 if [ x"$foundEntry" != x"" ] ; then
41 echo "Error: should not have found: $1 $2" >> "${WORKDIR}/marked.log"
42 return 1;
43 else
44 echo "Correctly not found: $1 $2" >> "${WORKDIR}/marked.log"
45 return 0;
49 cvs >/dev/null 2>&1
50 if test $? -ne 1
51 then
52 say 'skipping git-cvsserver tests, cvs not found'
53 test_done
55 if ! test_have_prereq PERL
56 then
57 say 'skipping git-cvsserver tests, perl not available'
58 test_done
60 perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
61 say 'skipping git-cvsserver tests, Perl SQLite interface unavailable'
62 test_done
65 unset GIT_DIR GIT_CONFIG
66 WORKDIR=$(pwd)
67 SERVERDIR=$(pwd)/gitcvs.git
68 git_config="$SERVERDIR/config"
69 CVSROOT=":fork:$SERVERDIR"
70 CVSWORK="$(pwd)/cvswork"
71 CVS_SERVER=git-cvsserver
72 export CVSROOT CVS_SERVER
74 rm -rf "$CVSWORK" "$SERVERDIR"
75 test_expect_success 'setup' '
76 echo "Simple text file" >textfile.c &&
77 echo "File with embedded NUL: Q <- there" | q_to_nul > binfile.bin &&
78 mkdir subdir &&
79 echo "Another text file" > subdir/file.h &&
80 echo "Another binary: Q (this time CR)" | q_to_cr > subdir/withCr.bin &&
81 echo "Mixed up NUL, but marked text: Q <- there" | q_to_nul > mixedUp.c
82 echo "Unspecified" > subdir/unspecified.other &&
83 echo "/*.bin -crlf" > .gitattributes &&
84 echo "/*.c crlf" >> .gitattributes &&
85 echo "subdir/*.bin -crlf" >> .gitattributes &&
86 echo "subdir/*.c crlf" >> .gitattributes &&
87 echo "subdir/file.h crlf" >> .gitattributes &&
88 git add .gitattributes textfile.c binfile.bin mixedUp.c subdir/* &&
89 git commit -q -m "First Commit" &&
90 git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
91 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
92 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log"
95 test_expect_success 'cvs co (default crlf)' '
96 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
97 test x"$(grep '/-k' cvswork/CVS/Entries cvswork/subdir/CVS/Entries)" = x""
100 rm -rf cvswork
101 test_expect_success 'cvs co (allbinary)' '
102 GIT_DIR="$SERVERDIR" git config --bool gitcvs.allbinary true &&
103 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
104 marked_as cvswork textfile.c -kb &&
105 marked_as cvswork binfile.bin -kb &&
106 marked_as cvswork .gitattributes -kb &&
107 marked_as cvswork mixedUp.c -kb &&
108 marked_as cvswork/subdir withCr.bin -kb &&
109 marked_as cvswork/subdir file.h -kb &&
110 marked_as cvswork/subdir unspecified.other -kb
113 rm -rf cvswork cvs.log
114 test_expect_success 'cvs co (use attributes/allbinary)' '
115 GIT_DIR="$SERVERDIR" git config --bool gitcvs.usecrlfattr true &&
116 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
117 marked_as cvswork textfile.c "" &&
118 marked_as cvswork binfile.bin -kb &&
119 marked_as cvswork .gitattributes -kb &&
120 marked_as cvswork mixedUp.c "" &&
121 marked_as cvswork/subdir withCr.bin -kb &&
122 marked_as cvswork/subdir file.h "" &&
123 marked_as cvswork/subdir unspecified.other -kb
126 rm -rf cvswork
127 test_expect_success 'cvs co (use attributes)' '
128 GIT_DIR="$SERVERDIR" git config --bool gitcvs.allbinary false &&
129 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
130 marked_as cvswork textfile.c "" &&
131 marked_as cvswork binfile.bin -kb &&
132 marked_as cvswork .gitattributes "" &&
133 marked_as cvswork mixedUp.c "" &&
134 marked_as cvswork/subdir withCr.bin -kb &&
135 marked_as cvswork/subdir file.h "" &&
136 marked_as cvswork/subdir unspecified.other ""
139 test_expect_success 'adding files' '
140 cd cvswork/subdir &&
141 echo "more text" > src.c &&
142 GIT_CONFIG="$git_config" cvs -Q add src.c >cvs.log 2>&1 &&
143 marked_as . src.c "" &&
144 echo "psuedo-binary" > temp.bin &&
145 cd .. &&
146 GIT_CONFIG="$git_config" cvs -Q add subdir/temp.bin >cvs.log 2>&1 &&
147 marked_as subdir temp.bin "-kb" &&
148 cd subdir &&
149 GIT_CONFIG="$git_config" cvs -Q ci -m "adding files" >cvs.log 2>&1 &&
150 marked_as . temp.bin "-kb" &&
151 marked_as . src.c ""
154 cd "$WORKDIR"
155 test_expect_success 'updating' '
156 git pull gitcvs.git &&
157 echo 'hi' > subdir/newfile.bin &&
158 echo 'junk' > subdir/file.h &&
159 echo 'hi' > subdir/newfile.c &&
160 echo 'hello' >> binfile.bin &&
161 git add subdir/newfile.bin subdir/file.h subdir/newfile.c binfile.bin &&
162 git commit -q -m "Add and change some files" &&
163 git push gitcvs.git >/dev/null &&
164 cd cvswork &&
165 GIT_CONFIG="$git_config" cvs -Q update &&
166 cd .. &&
167 marked_as cvswork textfile.c "" &&
168 marked_as cvswork binfile.bin -kb &&
169 marked_as cvswork .gitattributes "" &&
170 marked_as cvswork mixedUp.c "" &&
171 marked_as cvswork/subdir withCr.bin -kb &&
172 marked_as cvswork/subdir file.h "" &&
173 marked_as cvswork/subdir unspecified.other "" &&
174 marked_as cvswork/subdir newfile.bin -kb &&
175 marked_as cvswork/subdir newfile.c "" &&
176 echo "File with embedded NUL: Q <- there" | q_to_nul > tmpExpect1 &&
177 echo "hello" >> tmpExpect1 &&
178 cmp cvswork/binfile.bin tmpExpect1
181 rm -rf cvswork
182 test_expect_success 'cvs co (use attributes/guess)' '
183 GIT_DIR="$SERVERDIR" git config gitcvs.allbinary guess &&
184 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
185 marked_as cvswork textfile.c "" &&
186 marked_as cvswork binfile.bin -kb &&
187 marked_as cvswork .gitattributes "" &&
188 marked_as cvswork mixedUp.c "" &&
189 marked_as cvswork/subdir withCr.bin -kb &&
190 marked_as cvswork/subdir file.h "" &&
191 marked_as cvswork/subdir unspecified.other "" &&
192 marked_as cvswork/subdir newfile.bin -kb &&
193 marked_as cvswork/subdir newfile.c ""
196 test_expect_success 'setup multi-line files' '
197 ( echo "line 1" &&
198 echo "line 2" &&
199 echo "line 3" &&
200 echo "line 4 with NUL: Q <-" ) | q_to_nul > multiline.c &&
201 git add multiline.c &&
202 ( echo "line 1" &&
203 echo "line 2" &&
204 echo "line 3" &&
205 echo "line 4" ) | q_to_nul > multilineTxt.c &&
206 git add multilineTxt.c &&
207 git commit -q -m "multiline files" &&
208 git push gitcvs.git >/dev/null
211 rm -rf cvswork
212 test_expect_success 'cvs co (guess)' '
213 GIT_DIR="$SERVERDIR" git config --bool gitcvs.usecrlfattr false &&
214 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
215 marked_as cvswork textfile.c "" &&
216 marked_as cvswork binfile.bin -kb &&
217 marked_as cvswork .gitattributes "" &&
218 marked_as cvswork mixedUp.c -kb &&
219 marked_as cvswork multiline.c -kb &&
220 marked_as cvswork multilineTxt.c "" &&
221 marked_as cvswork/subdir withCr.bin -kb &&
222 marked_as cvswork/subdir file.h "" &&
223 marked_as cvswork/subdir unspecified.other "" &&
224 marked_as cvswork/subdir newfile.bin "" &&
225 marked_as cvswork/subdir newfile.c ""
228 test_expect_success 'cvs co another copy (guess)' '
229 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
230 marked_as cvswork2 textfile.c "" &&
231 marked_as cvswork2 binfile.bin -kb &&
232 marked_as cvswork2 .gitattributes "" &&
233 marked_as cvswork2 mixedUp.c -kb &&
234 marked_as cvswork2 multiline.c -kb &&
235 marked_as cvswork2 multilineTxt.c "" &&
236 marked_as cvswork2/subdir withCr.bin -kb &&
237 marked_as cvswork2/subdir file.h "" &&
238 marked_as cvswork2/subdir unspecified.other "" &&
239 marked_as cvswork2/subdir newfile.bin "" &&
240 marked_as cvswork2/subdir newfile.c ""
243 test_expect_success 'add text (guess)' '
244 cd cvswork &&
245 echo "simpleText" > simpleText.c &&
246 GIT_CONFIG="$git_config" cvs -Q add simpleText.c &&
247 cd .. &&
248 marked_as cvswork simpleText.c ""
251 test_expect_success 'add bin (guess)' '
252 cd cvswork &&
253 echo "simpleBin: NUL: Q <- there" | q_to_nul > simpleBin.bin &&
254 GIT_CONFIG="$git_config" cvs -Q add simpleBin.bin &&
255 cd .. &&
256 marked_as cvswork simpleBin.bin -kb
259 test_expect_success 'remove files (guess)' '
260 cd cvswork &&
261 GIT_CONFIG="$git_config" cvs -Q rm -f subdir/file.h &&
262 cd subdir &&
263 GIT_CONFIG="$git_config" cvs -Q rm -f withCr.bin &&
264 cd ../.. &&
265 marked_as cvswork/subdir withCr.bin -kb &&
266 marked_as cvswork/subdir file.h ""
269 test_expect_success 'cvs ci (guess)' '
270 cd cvswork &&
271 GIT_CONFIG="$git_config" cvs -Q ci -m "add/rm files" >cvs.log 2>&1 &&
272 cd .. &&
273 marked_as cvswork textfile.c "" &&
274 marked_as cvswork binfile.bin -kb &&
275 marked_as cvswork .gitattributes "" &&
276 marked_as cvswork mixedUp.c -kb &&
277 marked_as cvswork multiline.c -kb &&
278 marked_as cvswork multilineTxt.c "" &&
279 not_present cvswork/subdir withCr.bin &&
280 not_present cvswork/subdir file.h &&
281 marked_as cvswork/subdir unspecified.other "" &&
282 marked_as cvswork/subdir newfile.bin "" &&
283 marked_as cvswork/subdir newfile.c "" &&
284 marked_as cvswork simpleBin.bin -kb &&
285 marked_as cvswork simpleText.c ""
288 test_expect_success 'update subdir of other copy (guess)' '
289 cd cvswork2/subdir &&
290 GIT_CONFIG="$git_config" cvs -Q update &&
291 cd ../.. &&
292 marked_as cvswork2 textfile.c "" &&
293 marked_as cvswork2 binfile.bin -kb &&
294 marked_as cvswork2 .gitattributes "" &&
295 marked_as cvswork2 mixedUp.c -kb &&
296 marked_as cvswork2 multiline.c -kb &&
297 marked_as cvswork2 multilineTxt.c "" &&
298 not_present cvswork2/subdir withCr.bin &&
299 not_present cvswork2/subdir file.h &&
300 marked_as cvswork2/subdir unspecified.other "" &&
301 marked_as cvswork2/subdir newfile.bin "" &&
302 marked_as cvswork2/subdir newfile.c "" &&
303 not_present cvswork2 simpleBin.bin &&
304 not_present cvswork2 simpleText.c
307 echo "starting update/merge" >> "${WORKDIR}/marked.log"
308 test_expect_success 'update/merge full other copy (guess)' '
309 git pull gitcvs.git master &&
310 sed "s/3/replaced_3/" < multilineTxt.c > ml.temp &&
311 mv ml.temp multilineTxt.c &&
312 git add multilineTxt.c &&
313 git commit -q -m "modify multiline file" >> "${WORKDIR}/marked.log" &&
314 git push gitcvs.git >/dev/null &&
315 cd cvswork2 &&
316 sed "s/1/replaced_1/" < multilineTxt.c > ml.temp &&
317 mv ml.temp multilineTxt.c &&
318 GIT_CONFIG="$git_config" cvs update > cvs.log 2>&1 &&
319 cd .. &&
320 marked_as cvswork2 textfile.c "" &&
321 marked_as cvswork2 binfile.bin -kb &&
322 marked_as cvswork2 .gitattributes "" &&
323 marked_as cvswork2 mixedUp.c -kb &&
324 marked_as cvswork2 multiline.c -kb &&
325 marked_as cvswork2 multilineTxt.c "" &&
326 not_present cvswork2/subdir withCr.bin &&
327 not_present cvswork2/subdir file.h &&
328 marked_as cvswork2/subdir unspecified.other "" &&
329 marked_as cvswork2/subdir newfile.bin "" &&
330 marked_as cvswork2/subdir newfile.c "" &&
331 marked_as cvswork2 simpleBin.bin -kb &&
332 marked_as cvswork2 simpleText.c "" &&
333 echo "line replaced_1" > tmpExpect2 &&
334 echo "line 2" >> tmpExpect2 &&
335 echo "line replaced_3" >> tmpExpect2 &&
336 echo "line 4" | q_to_nul >> tmpExpect2 &&
337 cmp cvswork2/multilineTxt.c tmpExpect2
340 test_done