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 git-cvsserver pserver <request-anonymous >log 2>&1 &&
121 sed -ne \$p log | grep "^I LOVE YOU\$"
124 test_expect_success
'pserver authentication failure (non-anonymous user)' '
125 if git-cvsserver pserver <request-git >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 git-cvsserver pserver <login-git-ok >log 2>&1 &&
136 sed -ne \$p log | grep "^I LOVE YOU\$"
139 test_expect_success
'pserver authentication (login)' '
140 git-cvsserver pserver <login-anonymous >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 git-cvsserver pserver <login-git >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 git-cvsserver pserver <request-relative >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 git-cvsserver pserver <request-conflict >log 2>&1 &&
187 tail log | grep "^error 1 Conflicting roots specified$"
190 test_expect_success
'req_Root (strict paths)' '
191 git-cvsserver --strict-paths pserver "$SERVERDIR" <request-anonymous >log 2>&1 &&
192 sed -ne \$p log | grep "^I LOVE YOU\$"
195 test_expect_success
'req_Root failure (strict-paths)' '
196 ! git-cvsserver --strict-paths pserver "$WORKDIR" <request-anonymous >log 2>&1
199 test_expect_success
'req_Root (w/o strict-paths)' '
200 git-cvsserver pserver "$WORKDIR/" <request-anonymous >log 2>&1 &&
201 sed -ne \$p log | grep "^I LOVE YOU\$"
204 test_expect_success
'req_Root failure (w/o strict-paths)' '
205 ! git-cvsserver pserver "$WORKDIR/gitcvs" <request-anonymous >log 2>&1
208 cat >request-base
<<EOF
217 test_expect_success
'req_Root (base-path)' '
218 git-cvsserver --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" <request-base >log 2>&1 &&
219 sed -ne \$p log | grep "^I LOVE YOU\$"
222 test_expect_success
'req_Root failure (base-path)' '
223 ! git-cvsserver --strict-paths --base-path "$WORKDIR" pserver "$SERVERDIR" <request-anonymous >log 2>&1
226 GIT_DIR
="$SERVERDIR" git config
--bool gitcvs.enabled false ||
exit 1
228 test_expect_success
'req_Root (export-all)' '
229 git-cvsserver --export-all pserver "$WORKDIR" <request-anonymous >log 2>&1 &&
230 sed -ne \$p log | grep "^I LOVE YOU\$"
233 test_expect_success
'req_Root failure (export-all w/o directory list)' '
234 ! (git-cvsserver --export-all pserver <request-anonymous >log 2>&1 || false)'
236 test_expect_success
'req_Root (everything together)' '
237 git-cvsserver --export-all --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" <request-base >log 2>&1 &&
238 sed -ne \$p log | grep "^I LOVE YOU\$"
241 GIT_DIR
="$SERVERDIR" git config
--bool gitcvs.enabled true ||
exit 1
247 test_expect_success
'gitcvs.enabled = false' \
248 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
249 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1
251 echo unexpected cvs success
256 grep "GITCVS emulation disabled" cvs.log &&
260 test_expect_success
'gitcvs.ext.enabled = true' '
261 GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
262 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
263 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
264 test_cmp cvswork cvswork2
268 test_expect_success
'gitcvs.ext.enabled = false' '
269 GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
270 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
271 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1
273 echo unexpected cvs success
278 grep "GITCVS emulation disabled" cvs.log &&
283 test_expect_success
'gitcvs.dbname' '
284 GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
285 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
286 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
287 test_cmp cvswork cvswork2 &&
288 test -f "$SERVERDIR/gitcvs.ext.main.sqlite" &&
289 cmp "$SERVERDIR/gitcvs.main.sqlite" "$SERVERDIR/gitcvs.ext.main.sqlite"
293 test_expect_success
'gitcvs.ext.dbname' '
294 GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
295 GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
296 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
297 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
298 test_cmp cvswork cvswork2 &&
299 test -f "$SERVERDIR/gitcvs1.ext.main.sqlite" &&
300 test ! -f "$SERVERDIR/gitcvs2.ext.main.sqlite" &&
301 cmp "$SERVERDIR/gitcvs.main.sqlite" "$SERVERDIR/gitcvs1.ext.main.sqlite"
311 git clone
-q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev
/null
2>&1 &&
312 GIT_DIR
="$SERVERDIR" git config
--bool gitcvs.enabled true
&&
313 GIT_DIR
="$SERVERDIR" git config gitcvs.logfile
"$SERVERDIR/gitcvs.log" ||
316 test_expect_success
'cvs update (create new file)' '
317 echo testfile1 >testfile1 &&
319 git commit -q -m "Add testfile1" &&
320 git push gitcvs.git >/dev/null &&
322 GIT_CONFIG="$git_config" cvs -Q update &&
323 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
324 test_cmp testfile1 ../testfile1
328 test_expect_success
'cvs update (update existing file)' '
329 echo line 2 >>testfile1 &&
331 git commit -q -m "Append to testfile1" &&
332 git push gitcvs.git >/dev/null &&
334 GIT_CONFIG="$git_config" cvs -Q update &&
335 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
336 test_cmp testfile1 ../testfile1
340 #TODO: cvsserver doesn't support update w/o -d
341 test_expect_failure
"cvs update w/o -d doesn't create subdir (TODO)" '
345 git commit -q -m "Single Subdirectory" &&
346 git push gitcvs.git >/dev/null &&
348 GIT_CONFIG="$git_config" cvs -Q update &&
353 test_expect_success
'cvs update (subdirectories)' '
354 (for dir in A A/B A/B/C A/D E; do
356 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
357 git add $dir || exit 1
359 git commit -q -m "deep sub directory structure" &&
360 git push gitcvs.git >/dev/null &&
362 GIT_CONFIG="$git_config" cvs -Q update -d &&
363 (for dir in A A/B A/B/C A/D E; do
364 filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
365 if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
366 test_cmp "$dir/$filename" "../$dir/$filename"; then
375 test_expect_success
'cvs update (delete file)' '
377 git commit -q -m "Remove testfile1" &&
378 git push gitcvs.git >/dev/null &&
380 GIT_CONFIG="$git_config" cvs -Q update &&
381 test -z "$(grep testfile1 CVS/Entries)" &&
386 test_expect_success
'cvs update (re-add deleted file)' '
387 echo readded testfile >testfile1 &&
389 git commit -q -m "Re-Add testfile1" &&
390 git push gitcvs.git >/dev/null &&
392 GIT_CONFIG="$git_config" cvs -Q update &&
393 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
394 test_cmp testfile1 ../testfile1
398 test_expect_success
'cvs update (merge)' '
399 echo Line 0 >expected &&
400 for i in 1 2 3 4 5 6 7
402 echo Line $i >>merge &&
403 echo Line $i >>expected || return 1
405 echo Line 8 >>expected &&
407 git commit -q -m "Merge test (pre-merge)" &&
408 git push gitcvs.git >/dev/null &&
410 GIT_CONFIG="$git_config" cvs -Q update &&
411 test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
412 test_cmp merge ../merge &&
413 ( echo Line 0 && cat merge ) >merge.tmp &&
414 mv merge.tmp merge &&
416 echo Line 8 >>merge &&
418 git commit -q -m "Merge test (merge)" &&
419 git push gitcvs.git >/dev/null &&
421 sleep 1 && touch merge &&
422 GIT_CONFIG="$git_config" cvs -Q update &&
423 test_cmp merge ../expected
428 cat >expected.C
<<EOF
436 for i
in 1 2 3 4 5 6 7 8
438 echo Line
$i >>expected.C
441 test_expect_success
'cvs update (conflict merge)' '
442 ( echo LINE 0 && cat merge ) >merge.tmp &&
443 mv merge.tmp merge &&
445 git commit -q -m "Merge test (conflict)" &&
446 git push gitcvs.git >/dev/null &&
448 GIT_CONFIG="$git_config" cvs -Q update &&
449 test_cmp merge ../expected.C
453 test_expect_success
'cvs update (-C)' '
455 GIT_CONFIG="$git_config" cvs -Q update -C &&
456 test_cmp merge ../merge
460 test_expect_success
'cvs update (merge no-op)' '
461 echo Line 9 >>merge &&
462 cp merge cvswork/merge &&
464 git commit -q -m "Merge test (no-op)" &&
465 git push gitcvs.git >/dev/null &&
467 sleep 1 && touch merge &&
468 GIT_CONFIG="$git_config" cvs -Q update &&
469 test_cmp merge ../merge
473 test_expect_success
'cvs update (-p)' '
474 touch really-empty &&
475 echo Line 1 > no-lf &&
476 printf "Line 2" >> no-lf &&
477 git add really-empty no-lf &&
478 git commit -q -m "Update -p test" &&
479 git push gitcvs.git >/dev/null &&
481 GIT_CONFIG="$git_config" cvs update &&
482 for i in merge no-lf empty really-empty; do
483 GIT_CONFIG="$git_config" cvs update -p "$i" >$i.out &&
484 test_cmp $i.out ../$i || return 1
489 test_expect_success
'cvs update (module list supports packed refs)' '
490 GIT_DIR="$SERVERDIR" git pack-refs --all &&
491 GIT_CONFIG="$git_config" cvs -n up -d 2> out &&
492 grep "cvs update: New directory \`main'\''" < out
500 test_expect_success
'cvs status' '
502 echo Line > status.dir/status.file &&
503 echo Line > status.file &&
504 git add status.dir status.file &&
505 git commit -q -m "Status test" &&
506 git push gitcvs.git >/dev/null &&
508 GIT_CONFIG="$git_config" cvs update &&
509 GIT_CONFIG="$git_config" cvs status | grep "^File: status.file" >../out &&
510 test_line_count = 2 ../out
514 test_expect_success
'cvs status (nonrecursive)' '
516 GIT_CONFIG="$git_config" cvs status -l | grep "^File: status.file" >../out &&
517 test_line_count = 1 ../out
521 test_expect_success
'cvs status (no subdirs in header)' '
523 GIT_CONFIG="$git_config" cvs status | grep ^File: >../out &&
532 test_expect_success
'cvs co -c (shows module database)' '
533 GIT_CONFIG="$git_config" cvs co -c > out &&
534 grep "^main[ ][ ]*main$" <out &&
535 ! grep -v "^main[ ][ ]*main$" <out
542 # Known issues with git-cvsserver current log output:
543 # - Hard coded "lines: +2 -3" placeholder, instead of real numbers.
544 # - CVS normally does not internally add a blank first line
545 # or a last line with nothing but a space to log messages.
546 # - The latest cvs 1.12.x server sends +0000 timezone (with some hidden "MT"
547 # tagging in the protocol), and if cvs 1.12.x client sees the MT tags,
548 # it converts to local time zone. git-cvsserver doesn't do the +0000
550 # - The latest 1.12.x releases add a "commitid:" field on to the end of the
551 # "date:" line (after "lines:"). Maybe we could stick git's commit id
552 # in it? Or does CVS expect a certain number of bits (too few for
555 # Given the above, expect the following test to break if git-cvsserver's
556 # log output is improved. The test is just to ensure it doesn't
557 # accidentally get worse.
559 sed -e 's/^x//' -e 's/SP$/ /' > "$WORKDIR/expect" <<EOF
561 xRCS file: $WORKDIR/gitcvs.git/main/merge,v
568 xkeyword substitution: kv
569 xtotal revisions: 4; selected revisions: 4
571 x----------------------------
573 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
577 x----------------------------
579 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
581 xMerge test (conflict)
583 x----------------------------
585 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
589 x----------------------------
591 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
593 xMerge test (pre-merge)
595 x=============================================================================
600 test_expect_success
'cvs log' '
602 test x"$expectStat" = x"0" &&
603 GIT_CONFIG="$git_config" cvs log merge >../out &&
604 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 &&
605 test_cmp ../expect ../actual
613 test_expect_success
'cvs annotate' '
615 GIT_CONFIG="$git_config" cvs annotate merge >../out &&
616 sed -e "s/ .*//" ../out >../actual &&
617 printf "1.%d\n" 3 1 1 1 1 1 1 1 2 4 >../expect &&
618 test_cmp ../expect ../actual
622 # running via git-shell
627 test_expect_success
'create remote-cvs helper' '
628 write_script remote-cvs <<-\EOF
629 exec git shell -c "cvs server"
633 test_expect_success
'cvs server does not run with vanilla git-shell' '
636 CVS_SERVER=$WORKDIR/remote-cvs &&
642 test_expect_success
'configure git shell to run cvs server' '
643 mkdir "$HOME"/git-shell-commands &&
645 write_script "$HOME"/git-shell-commands/cvs <<-\EOF &&
646 if ! test $# = 1 && test "$1" = "server"
648 echo >&2 "git-cvsserver only handles \"server\""
651 exec git cvsserver server
654 # Should not be used, but part of the recommended setup
655 write_script "$HOME"/git-shell-commands/no-interactive-login <<-\EOF
656 echo Interactive login forbidden
660 test_expect_success
'cvs server can run with recommended config' '
663 CVS_SERVER=$WORKDIR/remote-cvs &&