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 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
13 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
15 TEST_PASSES_SANITIZE_LEAK
=true
19 foundEntry
="$(grep "^
/$2/" "$1/CVS
/Entries
")"
20 if [ x
"$foundEntry" = x
"" ] ; then
21 echo "NOT FOUND: $1 $2 1 $3" >> "${WORKDIR}/marked.log"
24 test x
"$(grep "^
/$2/" "$1/CVS
/Entries
" | cut -d/ -f5)" = x
"$3"
26 echo "$1 $2 $stat '$3'" >> "${WORKDIR}/marked.log"
31 foundEntry
="$(grep "^
/$2/" "$1/CVS
/Entries
")"
32 if [ -r "$1/$2" ] ; then
33 echo "Error: File still exists: $1 $2" >> "${WORKDIR}/marked.log"
36 if [ x
"$foundEntry" != x
"" ] ; then
37 echo "Error: should not have found: $1 $2" >> "${WORKDIR}/marked.log"
40 echo "Correctly not found: $1 $2" >> "${WORKDIR}/marked.log"
45 check_status_options
() {
47 GIT_CONFIG
="$git_config" cvs
-Q status
"$2" > "${WORKDIR}/status.out" 2>&1
49 if [ x
"$?" != x
"0" ] ; then
50 echo "Error from cvs status: $1 $2" >> "${WORKDIR}/marked.log"
53 got
="$(sed -n -e 's/^[ ]*Sticky Options:[ ]*//p' "${WORKDIR}/status.out
")"
55 if [ x
"$expect" = x
"" ] ; then
58 test x
"$got" = x
"$expect"
60 echo "cvs status: $1 $2 $stat '$3' '$got'" >> "${WORKDIR}/marked.log"
67 skip_all
='skipping git-cvsserver tests, cvs not found'
70 if ! test_have_prereq PERL
72 skip_all
='skipping git-cvsserver tests, perl not available'
75 perl
-e 'use DBI; use DBD::SQLite' >/dev
/null
2>&1 ||
{
76 skip_all
='skipping git-cvsserver tests, Perl SQLite interface unavailable'
80 unset GIT_DIR GIT_CONFIG
82 SERVERDIR
=$PWD/gitcvs.git
83 git_config
="$SERVERDIR/config"
84 CVSROOT
=":fork:$SERVERDIR"
85 CVSWORK
="$PWD/cvswork"
86 CVS_SERVER
=git-cvsserver
87 export CVSROOT CVS_SERVER
89 rm -rf "$CVSWORK" "$SERVERDIR"
90 test_expect_success
'setup' '
91 git config push.default matching &&
92 echo "Simple text file" >textfile.c &&
93 echo "File with embedded NUL: Q <- there" | q_to_nul > binfile.bin &&
95 echo "Another text file" > subdir/file.h &&
96 echo "Another binary: Q (this time CR)" | q_to_cr > subdir/withCr.bin &&
97 echo "Mixed up NUL, but marked text: Q <- there" | q_to_nul > mixedUp.c &&
98 echo "Unspecified" > subdir/unspecified.other &&
99 echo "/*.bin -crlf" > .gitattributes &&
100 echo "/*.c crlf" >> .gitattributes &&
101 echo "subdir/*.bin -crlf" >> .gitattributes &&
102 echo "subdir/*.c crlf" >> .gitattributes &&
103 echo "subdir/file.h crlf" >> .gitattributes &&
104 git add .gitattributes textfile.c binfile.bin mixedUp.c subdir/* &&
105 git commit -q -m "First Commit" &&
106 git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
107 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
108 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log"
111 test_expect_success
'cvs co (default crlf)' '
112 GIT_CONFIG="$git_config" cvs -Q co -d cvswork main >cvs.log 2>&1 &&
113 test x"$(grep '/-k' cvswork/CVS/Entries cvswork/subdir/CVS/Entries)" = x""
117 test_expect_success
'cvs co (allbinary)' '
118 GIT_DIR="$SERVERDIR" git config --bool gitcvs.allbinary true &&
119 GIT_CONFIG="$git_config" cvs -Q co -d cvswork main >cvs.log 2>&1 &&
120 marked_as cvswork textfile.c -kb &&
121 marked_as cvswork binfile.bin -kb &&
122 marked_as cvswork .gitattributes -kb &&
123 marked_as cvswork mixedUp.c -kb &&
124 marked_as cvswork/subdir withCr.bin -kb &&
125 marked_as cvswork/subdir file.h -kb &&
126 marked_as cvswork/subdir unspecified.other -kb
129 rm -rf cvswork cvs.log
130 test_expect_success
'cvs co (use attributes/allbinary)' '
131 GIT_DIR="$SERVERDIR" git config --bool gitcvs.usecrlfattr true &&
132 GIT_CONFIG="$git_config" cvs -Q co -d cvswork main >cvs.log 2>&1 &&
133 marked_as cvswork textfile.c "" &&
134 marked_as cvswork binfile.bin -kb &&
135 marked_as cvswork .gitattributes -kb &&
136 marked_as cvswork mixedUp.c "" &&
137 marked_as cvswork/subdir withCr.bin -kb &&
138 marked_as cvswork/subdir file.h "" &&
139 marked_as cvswork/subdir unspecified.other -kb
143 test_expect_success
'cvs co (use attributes)' '
144 GIT_DIR="$SERVERDIR" git config --bool gitcvs.allbinary false &&
145 GIT_CONFIG="$git_config" cvs -Q co -d cvswork main >cvs.log 2>&1 &&
146 marked_as cvswork textfile.c "" &&
147 marked_as cvswork binfile.bin -kb &&
148 marked_as cvswork .gitattributes "" &&
149 marked_as cvswork mixedUp.c "" &&
150 marked_as cvswork/subdir withCr.bin -kb &&
151 marked_as cvswork/subdir file.h "" &&
152 marked_as cvswork/subdir unspecified.other ""
155 test_expect_success
'adding files' '
158 echo "more text" > src.c &&
159 GIT_CONFIG="$git_config" cvs -Q add src.c >cvs.log 2>&1 &&
160 marked_as . src.c "" &&
161 echo "pseudo-binary" > temp.bin
163 GIT_CONFIG="$git_config" cvs -Q add subdir/temp.bin >cvs.log 2>&1 &&
164 marked_as subdir temp.bin "-kb" &&
166 GIT_CONFIG="$git_config" cvs -Q ci -m "adding files" >cvs.log 2>&1 &&
167 marked_as . temp.bin "-kb" &&
172 test_expect_success
'updating' '
173 git pull gitcvs.git &&
174 echo "hi" >subdir/newfile.bin &&
175 echo "junk" >subdir/file.h &&
176 echo "hi" >subdir/newfile.c &&
177 echo "hello" >>binfile.bin &&
178 git add subdir/newfile.bin subdir/file.h subdir/newfile.c binfile.bin &&
179 git commit -q -m "Add and change some files" &&
180 git push gitcvs.git >/dev/null &&
182 GIT_CONFIG="$git_config" cvs -Q update
184 marked_as cvswork textfile.c "" &&
185 marked_as cvswork binfile.bin -kb &&
186 marked_as cvswork .gitattributes "" &&
187 marked_as cvswork mixedUp.c "" &&
188 marked_as cvswork/subdir withCr.bin -kb &&
189 marked_as cvswork/subdir file.h "" &&
190 marked_as cvswork/subdir unspecified.other "" &&
191 marked_as cvswork/subdir newfile.bin -kb &&
192 marked_as cvswork/subdir newfile.c "" &&
193 echo "File with embedded NUL: Q <- there" | q_to_nul > tmpExpect1 &&
194 echo "hello" >> tmpExpect1 &&
195 cmp cvswork/binfile.bin tmpExpect1
199 test_expect_success
'cvs co (use attributes/guess)' '
200 GIT_DIR="$SERVERDIR" git config gitcvs.allbinary guess &&
201 GIT_CONFIG="$git_config" cvs -Q co -d cvswork main >cvs.log 2>&1 &&
202 marked_as cvswork textfile.c "" &&
203 marked_as cvswork binfile.bin -kb &&
204 marked_as cvswork .gitattributes "" &&
205 marked_as cvswork mixedUp.c "" &&
206 marked_as cvswork/subdir withCr.bin -kb &&
207 marked_as cvswork/subdir file.h "" &&
208 marked_as cvswork/subdir unspecified.other "" &&
209 marked_as cvswork/subdir newfile.bin -kb &&
210 marked_as cvswork/subdir newfile.c ""
213 test_expect_success
'setup multi-line files' '
217 echo "line 4 with NUL: Q <-" ) | q_to_nul > multiline.c &&
218 git add multiline.c &&
222 echo "line 4" ) | q_to_nul > multilineTxt.c &&
223 git add multilineTxt.c &&
224 git commit -q -m "multiline files" &&
225 git push gitcvs.git >/dev/null
229 test_expect_success
'cvs co (guess)' '
230 GIT_DIR="$SERVERDIR" git config --bool gitcvs.usecrlfattr false &&
231 GIT_CONFIG="$git_config" cvs -Q co -d cvswork main >cvs.log 2>&1 &&
232 marked_as cvswork textfile.c "" &&
233 marked_as cvswork binfile.bin -kb &&
234 marked_as cvswork .gitattributes "" &&
235 marked_as cvswork mixedUp.c -kb &&
236 marked_as cvswork multiline.c -kb &&
237 marked_as cvswork multilineTxt.c "" &&
238 marked_as cvswork/subdir withCr.bin -kb &&
239 marked_as cvswork/subdir file.h "" &&
240 marked_as cvswork/subdir unspecified.other "" &&
241 marked_as cvswork/subdir newfile.bin "" &&
242 marked_as cvswork/subdir newfile.c ""
245 test_expect_success
'cvs co another copy (guess)' '
246 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
247 marked_as cvswork2 textfile.c "" &&
248 marked_as cvswork2 binfile.bin -kb &&
249 marked_as cvswork2 .gitattributes "" &&
250 marked_as cvswork2 mixedUp.c -kb &&
251 marked_as cvswork2 multiline.c -kb &&
252 marked_as cvswork2 multilineTxt.c "" &&
253 marked_as cvswork2/subdir withCr.bin -kb &&
254 marked_as cvswork2/subdir file.h "" &&
255 marked_as cvswork2/subdir unspecified.other "" &&
256 marked_as cvswork2/subdir newfile.bin "" &&
257 marked_as cvswork2/subdir newfile.c ""
260 test_expect_success
'cvs status - sticky options' '
261 check_status_options cvswork2 textfile.c "" &&
262 check_status_options cvswork2 binfile.bin -kb &&
263 check_status_options cvswork2 .gitattributes "" &&
264 check_status_options cvswork2 mixedUp.c -kb &&
265 check_status_options cvswork2 multiline.c -kb &&
266 check_status_options cvswork2 multilineTxt.c "" &&
267 check_status_options cvswork2/subdir withCr.bin -kb &&
268 check_status_options cvswork2 subdir/withCr.bin -kb &&
269 check_status_options cvswork2/subdir file.h "" &&
270 check_status_options cvswork2 subdir/file.h "" &&
271 check_status_options cvswork2/subdir unspecified.other "" &&
272 check_status_options cvswork2/subdir newfile.bin "" &&
273 check_status_options cvswork2/subdir newfile.c ""
276 test_expect_success
'add text (guess)' '
278 echo "simpleText" > simpleText.c &&
279 GIT_CONFIG="$git_config" cvs -Q add simpleText.c
281 marked_as cvswork simpleText.c ""
284 test_expect_success
'add bin (guess)' '
286 echo "simpleBin: NUL: Q <- there" | q_to_nul > simpleBin.bin &&
287 GIT_CONFIG="$git_config" cvs -Q add simpleBin.bin
289 marked_as cvswork simpleBin.bin -kb
292 test_expect_success
'remove files (guess)' '
294 GIT_CONFIG="$git_config" cvs -Q rm -f subdir/file.h &&
296 GIT_CONFIG="$git_config" cvs -Q rm -f withCr.bin
298 marked_as cvswork/subdir withCr.bin -kb &&
299 marked_as cvswork/subdir file.h ""
302 test_expect_success
'cvs ci (guess)' '
304 GIT_CONFIG="$git_config" cvs -Q ci -m "add/rm files" >cvs.log 2>&1
306 marked_as cvswork textfile.c "" &&
307 marked_as cvswork binfile.bin -kb &&
308 marked_as cvswork .gitattributes "" &&
309 marked_as cvswork mixedUp.c -kb &&
310 marked_as cvswork multiline.c -kb &&
311 marked_as cvswork multilineTxt.c "" &&
312 not_present cvswork/subdir withCr.bin &&
313 not_present cvswork/subdir file.h &&
314 marked_as cvswork/subdir unspecified.other "" &&
315 marked_as cvswork/subdir newfile.bin "" &&
316 marked_as cvswork/subdir newfile.c "" &&
317 marked_as cvswork simpleBin.bin -kb &&
318 marked_as cvswork simpleText.c ""
321 test_expect_success
'update subdir of other copy (guess)' '
322 (cd cvswork2/subdir &&
323 GIT_CONFIG="$git_config" cvs -Q update
325 marked_as cvswork2 textfile.c "" &&
326 marked_as cvswork2 binfile.bin -kb &&
327 marked_as cvswork2 .gitattributes "" &&
328 marked_as cvswork2 mixedUp.c -kb &&
329 marked_as cvswork2 multiline.c -kb &&
330 marked_as cvswork2 multilineTxt.c "" &&
331 not_present cvswork2/subdir withCr.bin &&
332 not_present cvswork2/subdir file.h &&
333 marked_as cvswork2/subdir unspecified.other "" &&
334 marked_as cvswork2/subdir newfile.bin "" &&
335 marked_as cvswork2/subdir newfile.c "" &&
336 not_present cvswork2 simpleBin.bin &&
337 not_present cvswork2 simpleText.c
340 echo "starting update/merge" >> "${WORKDIR}/marked.log"
341 test_expect_success
'update/merge full other copy (guess)' '
342 git pull gitcvs.git main &&
343 sed "s/3/replaced_3/" < multilineTxt.c > ml.temp &&
344 mv ml.temp multilineTxt.c &&
345 git add multilineTxt.c &&
346 git commit -q -m "modify multiline file" >> "${WORKDIR}/marked.log" &&
347 git push gitcvs.git >/dev/null &&
349 sed "s/1/replaced_1/" < multilineTxt.c > ml.temp &&
350 mv ml.temp multilineTxt.c &&
351 GIT_CONFIG="$git_config" cvs update > cvs.log 2>&1
353 marked_as cvswork2 textfile.c "" &&
354 marked_as cvswork2 binfile.bin -kb &&
355 marked_as cvswork2 .gitattributes "" &&
356 marked_as cvswork2 mixedUp.c -kb &&
357 marked_as cvswork2 multiline.c -kb &&
358 marked_as cvswork2 multilineTxt.c "" &&
359 not_present cvswork2/subdir withCr.bin &&
360 not_present cvswork2/subdir file.h &&
361 marked_as cvswork2/subdir unspecified.other "" &&
362 marked_as cvswork2/subdir newfile.bin "" &&
363 marked_as cvswork2/subdir newfile.c "" &&
364 marked_as cvswork2 simpleBin.bin -kb &&
365 marked_as cvswork2 simpleText.c "" &&
366 echo "line replaced_1" > tmpExpect2 &&
367 echo "line 2" >> tmpExpect2 &&
368 echo "line replaced_3" >> tmpExpect2 &&
369 echo "line 4" | q_to_nul >> tmpExpect2 &&
370 cmp cvswork2/multilineTxt.c tmpExpect2