Merge branch 'ao/send-email-irt'
[git/kirr.git] / t / t9401-git-cvsserver-crlf.sh
blobff6d6fb473fe0b00a4e2135395cdf89c43250a1a
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 marked_as () {
15 foundEntry="$(grep "^/$2/" "$1/CVS/Entries")"
16 if [ x"$foundEntry" = x"" ] ; then
17 echo "NOT FOUND: $1 $2 1 $3" >> "${WORKDIR}/marked.log"
18 return 1
20 test x"$(grep "^/$2/" "$1/CVS/Entries" | cut -d/ -f5)" = x"$3"
21 stat=$?
22 echo "$1 $2 $stat '$3'" >> "${WORKDIR}/marked.log"
23 return $stat
26 not_present() {
27 foundEntry="$(grep "^/$2/" "$1/CVS/Entries")"
28 if [ -r "$1/$2" ] ; then
29 echo "Error: File still exists: $1 $2" >> "${WORKDIR}/marked.log"
30 return 1;
32 if [ x"$foundEntry" != x"" ] ; then
33 echo "Error: should not have found: $1 $2" >> "${WORKDIR}/marked.log"
34 return 1;
35 else
36 echo "Correctly not found: $1 $2" >> "${WORKDIR}/marked.log"
37 return 0;
41 cvs >/dev/null 2>&1
42 if test $? -ne 1
43 then
44 skip_all='skipping git-cvsserver tests, cvs not found'
45 test_done
47 if ! test_have_prereq PERL
48 then
49 skip_all='skipping git-cvsserver tests, perl not available'
50 test_done
52 "$PERL_PATH" -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
53 skip_all='skipping git-cvsserver tests, Perl SQLite interface unavailable'
54 test_done
57 unset GIT_DIR GIT_CONFIG
58 WORKDIR=$(pwd)
59 SERVERDIR=$(pwd)/gitcvs.git
60 git_config="$SERVERDIR/config"
61 CVSROOT=":fork:$SERVERDIR"
62 CVSWORK="$(pwd)/cvswork"
63 CVS_SERVER=git-cvsserver
64 export CVSROOT CVS_SERVER
66 rm -rf "$CVSWORK" "$SERVERDIR"
67 test_expect_success 'setup' '
68 echo "Simple text file" >textfile.c &&
69 echo "File with embedded NUL: Q <- there" | q_to_nul > binfile.bin &&
70 mkdir subdir &&
71 echo "Another text file" > subdir/file.h &&
72 echo "Another binary: Q (this time CR)" | q_to_cr > subdir/withCr.bin &&
73 echo "Mixed up NUL, but marked text: Q <- there" | q_to_nul > mixedUp.c &&
74 echo "Unspecified" > subdir/unspecified.other &&
75 echo "/*.bin -crlf" > .gitattributes &&
76 echo "/*.c crlf" >> .gitattributes &&
77 echo "subdir/*.bin -crlf" >> .gitattributes &&
78 echo "subdir/*.c crlf" >> .gitattributes &&
79 echo "subdir/file.h crlf" >> .gitattributes &&
80 git add .gitattributes textfile.c binfile.bin mixedUp.c subdir/* &&
81 git commit -q -m "First Commit" &&
82 git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
83 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
84 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log"
87 test_expect_success 'cvs co (default crlf)' '
88 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
89 test x"$(grep '/-k' cvswork/CVS/Entries cvswork/subdir/CVS/Entries)" = x""
92 rm -rf cvswork
93 test_expect_success 'cvs co (allbinary)' '
94 GIT_DIR="$SERVERDIR" git config --bool gitcvs.allbinary true &&
95 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
96 marked_as cvswork textfile.c -kb &&
97 marked_as cvswork binfile.bin -kb &&
98 marked_as cvswork .gitattributes -kb &&
99 marked_as cvswork mixedUp.c -kb &&
100 marked_as cvswork/subdir withCr.bin -kb &&
101 marked_as cvswork/subdir file.h -kb &&
102 marked_as cvswork/subdir unspecified.other -kb
105 rm -rf cvswork cvs.log
106 test_expect_success 'cvs co (use attributes/allbinary)' '
107 GIT_DIR="$SERVERDIR" git config --bool gitcvs.usecrlfattr true &&
108 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
109 marked_as cvswork textfile.c "" &&
110 marked_as cvswork binfile.bin -kb &&
111 marked_as cvswork .gitattributes -kb &&
112 marked_as cvswork mixedUp.c "" &&
113 marked_as cvswork/subdir withCr.bin -kb &&
114 marked_as cvswork/subdir file.h "" &&
115 marked_as cvswork/subdir unspecified.other -kb
118 rm -rf cvswork
119 test_expect_success 'cvs co (use attributes)' '
120 GIT_DIR="$SERVERDIR" git config --bool gitcvs.allbinary false &&
121 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
122 marked_as cvswork textfile.c "" &&
123 marked_as cvswork binfile.bin -kb &&
124 marked_as cvswork .gitattributes "" &&
125 marked_as cvswork mixedUp.c "" &&
126 marked_as cvswork/subdir withCr.bin -kb &&
127 marked_as cvswork/subdir file.h "" &&
128 marked_as cvswork/subdir unspecified.other ""
131 test_expect_success 'adding files' '
132 (cd cvswork &&
133 (cd subdir &&
134 echo "more text" > src.c &&
135 GIT_CONFIG="$git_config" cvs -Q add src.c >cvs.log 2>&1 &&
136 marked_as . src.c "" &&
137 echo "psuedo-binary" > temp.bin
138 ) &&
139 GIT_CONFIG="$git_config" cvs -Q add subdir/temp.bin >cvs.log 2>&1 &&
140 marked_as subdir temp.bin "-kb" &&
141 cd subdir &&
142 GIT_CONFIG="$git_config" cvs -Q ci -m "adding files" >cvs.log 2>&1 &&
143 marked_as . temp.bin "-kb" &&
144 marked_as . src.c ""
148 test_expect_success 'updating' '
149 git pull gitcvs.git &&
150 echo 'hi' > subdir/newfile.bin &&
151 echo 'junk' > subdir/file.h &&
152 echo 'hi' > subdir/newfile.c &&
153 echo 'hello' >> binfile.bin &&
154 git add subdir/newfile.bin subdir/file.h subdir/newfile.c binfile.bin &&
155 git commit -q -m "Add and change some files" &&
156 git push gitcvs.git >/dev/null &&
157 (cd cvswork &&
158 GIT_CONFIG="$git_config" cvs -Q update
159 ) &&
160 marked_as cvswork textfile.c "" &&
161 marked_as cvswork binfile.bin -kb &&
162 marked_as cvswork .gitattributes "" &&
163 marked_as cvswork mixedUp.c "" &&
164 marked_as cvswork/subdir withCr.bin -kb &&
165 marked_as cvswork/subdir file.h "" &&
166 marked_as cvswork/subdir unspecified.other "" &&
167 marked_as cvswork/subdir newfile.bin -kb &&
168 marked_as cvswork/subdir newfile.c "" &&
169 echo "File with embedded NUL: Q <- there" | q_to_nul > tmpExpect1 &&
170 echo "hello" >> tmpExpect1 &&
171 cmp cvswork/binfile.bin tmpExpect1
174 rm -rf cvswork
175 test_expect_success 'cvs co (use attributes/guess)' '
176 GIT_DIR="$SERVERDIR" git config gitcvs.allbinary guess &&
177 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
178 marked_as cvswork textfile.c "" &&
179 marked_as cvswork binfile.bin -kb &&
180 marked_as cvswork .gitattributes "" &&
181 marked_as cvswork mixedUp.c "" &&
182 marked_as cvswork/subdir withCr.bin -kb &&
183 marked_as cvswork/subdir file.h "" &&
184 marked_as cvswork/subdir unspecified.other "" &&
185 marked_as cvswork/subdir newfile.bin -kb &&
186 marked_as cvswork/subdir newfile.c ""
189 test_expect_success 'setup multi-line files' '
190 ( echo "line 1" &&
191 echo "line 2" &&
192 echo "line 3" &&
193 echo "line 4 with NUL: Q <-" ) | q_to_nul > multiline.c &&
194 git add multiline.c &&
195 ( echo "line 1" &&
196 echo "line 2" &&
197 echo "line 3" &&
198 echo "line 4" ) | q_to_nul > multilineTxt.c &&
199 git add multilineTxt.c &&
200 git commit -q -m "multiline files" &&
201 git push gitcvs.git >/dev/null
204 rm -rf cvswork
205 test_expect_success 'cvs co (guess)' '
206 GIT_DIR="$SERVERDIR" git config --bool gitcvs.usecrlfattr false &&
207 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
208 marked_as cvswork textfile.c "" &&
209 marked_as cvswork binfile.bin -kb &&
210 marked_as cvswork .gitattributes "" &&
211 marked_as cvswork mixedUp.c -kb &&
212 marked_as cvswork multiline.c -kb &&
213 marked_as cvswork multilineTxt.c "" &&
214 marked_as cvswork/subdir withCr.bin -kb &&
215 marked_as cvswork/subdir file.h "" &&
216 marked_as cvswork/subdir unspecified.other "" &&
217 marked_as cvswork/subdir newfile.bin "" &&
218 marked_as cvswork/subdir newfile.c ""
221 test_expect_success 'cvs co another copy (guess)' '
222 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
223 marked_as cvswork2 textfile.c "" &&
224 marked_as cvswork2 binfile.bin -kb &&
225 marked_as cvswork2 .gitattributes "" &&
226 marked_as cvswork2 mixedUp.c -kb &&
227 marked_as cvswork2 multiline.c -kb &&
228 marked_as cvswork2 multilineTxt.c "" &&
229 marked_as cvswork2/subdir withCr.bin -kb &&
230 marked_as cvswork2/subdir file.h "" &&
231 marked_as cvswork2/subdir unspecified.other "" &&
232 marked_as cvswork2/subdir newfile.bin "" &&
233 marked_as cvswork2/subdir newfile.c ""
236 test_expect_success 'add text (guess)' '
237 (cd cvswork &&
238 echo "simpleText" > simpleText.c &&
239 GIT_CONFIG="$git_config" cvs -Q add simpleText.c
240 ) &&
241 marked_as cvswork simpleText.c ""
244 test_expect_success 'add bin (guess)' '
245 (cd cvswork &&
246 echo "simpleBin: NUL: Q <- there" | q_to_nul > simpleBin.bin &&
247 GIT_CONFIG="$git_config" cvs -Q add simpleBin.bin
248 ) &&
249 marked_as cvswork simpleBin.bin -kb
252 test_expect_success 'remove files (guess)' '
253 (cd cvswork &&
254 GIT_CONFIG="$git_config" cvs -Q rm -f subdir/file.h &&
255 (cd subdir &&
256 GIT_CONFIG="$git_config" cvs -Q rm -f withCr.bin
257 )) &&
258 marked_as cvswork/subdir withCr.bin -kb &&
259 marked_as cvswork/subdir file.h ""
262 test_expect_success 'cvs ci (guess)' '
263 (cd cvswork &&
264 GIT_CONFIG="$git_config" cvs -Q ci -m "add/rm files" >cvs.log 2>&1
265 ) &&
266 marked_as cvswork textfile.c "" &&
267 marked_as cvswork binfile.bin -kb &&
268 marked_as cvswork .gitattributes "" &&
269 marked_as cvswork mixedUp.c -kb &&
270 marked_as cvswork multiline.c -kb &&
271 marked_as cvswork multilineTxt.c "" &&
272 not_present cvswork/subdir withCr.bin &&
273 not_present cvswork/subdir file.h &&
274 marked_as cvswork/subdir unspecified.other "" &&
275 marked_as cvswork/subdir newfile.bin "" &&
276 marked_as cvswork/subdir newfile.c "" &&
277 marked_as cvswork simpleBin.bin -kb &&
278 marked_as cvswork simpleText.c ""
281 test_expect_success 'update subdir of other copy (guess)' '
282 (cd cvswork2/subdir &&
283 GIT_CONFIG="$git_config" cvs -Q update
284 ) &&
285 marked_as cvswork2 textfile.c "" &&
286 marked_as cvswork2 binfile.bin -kb &&
287 marked_as cvswork2 .gitattributes "" &&
288 marked_as cvswork2 mixedUp.c -kb &&
289 marked_as cvswork2 multiline.c -kb &&
290 marked_as cvswork2 multilineTxt.c "" &&
291 not_present cvswork2/subdir withCr.bin &&
292 not_present cvswork2/subdir file.h &&
293 marked_as cvswork2/subdir unspecified.other "" &&
294 marked_as cvswork2/subdir newfile.bin "" &&
295 marked_as cvswork2/subdir newfile.c "" &&
296 not_present cvswork2 simpleBin.bin &&
297 not_present cvswork2 simpleText.c
300 echo "starting update/merge" >> "${WORKDIR}/marked.log"
301 test_expect_success 'update/merge full other copy (guess)' '
302 git pull gitcvs.git master &&
303 sed "s/3/replaced_3/" < multilineTxt.c > ml.temp &&
304 mv ml.temp multilineTxt.c &&
305 git add multilineTxt.c &&
306 git commit -q -m "modify multiline file" >> "${WORKDIR}/marked.log" &&
307 git push gitcvs.git >/dev/null &&
308 (cd cvswork2 &&
309 sed "s/1/replaced_1/" < multilineTxt.c > ml.temp &&
310 mv ml.temp multilineTxt.c &&
311 GIT_CONFIG="$git_config" cvs update > cvs.log 2>&1
312 ) &&
313 marked_as cvswork2 textfile.c "" &&
314 marked_as cvswork2 binfile.bin -kb &&
315 marked_as cvswork2 .gitattributes "" &&
316 marked_as cvswork2 mixedUp.c -kb &&
317 marked_as cvswork2 multiline.c -kb &&
318 marked_as cvswork2 multilineTxt.c "" &&
319 not_present cvswork2/subdir withCr.bin &&
320 not_present cvswork2/subdir file.h &&
321 marked_as cvswork2/subdir unspecified.other "" &&
322 marked_as cvswork2/subdir newfile.bin "" &&
323 marked_as cvswork2/subdir newfile.c "" &&
324 marked_as cvswork2 simpleBin.bin -kb &&
325 marked_as cvswork2 simpleText.c "" &&
326 echo "line replaced_1" > tmpExpect2 &&
327 echo "line 2" >> tmpExpect2 &&
328 echo "line replaced_3" >> tmpExpect2 &&
329 echo "line 4" | q_to_nul >> tmpExpect2 &&
330 cmp cvswork2/multilineTxt.c tmpExpect2
333 test_done