3 # Copyright (c) 2007 Frank Lichtenheld
6 test_description
='git-cvsserver access
8 tests read access to a git repository with the
9 cvs CLI client via git-cvsserver server'
11 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
12 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
16 if ! test_have_prereq PERL
; then
17 skip_all
='skipping git cvsserver tests, perl not available'
23 skip_all
='skipping git-cvsserver tests, cvs not found'
26 perl
-e 'use DBI; use DBD::SQLite' >/dev
/null
2>&1 ||
{
27 skip_all
='skipping git-cvsserver tests, Perl SQLite interface unavailable'
32 SERVERDIR
=$PWD/gitcvs.git
33 git_config
="$SERVERDIR/config"
34 CVSROOT
=":fork:$SERVERDIR"
35 CVSWORK
="$PWD/cvswork"
36 CVS_SERVER
=git-cvsserver
37 export CVSROOT CVS_SERVER
39 if perl
-e 'exit(1) if not defined crypt("", "cv")'
41 PWDHASH
='lac2ItudM3.KM'
43 PWDHASH
='$2b$10$t8fGvE/a9eLmfOLzsZme2uOa2QtoMYwIxq9wZA6aBKtF1Yb7FJIzi'
46 rm -rf "$CVSWORK" "$SERVERDIR"
47 test_expect_success
'setup' '
48 git config push.default matching &&
51 git commit -q -m "First Commit" &&
55 touch secondrootfile &&
56 git add secondrootfile &&
57 git commit -m "second root") &&
58 git fetch secondroot main &&
59 git merge --allow-unrelated-histories FETCH_HEAD &&
60 git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
61 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
62 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" &&
63 GIT_DIR="$SERVERDIR" git config gitcvs.authdb "$SERVERDIR/auth.db" &&
64 echo "cvsuser:$PWDHASH" >"$SERVERDIR/auth.db"
67 # note that cvs doesn't accept absolute pathnames
68 # as argument to co -d
69 test_expect_success
'basic checkout' '
70 GIT_CONFIG="$git_config" cvs -Q co -d cvswork main &&
71 test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | head -n 1))" = "empty/1.1/" &&
72 test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | sed -ne \$p))" = "secondrootfile/1.1/"
75 #------------------------
76 # PSERVER AUTHENTICATION
77 #------------------------
79 cat >request-anonymous
<<EOF
87 cat >request-git
<<EOF
95 cat >login-anonymous
<<EOF
96 BEGIN VERIFICATION REQUEST
100 END VERIFICATION REQUEST
104 BEGIN VERIFICATION REQUEST
108 END VERIFICATION REQUEST
111 cat >login-git-ok
<<EOF
112 BEGIN VERIFICATION REQUEST
116 END VERIFICATION REQUEST
119 test_expect_success
'pserver authentication' '
120 cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
121 sed -ne \$p log | grep "^I LOVE YOU\$"
124 test_expect_success
'pserver authentication failure (non-anonymous user)' '
125 if cat request-git | git-cvsserver pserver >log 2>&1
131 sed -ne \$p log | grep "^I HATE YOU\$"
134 test_expect_success
'pserver authentication success (non-anonymous user with password)' '
135 cat login-git-ok | git-cvsserver pserver >log 2>&1 &&
136 sed -ne \$p log | grep "^I LOVE YOU\$"
139 test_expect_success
'pserver authentication (login)' '
140 cat login-anonymous | git-cvsserver pserver >log 2>&1 &&
141 sed -ne \$p log | grep "^I LOVE YOU\$"
144 test_expect_success
'pserver authentication failure (login/non-anonymous user)' '
145 if cat login-git | git-cvsserver pserver >log 2>&1
151 sed -ne \$p log | grep "^I HATE YOU\$"
155 # misuse pserver authentication for testing of req_Root
157 cat >request-relative
<<EOF
165 cat >request-conflict
<<EOF
174 test_expect_success
'req_Root failure (relative pathname)' '
175 if cat request-relative | git-cvsserver pserver >log 2>&1
177 echo unexpected success
182 tail log | grep "^error 1 Root must be an absolute pathname$"
185 test_expect_success
'req_Root failure (conflicting roots)' '
186 cat request-conflict | git-cvsserver pserver >log 2>&1 &&
187 tail log | grep "^error 1 Conflicting roots specified$"
190 test_expect_success
'req_Root (strict paths)' '
191 cat request-anonymous | git-cvsserver --strict-paths pserver "$SERVERDIR" >log 2>&1 &&
192 sed -ne \$p log | grep "^I LOVE YOU\$"
195 test_expect_success
'req_Root failure (strict-paths)' '
196 ! cat request-anonymous |
197 git-cvsserver --strict-paths pserver "$WORKDIR" >log 2>&1
200 test_expect_success
'req_Root (w/o strict-paths)' '
201 cat request-anonymous | git-cvsserver pserver "$WORKDIR/" >log 2>&1 &&
202 sed -ne \$p log | grep "^I LOVE YOU\$"
205 test_expect_success
'req_Root failure (w/o strict-paths)' '
206 ! cat request-anonymous |
207 git-cvsserver pserver "$WORKDIR/gitcvs" >log 2>&1
210 cat >request-base
<<EOF
219 test_expect_success
'req_Root (base-path)' '
220 cat request-base | git-cvsserver --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
221 sed -ne \$p log | grep "^I LOVE YOU\$"
224 test_expect_success
'req_Root failure (base-path)' '
225 ! cat request-anonymous |
226 git-cvsserver --strict-paths --base-path "$WORKDIR" pserver "$SERVERDIR" >log 2>&1
229 GIT_DIR
="$SERVERDIR" git config
--bool gitcvs.enabled false ||
exit 1
231 test_expect_success
'req_Root (export-all)' '
232 cat request-anonymous | git-cvsserver --export-all pserver "$WORKDIR" >log 2>&1 &&
233 sed -ne \$p log | grep "^I LOVE YOU\$"
236 test_expect_success
'req_Root failure (export-all w/o directory list)' '
237 ! (cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 || false)'
239 test_expect_success
'req_Root (everything together)' '
240 cat request-base | git-cvsserver --export-all --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
241 sed -ne \$p log | grep "^I LOVE YOU\$"
244 GIT_DIR
="$SERVERDIR" git config
--bool gitcvs.enabled true ||
exit 1
250 test_expect_success
'gitcvs.enabled = false' \
251 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
252 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1
254 echo unexpected cvs success
259 grep "GITCVS emulation disabled" cvs.log &&
263 test_expect_success
'gitcvs.ext.enabled = true' '
264 GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
265 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
266 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
267 test_cmp cvswork cvswork2
271 test_expect_success
'gitcvs.ext.enabled = false' '
272 GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
273 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
274 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1
276 echo unexpected cvs success
281 grep "GITCVS emulation disabled" cvs.log &&
286 test_expect_success
'gitcvs.dbname' '
287 GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
288 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
289 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
290 test_cmp cvswork cvswork2 &&
291 test -f "$SERVERDIR/gitcvs.ext.main.sqlite" &&
292 cmp "$SERVERDIR/gitcvs.main.sqlite" "$SERVERDIR/gitcvs.ext.main.sqlite"
296 test_expect_success
'gitcvs.ext.dbname' '
297 GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
298 GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
299 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
300 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
301 test_cmp cvswork cvswork2 &&
302 test -f "$SERVERDIR/gitcvs1.ext.main.sqlite" &&
303 test ! -f "$SERVERDIR/gitcvs2.ext.main.sqlite" &&
304 cmp "$SERVERDIR/gitcvs.main.sqlite" "$SERVERDIR/gitcvs1.ext.main.sqlite"
314 git clone
-q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev
/null
2>&1 &&
315 GIT_DIR
="$SERVERDIR" git config
--bool gitcvs.enabled true
&&
316 GIT_DIR
="$SERVERDIR" git config gitcvs.logfile
"$SERVERDIR/gitcvs.log" ||
319 test_expect_success
'cvs update (create new file)' '
320 echo testfile1 >testfile1 &&
322 git commit -q -m "Add testfile1" &&
323 git push gitcvs.git >/dev/null &&
325 GIT_CONFIG="$git_config" cvs -Q update &&
326 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
327 test_cmp testfile1 ../testfile1
331 test_expect_success
'cvs update (update existing file)' '
332 echo line 2 >>testfile1 &&
334 git commit -q -m "Append to testfile1" &&
335 git push gitcvs.git >/dev/null &&
337 GIT_CONFIG="$git_config" cvs -Q update &&
338 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
339 test_cmp testfile1 ../testfile1
343 #TODO: cvsserver doesn't support update w/o -d
344 test_expect_failure
"cvs update w/o -d doesn't create subdir (TODO)" '
348 git commit -q -m "Single Subdirectory" &&
349 git push gitcvs.git >/dev/null &&
351 GIT_CONFIG="$git_config" cvs -Q update &&
356 test_expect_success
'cvs update (subdirectories)' '
357 (for dir in A A/B A/B/C A/D E; do
359 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
360 git add $dir || exit 1
362 git commit -q -m "deep sub directory structure" &&
363 git push gitcvs.git >/dev/null &&
365 GIT_CONFIG="$git_config" cvs -Q update -d &&
366 (for dir in A A/B A/B/C A/D E; do
367 filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
368 if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
369 test_cmp "$dir/$filename" "../$dir/$filename"; then
378 test_expect_success
'cvs update (delete file)' '
380 git commit -q -m "Remove testfile1" &&
381 git push gitcvs.git >/dev/null &&
383 GIT_CONFIG="$git_config" cvs -Q update &&
384 test -z "$(grep testfile1 CVS/Entries)" &&
389 test_expect_success
'cvs update (re-add deleted file)' '
390 echo readded testfile >testfile1 &&
392 git commit -q -m "Re-Add testfile1" &&
393 git push gitcvs.git >/dev/null &&
395 GIT_CONFIG="$git_config" cvs -Q update &&
396 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
397 test_cmp testfile1 ../testfile1
401 test_expect_success
'cvs update (merge)' '
402 echo Line 0 >expected &&
403 for i in 1 2 3 4 5 6 7
405 echo Line $i >>merge &&
406 echo Line $i >>expected || return 1
408 echo Line 8 >>expected &&
410 git commit -q -m "Merge test (pre-merge)" &&
411 git push gitcvs.git >/dev/null &&
413 GIT_CONFIG="$git_config" cvs -Q update &&
414 test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
415 test_cmp merge ../merge &&
416 ( echo Line 0 && cat merge ) >merge.tmp &&
417 mv merge.tmp merge &&
419 echo Line 8 >>merge &&
421 git commit -q -m "Merge test (merge)" &&
422 git push gitcvs.git >/dev/null &&
424 sleep 1 && touch merge &&
425 GIT_CONFIG="$git_config" cvs -Q update &&
426 test_cmp merge ../expected
431 cat >expected.C
<<EOF
439 for i
in 1 2 3 4 5 6 7 8
441 echo Line
$i >>expected.C
444 test_expect_success
'cvs update (conflict merge)' '
445 ( echo LINE 0 && cat merge ) >merge.tmp &&
446 mv merge.tmp merge &&
448 git commit -q -m "Merge test (conflict)" &&
449 git push gitcvs.git >/dev/null &&
451 GIT_CONFIG="$git_config" cvs -Q update &&
452 test_cmp merge ../expected.C
456 test_expect_success
'cvs update (-C)' '
458 GIT_CONFIG="$git_config" cvs -Q update -C &&
459 test_cmp merge ../merge
463 test_expect_success
'cvs update (merge no-op)' '
464 echo Line 9 >>merge &&
465 cp merge cvswork/merge &&
467 git commit -q -m "Merge test (no-op)" &&
468 git push gitcvs.git >/dev/null &&
470 sleep 1 && touch merge &&
471 GIT_CONFIG="$git_config" cvs -Q update &&
472 test_cmp merge ../merge
476 test_expect_success
'cvs update (-p)' '
477 touch really-empty &&
478 echo Line 1 > no-lf &&
479 printf "Line 2" >> no-lf &&
480 git add really-empty no-lf &&
481 git commit -q -m "Update -p test" &&
482 git push gitcvs.git >/dev/null &&
484 GIT_CONFIG="$git_config" cvs update &&
485 for i in merge no-lf empty really-empty; do
486 GIT_CONFIG="$git_config" cvs update -p "$i" >$i.out &&
487 test_cmp $i.out ../$i || return 1
492 test_expect_success
'cvs update (module list supports packed refs)' '
493 GIT_DIR="$SERVERDIR" git pack-refs --all &&
494 GIT_CONFIG="$git_config" cvs -n up -d 2> out &&
495 grep "cvs update: New directory \`main'\''" < out
503 test_expect_success
'cvs status' '
505 echo Line > status.dir/status.file &&
506 echo Line > status.file &&
507 git add status.dir status.file &&
508 git commit -q -m "Status test" &&
509 git push gitcvs.git >/dev/null &&
511 GIT_CONFIG="$git_config" cvs update &&
512 GIT_CONFIG="$git_config" cvs status | grep "^File: status.file" >../out &&
513 test_line_count = 2 ../out
517 test_expect_success
'cvs status (nonrecursive)' '
519 GIT_CONFIG="$git_config" cvs status -l | grep "^File: status.file" >../out &&
520 test_line_count = 1 ../out
524 test_expect_success
'cvs status (no subdirs in header)' '
526 GIT_CONFIG="$git_config" cvs status | grep ^File: >../out &&
535 test_expect_success
'cvs co -c (shows module database)' '
536 GIT_CONFIG="$git_config" cvs co -c > out &&
537 grep "^main[ ][ ]*main$" <out &&
538 ! grep -v "^main[ ][ ]*main$" <out
545 # Known issues with git-cvsserver current log output:
546 # - Hard coded "lines: +2 -3" placeholder, instead of real numbers.
547 # - CVS normally does not internally add a blank first line
548 # or a last line with nothing but a space to log messages.
549 # - The latest cvs 1.12.x server sends +0000 timezone (with some hidden "MT"
550 # tagging in the protocol), and if cvs 1.12.x client sees the MT tags,
551 # it converts to local time zone. git-cvsserver doesn't do the +0000
553 # - The latest 1.12.x releases add a "commitid:" field on to the end of the
554 # "date:" line (after "lines:"). Maybe we could stick git's commit id
555 # in it? Or does CVS expect a certain number of bits (too few for
558 # Given the above, expect the following test to break if git-cvsserver's
559 # log output is improved. The test is just to ensure it doesn't
560 # accidentally get worse.
562 sed -e 's/^x//' -e 's/SP$/ /' > "$WORKDIR/expect" <<EOF
564 xRCS file: $WORKDIR/gitcvs.git/main/merge,v
571 xkeyword substitution: kv
572 xtotal revisions: 4; selected revisions: 4
574 x----------------------------
576 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
580 x----------------------------
582 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
584 xMerge test (conflict)
586 x----------------------------
588 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
592 x----------------------------
594 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
596 xMerge test (pre-merge)
598 x=============================================================================
603 test_expect_success
'cvs log' '
605 test x"$expectStat" = x"0" &&
606 GIT_CONFIG="$git_config" cvs log merge >../out &&
607 sed -e "s%2[0-9][0-9][0-9]/[01][0-9]/[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]%__DATE__%" ../out > ../actual &&
608 test_cmp ../expect ../actual
616 test_expect_success
'cvs annotate' '
618 GIT_CONFIG="$git_config" cvs annotate merge >../out &&
619 sed -e "s/ .*//" ../out >../actual &&
620 printf "1.%d\n" 3 1 1 1 1 1 1 1 2 4 >../expect &&
621 test_cmp ../expect ../actual
625 # running via git-shell
630 test_expect_success
'create remote-cvs helper' '
631 write_script remote-cvs <<-\EOF
632 exec git shell -c "cvs server"
636 test_expect_success
'cvs server does not run with vanilla git-shell' '
639 CVS_SERVER=$WORKDIR/remote-cvs &&
645 test_expect_success
'configure git shell to run cvs server' '
646 mkdir "$HOME"/git-shell-commands &&
648 write_script "$HOME"/git-shell-commands/cvs <<-\EOF &&
649 if ! test $# = 1 && test "$1" = "server"
651 echo >&2 "git-cvsserver only handles \"server\""
654 exec git cvsserver server
657 # Should not be used, but part of the recommended setup
658 write_script "$HOME"/git-shell-commands/no-interactive-login <<-\EOF
659 echo Interactive login forbidden
663 test_expect_success
'cvs server can run with recommended config' '
666 CVS_SERVER=$WORKDIR/remote-cvs &&