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'
23 foundEntry="$(grep "^/$2/" "$1/CVS/Entries")"
24 if [ x"$foundEntry" = x"" ] ; then
25 echo "NOT FOUND: $1 $2 1 $3" >> "${WORKDIR}/marked.log"
28 test x"$(grep "^/$2/" "$1/CVS/Entries" | cut -d/ -f5)" = x"$3"
30 echo "$1 $2 $stat '$3'" >> "${WORKDIR}/marked.log"
35 foundEntry="$(grep "^/$2/" "$1/CVS/Entries")"
36 if [ -r "$1/$2" ] ; then
37 echo "Error: File still exists: $1 $2" >> "${WORKDIR}/marked.log"
40 if [ x"$foundEntry" != x"" ] ; then
41 echo "Error: should not have found: $1 $2" >> "${WORKDIR}/marked.log"
44 echo "Correctly not found: $1 $2" >> "${WORKDIR}/marked.log"
52 say 'skipping git-cvsserver tests, cvs not found'
55 if ! test_have_prereq PERL
57 say 'skipping git-cvsserver tests, perl not available'
60 perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
61 say 'skipping git-cvsserver tests, Perl SQLite interface unavailable'
65 unset GIT_DIR GIT_CONFIG
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 &&
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""
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
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' '
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 &&
146 GIT_CONFIG="$git_config" cvs -Q add subdir/temp.bin >cvs.log 2>&1 &&
147 marked_as subdir temp.bin "-kb" &&
149 GIT_CONFIG="$git_config" cvs -Q ci -m "adding files" >cvs.log 2>&1 &&
150 marked_as . temp.bin "-kb" &&
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 &&
165 GIT_CONFIG="$git_config" cvs -Q update &&
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
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' '
200 echo "line 4 with NUL: Q <-" ) | q_to_nul > multiline.c &&
201 git add multiline.c &&
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
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)' '
245 echo "simpleText" > simpleText.c &&
246 GIT_CONFIG="$git_config" cvs -Q add simpleText.c &&
248 marked_as cvswork simpleText.c ""
251 test_expect_success 'add bin (guess)' '
253 echo "simpleBin: NUL: Q <- there" | q_to_nul > simpleBin.bin &&
254 GIT_CONFIG="$git_config" cvs -Q add simpleBin.bin &&
256 marked_as cvswork simpleBin.bin -kb
259 test_expect_success 'remove files (guess)' '
261 GIT_CONFIG="$git_config" cvs -Q rm -f subdir/file.h &&
263 GIT_CONFIG="$git_config" cvs -Q rm -f withCr.bin &&
265 marked_as cvswork/subdir withCr.bin -kb &&
266 marked_as cvswork/subdir file.h ""
269 test_expect_success 'cvs ci (guess)' '
271 GIT_CONFIG="$git_config" cvs -Q ci -m "add/rm files" >cvs.log 2>&1 &&
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 &&
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 &&
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 &&
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