MinGW: Quote arguments for subprocesses that contain a single-quote
[git/dscho.git] / t / t9401-git-cvsserver-crlf.sh
blob888223013444999817a93082418fb60690a425e3
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
54 exit
56 perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
57 say 'skipping git-cvsserver tests, Perl SQLite interface unavailable'
58 test_done
59 exit
62 unset GIT_DIR GIT_CONFIG
63 WORKDIR=$(pwd)
64 SERVERDIR=$(pwd)/gitcvs.git
65 git_config="$SERVERDIR/config"
66 CVSROOT=":fork:$SERVERDIR"
67 CVSWORK="$(pwd)/cvswork"
68 CVS_SERVER=git-cvsserver
69 export CVSROOT CVS_SERVER
71 rm -rf "$CVSWORK" "$SERVERDIR"
72 test_expect_success 'setup' '
73 echo "Simple text file" >textfile.c &&
74 echo "File with embedded NUL: Q <- there" | q_to_nul > binfile.bin &&
75 mkdir subdir &&
76 echo "Another text file" > subdir/file.h &&
77 echo "Another binary: Q (this time CR)" | q_to_cr > subdir/withCr.bin &&
78 echo "Mixed up NUL, but marked text: Q <- there" | q_to_nul > mixedUp.c
79 echo "Unspecified" > subdir/unspecified.other &&
80 echo "/*.bin -crlf" > .gitattributes &&
81 echo "/*.c crlf" >> .gitattributes &&
82 echo "subdir/*.bin -crlf" >> .gitattributes &&
83 echo "subdir/*.c crlf" >> .gitattributes &&
84 echo "subdir/file.h crlf" >> .gitattributes &&
85 git add .gitattributes textfile.c binfile.bin mixedUp.c subdir/* &&
86 git commit -q -m "First Commit" &&
87 git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
88 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
89 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log"
92 test_expect_success 'cvs co (default crlf)' '
93 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
94 test x"$(grep '/-k' cvswork/CVS/Entries cvswork/subdir/CVS/Entries)" = x""
97 rm -rf cvswork
98 test_expect_success 'cvs co (allbinary)' '
99 GIT_DIR="$SERVERDIR" git config --bool gitcvs.allbinary true &&
100 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
101 marked_as cvswork textfile.c -kb &&
102 marked_as cvswork binfile.bin -kb &&
103 marked_as cvswork .gitattributes -kb &&
104 marked_as cvswork mixedUp.c -kb &&
105 marked_as cvswork/subdir withCr.bin -kb &&
106 marked_as cvswork/subdir file.h -kb &&
107 marked_as cvswork/subdir unspecified.other -kb
110 rm -rf cvswork cvs.log
111 test_expect_success 'cvs co (use attributes/allbinary)' '
112 GIT_DIR="$SERVERDIR" git config --bool gitcvs.usecrlfattr true &&
113 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
114 marked_as cvswork textfile.c "" &&
115 marked_as cvswork binfile.bin -kb &&
116 marked_as cvswork .gitattributes -kb &&
117 marked_as cvswork mixedUp.c "" &&
118 marked_as cvswork/subdir withCr.bin -kb &&
119 marked_as cvswork/subdir file.h "" &&
120 marked_as cvswork/subdir unspecified.other -kb
123 rm -rf cvswork
124 test_expect_success 'cvs co (use attributes)' '
125 GIT_DIR="$SERVERDIR" git config --bool gitcvs.allbinary false &&
126 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
127 marked_as cvswork textfile.c "" &&
128 marked_as cvswork binfile.bin -kb &&
129 marked_as cvswork .gitattributes "" &&
130 marked_as cvswork mixedUp.c "" &&
131 marked_as cvswork/subdir withCr.bin -kb &&
132 marked_as cvswork/subdir file.h "" &&
133 marked_as cvswork/subdir unspecified.other ""
136 test_expect_success 'adding files' '
137 cd cvswork/subdir &&
138 echo "more text" > src.c &&
139 GIT_CONFIG="$git_config" cvs -Q add src.c >cvs.log 2>&1 &&
140 marked_as . src.c "" &&
141 echo "psuedo-binary" > temp.bin &&
142 cd .. &&
143 GIT_CONFIG="$git_config" cvs -Q add subdir/temp.bin >cvs.log 2>&1 &&
144 marked_as subdir temp.bin "-kb" &&
145 cd subdir &&
146 GIT_CONFIG="$git_config" cvs -Q ci -m "adding files" >cvs.log 2>&1 &&
147 marked_as . temp.bin "-kb" &&
148 marked_as . src.c ""
151 cd "$WORKDIR"
152 test_expect_success 'updating' '
153 git pull gitcvs.git &&
154 echo 'hi' > subdir/newfile.bin &&
155 echo 'junk' > subdir/file.h &&
156 echo 'hi' > subdir/newfile.c &&
157 echo 'hello' >> binfile.bin &&
158 git add subdir/newfile.bin subdir/file.h subdir/newfile.c binfile.bin &&
159 git commit -q -m "Add and change some files" &&
160 git push gitcvs.git >/dev/null &&
161 cd cvswork &&
162 GIT_CONFIG="$git_config" cvs -Q update &&
163 cd .. &&
164 marked_as cvswork textfile.c "" &&
165 marked_as cvswork binfile.bin -kb &&
166 marked_as cvswork .gitattributes "" &&
167 marked_as cvswork mixedUp.c "" &&
168 marked_as cvswork/subdir withCr.bin -kb &&
169 marked_as cvswork/subdir file.h "" &&
170 marked_as cvswork/subdir unspecified.other "" &&
171 marked_as cvswork/subdir newfile.bin -kb &&
172 marked_as cvswork/subdir newfile.c "" &&
173 echo "File with embedded NUL: Q <- there" | q_to_nul > tmpExpect1 &&
174 echo "hello" >> tmpExpect1 &&
175 cmp cvswork/binfile.bin tmpExpect1
178 rm -rf cvswork
179 test_expect_success 'cvs co (use attributes/guess)' '
180 GIT_DIR="$SERVERDIR" git config gitcvs.allbinary guess &&
181 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
182 marked_as cvswork textfile.c "" &&
183 marked_as cvswork binfile.bin -kb &&
184 marked_as cvswork .gitattributes "" &&
185 marked_as cvswork mixedUp.c "" &&
186 marked_as cvswork/subdir withCr.bin -kb &&
187 marked_as cvswork/subdir file.h "" &&
188 marked_as cvswork/subdir unspecified.other "" &&
189 marked_as cvswork/subdir newfile.bin -kb &&
190 marked_as cvswork/subdir newfile.c ""
193 test_expect_success 'setup multi-line files' '
194 ( echo "line 1" &&
195 echo "line 2" &&
196 echo "line 3" &&
197 echo "line 4 with NUL: Q <-" ) | q_to_nul > multiline.c &&
198 git add multiline.c &&
199 ( echo "line 1" &&
200 echo "line 2" &&
201 echo "line 3" &&
202 echo "line 4" ) | q_to_nul > multilineTxt.c &&
203 git add multilineTxt.c &&
204 git commit -q -m "multiline files" &&
205 git push gitcvs.git >/dev/null
208 rm -rf cvswork
209 test_expect_success 'cvs co (guess)' '
210 GIT_DIR="$SERVERDIR" git config --bool gitcvs.usecrlfattr false &&
211 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
212 marked_as cvswork textfile.c "" &&
213 marked_as cvswork binfile.bin -kb &&
214 marked_as cvswork .gitattributes "" &&
215 marked_as cvswork mixedUp.c -kb &&
216 marked_as cvswork multiline.c -kb &&
217 marked_as cvswork multilineTxt.c "" &&
218 marked_as cvswork/subdir withCr.bin -kb &&
219 marked_as cvswork/subdir file.h "" &&
220 marked_as cvswork/subdir unspecified.other "" &&
221 marked_as cvswork/subdir newfile.bin "" &&
222 marked_as cvswork/subdir newfile.c ""
225 test_expect_success 'cvs co another copy (guess)' '
226 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
227 marked_as cvswork2 textfile.c "" &&
228 marked_as cvswork2 binfile.bin -kb &&
229 marked_as cvswork2 .gitattributes "" &&
230 marked_as cvswork2 mixedUp.c -kb &&
231 marked_as cvswork2 multiline.c -kb &&
232 marked_as cvswork2 multilineTxt.c "" &&
233 marked_as cvswork2/subdir withCr.bin -kb &&
234 marked_as cvswork2/subdir file.h "" &&
235 marked_as cvswork2/subdir unspecified.other "" &&
236 marked_as cvswork2/subdir newfile.bin "" &&
237 marked_as cvswork2/subdir newfile.c ""
240 test_expect_success 'add text (guess)' '
241 cd cvswork &&
242 echo "simpleText" > simpleText.c &&
243 GIT_CONFIG="$git_config" cvs -Q add simpleText.c &&
244 cd .. &&
245 marked_as cvswork simpleText.c ""
248 test_expect_success 'add bin (guess)' '
249 cd cvswork &&
250 echo "simpleBin: NUL: Q <- there" | q_to_nul > simpleBin.bin &&
251 GIT_CONFIG="$git_config" cvs -Q add simpleBin.bin &&
252 cd .. &&
253 marked_as cvswork simpleBin.bin -kb
256 test_expect_success 'remove files (guess)' '
257 cd cvswork &&
258 GIT_CONFIG="$git_config" cvs -Q rm -f subdir/file.h &&
259 cd subdir &&
260 GIT_CONFIG="$git_config" cvs -Q rm -f withCr.bin &&
261 cd ../.. &&
262 marked_as cvswork/subdir withCr.bin -kb &&
263 marked_as cvswork/subdir file.h ""
266 test_expect_success 'cvs ci (guess)' '
267 cd cvswork &&
268 GIT_CONFIG="$git_config" cvs -Q ci -m "add/rm files" >cvs.log 2>&1 &&
269 cd .. &&
270 marked_as cvswork textfile.c "" &&
271 marked_as cvswork binfile.bin -kb &&
272 marked_as cvswork .gitattributes "" &&
273 marked_as cvswork mixedUp.c -kb &&
274 marked_as cvswork multiline.c -kb &&
275 marked_as cvswork multilineTxt.c "" &&
276 not_present cvswork/subdir withCr.bin &&
277 not_present cvswork/subdir file.h &&
278 marked_as cvswork/subdir unspecified.other "" &&
279 marked_as cvswork/subdir newfile.bin "" &&
280 marked_as cvswork/subdir newfile.c "" &&
281 marked_as cvswork simpleBin.bin -kb &&
282 marked_as cvswork simpleText.c ""
285 test_expect_success 'update subdir of other copy (guess)' '
286 cd cvswork2/subdir &&
287 GIT_CONFIG="$git_config" cvs -Q update &&
288 cd ../.. &&
289 marked_as cvswork2 textfile.c "" &&
290 marked_as cvswork2 binfile.bin -kb &&
291 marked_as cvswork2 .gitattributes "" &&
292 marked_as cvswork2 mixedUp.c -kb &&
293 marked_as cvswork2 multiline.c -kb &&
294 marked_as cvswork2 multilineTxt.c "" &&
295 not_present cvswork2/subdir withCr.bin &&
296 not_present cvswork2/subdir file.h &&
297 marked_as cvswork2/subdir unspecified.other "" &&
298 marked_as cvswork2/subdir newfile.bin "" &&
299 marked_as cvswork2/subdir newfile.c "" &&
300 not_present cvswork2 simpleBin.bin &&
301 not_present cvswork2 simpleText.c
304 echo "starting update/merge" >> "${WORKDIR}/marked.log"
305 test_expect_success 'update/merge full other copy (guess)' '
306 git pull gitcvs.git master &&
307 sed "s/3/replaced_3/" < multilineTxt.c > ml.temp &&
308 mv ml.temp multilineTxt.c &&
309 git add multilineTxt.c &&
310 git commit -q -m "modify multiline file" >> "${WORKDIR}/marked.log" &&
311 git push gitcvs.git >/dev/null &&
312 cd cvswork2 &&
313 sed "s/1/replaced_1/" < multilineTxt.c > ml.temp &&
314 mv ml.temp multilineTxt.c &&
315 GIT_CONFIG="$git_config" cvs update > cvs.log 2>&1 &&
316 cd .. &&
317 marked_as cvswork2 textfile.c "" &&
318 marked_as cvswork2 binfile.bin -kb &&
319 marked_as cvswork2 .gitattributes "" &&
320 marked_as cvswork2 mixedUp.c -kb &&
321 marked_as cvswork2 multiline.c -kb &&
322 marked_as cvswork2 multilineTxt.c "" &&
323 not_present cvswork2/subdir withCr.bin &&
324 not_present cvswork2/subdir file.h &&
325 marked_as cvswork2/subdir unspecified.other "" &&
326 marked_as cvswork2/subdir newfile.bin "" &&
327 marked_as cvswork2/subdir newfile.c "" &&
328 marked_as cvswork2 simpleBin.bin -kb &&
329 marked_as cvswork2 simpleText.c "" &&
330 echo "line replaced_1" > tmpExpect2 &&
331 echo "line 2" >> tmpExpect2 &&
332 echo "line replaced_3" >> tmpExpect2 &&
333 echo "line 4" | q_to_nul >> tmpExpect2 &&
334 cmp cvswork2/multilineTxt.c tmpExpect2
337 test_done