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/"'
74 #------------------------
75 # PSERVER AUTHENTICATION
76 #------------------------
78 cat >request-anonymous
<<EOF
86 cat >request-git
<<EOF
94 cat >login-anonymous
<<EOF
95 BEGIN VERIFICATION REQUEST
99 END VERIFICATION REQUEST
103 BEGIN VERIFICATION REQUEST
107 END VERIFICATION REQUEST
110 cat >login-git-ok
<<EOF
111 BEGIN VERIFICATION REQUEST
115 END VERIFICATION REQUEST
118 test_expect_success
'pserver authentication' \
119 'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
120 sed -ne \$p log | grep "^I LOVE YOU\$"'
122 test_expect_success
'pserver authentication failure (non-anonymous user)' \
123 'if cat request-git | git-cvsserver pserver >log 2>&1
129 sed -ne \$p log | grep "^I HATE YOU\$"'
131 test_expect_success
'pserver authentication success (non-anonymous user with password)' \
132 'cat login-git-ok | git-cvsserver pserver >log 2>&1 &&
133 sed -ne \$p log | grep "^I LOVE YOU\$"'
135 test_expect_success
'pserver authentication (login)' \
136 'cat login-anonymous | git-cvsserver pserver >log 2>&1 &&
137 sed -ne \$p log | grep "^I LOVE YOU\$"'
139 test_expect_success
'pserver authentication failure (login/non-anonymous user)' \
140 'if cat login-git | git-cvsserver pserver >log 2>&1
146 sed -ne \$p log | grep "^I HATE YOU\$"'
149 # misuse pserver authentication for testing of req_Root
151 cat >request-relative
<<EOF
159 cat >request-conflict
<<EOF
168 test_expect_success
'req_Root failure (relative pathname)' \
169 'if cat request-relative | git-cvsserver pserver >log 2>&1
171 echo unexpected success
176 tail log | grep "^error 1 Root must be an absolute pathname$"'
178 test_expect_success
'req_Root failure (conflicting roots)' \
179 'cat request-conflict | git-cvsserver pserver >log 2>&1 &&
180 tail log | grep "^error 1 Conflicting roots specified$"'
182 test_expect_success
'req_Root (strict paths)' \
183 'cat request-anonymous | git-cvsserver --strict-paths pserver "$SERVERDIR" >log 2>&1 &&
184 sed -ne \$p log | grep "^I LOVE YOU\$"'
186 test_expect_success
'req_Root failure (strict-paths)' '
187 ! cat request-anonymous |
188 git-cvsserver --strict-paths pserver "$WORKDIR" >log 2>&1
191 test_expect_success
'req_Root (w/o strict-paths)' \
192 'cat request-anonymous | git-cvsserver pserver "$WORKDIR/" >log 2>&1 &&
193 sed -ne \$p log | grep "^I LOVE YOU\$"'
195 test_expect_success
'req_Root failure (w/o strict-paths)' '
196 ! cat request-anonymous |
197 git-cvsserver pserver "$WORKDIR/gitcvs" >log 2>&1
200 cat >request-base
<<EOF
209 test_expect_success
'req_Root (base-path)' \
210 'cat request-base | git-cvsserver --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
211 sed -ne \$p log | grep "^I LOVE YOU\$"'
213 test_expect_success
'req_Root failure (base-path)' '
214 ! cat request-anonymous |
215 git-cvsserver --strict-paths --base-path "$WORKDIR" pserver "$SERVERDIR" >log 2>&1
218 GIT_DIR
="$SERVERDIR" git config
--bool gitcvs.enabled false ||
exit 1
220 test_expect_success
'req_Root (export-all)' \
221 'cat request-anonymous | git-cvsserver --export-all pserver "$WORKDIR" >log 2>&1 &&
222 sed -ne \$p log | grep "^I LOVE YOU\$"'
224 test_expect_success
'req_Root failure (export-all w/o whitelist)' \
225 '! (cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 || false)'
227 test_expect_success
'req_Root (everything together)' \
228 'cat request-base | git-cvsserver --export-all --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
229 sed -ne \$p log | grep "^I LOVE YOU\$"'
231 GIT_DIR
="$SERVERDIR" git config
--bool gitcvs.enabled true ||
exit 1
237 test_expect_success
'gitcvs.enabled = false' \
238 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
239 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1
241 echo unexpected cvs success
246 grep "GITCVS emulation disabled" cvs.log &&
250 test_expect_success
'gitcvs.ext.enabled = true' \
251 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
252 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
253 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
254 test_cmp cvswork cvswork2'
257 test_expect_success
'gitcvs.ext.enabled = false' \
258 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
259 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
260 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1
262 echo unexpected cvs success
267 grep "GITCVS emulation disabled" cvs.log &&
271 test_expect_success
'gitcvs.dbname' \
272 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
273 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
274 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
275 test_cmp cvswork cvswork2 &&
276 test -f "$SERVERDIR/gitcvs.ext.main.sqlite" &&
277 cmp "$SERVERDIR/gitcvs.main.sqlite" "$SERVERDIR/gitcvs.ext.main.sqlite"'
280 test_expect_success
'gitcvs.ext.dbname' \
281 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
282 GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
283 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
284 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
285 test_cmp cvswork cvswork2 &&
286 test -f "$SERVERDIR/gitcvs1.ext.main.sqlite" &&
287 test ! -f "$SERVERDIR/gitcvs2.ext.main.sqlite" &&
288 cmp "$SERVERDIR/gitcvs.main.sqlite" "$SERVERDIR/gitcvs1.ext.main.sqlite"'
297 git clone
-q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev
/null
2>&1 &&
298 GIT_DIR
="$SERVERDIR" git config
--bool gitcvs.enabled true
&&
299 GIT_DIR
="$SERVERDIR" git config gitcvs.logfile
"$SERVERDIR/gitcvs.log" ||
302 test_expect_success
'cvs update (create new file)' \
303 'echo testfile1 >testfile1 &&
305 git commit -q -m "Add testfile1" &&
306 git push gitcvs.git >/dev/null &&
308 GIT_CONFIG="$git_config" cvs -Q update &&
309 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
310 test_cmp testfile1 ../testfile1'
313 test_expect_success
'cvs update (update existing file)' \
314 'echo line 2 >>testfile1 &&
316 git commit -q -m "Append to testfile1" &&
317 git push gitcvs.git >/dev/null &&
319 GIT_CONFIG="$git_config" cvs -Q update &&
320 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
321 test_cmp testfile1 ../testfile1'
324 #TODO: cvsserver doesn't support update w/o -d
325 test_expect_failure
"cvs update w/o -d doesn't create subdir (TODO)" '
329 git commit -q -m "Single Subdirectory" &&
330 git push gitcvs.git >/dev/null &&
332 GIT_CONFIG="$git_config" cvs -Q update &&
337 test_expect_success
'cvs update (subdirectories)' \
338 '(for dir in A A/B A/B/C A/D E; do
340 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
341 git add $dir || exit 1
343 git commit -q -m "deep sub directory structure" &&
344 git push gitcvs.git >/dev/null &&
346 GIT_CONFIG="$git_config" cvs -Q update -d &&
347 (for dir in A A/B A/B/C A/D E; do
348 filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
349 if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
350 test_cmp "$dir/$filename" "../$dir/$filename"; then
358 test_expect_success
'cvs update (delete file)' \
360 git commit -q -m "Remove testfile1" &&
361 git push gitcvs.git >/dev/null &&
363 GIT_CONFIG="$git_config" cvs -Q update &&
364 test -z "$(grep testfile1 CVS/Entries)" &&
368 test_expect_success
'cvs update (re-add deleted file)' \
369 'echo readded testfile >testfile1 &&
371 git commit -q -m "Re-Add testfile1" &&
372 git push gitcvs.git >/dev/null &&
374 GIT_CONFIG="$git_config" cvs -Q update &&
375 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
376 test_cmp testfile1 ../testfile1'
379 test_expect_success
'cvs update (merge)' \
380 'echo Line 0 >expected &&
381 for i in 1 2 3 4 5 6 7
383 echo Line $i >>merge &&
384 echo Line $i >>expected || return 1
386 echo Line 8 >>expected &&
388 git commit -q -m "Merge test (pre-merge)" &&
389 git push gitcvs.git >/dev/null &&
391 GIT_CONFIG="$git_config" cvs -Q update &&
392 test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
393 test_cmp merge ../merge &&
394 ( echo Line 0 && cat merge ) >merge.tmp &&
395 mv merge.tmp merge &&
397 echo Line 8 >>merge &&
399 git commit -q -m "Merge test (merge)" &&
400 git push gitcvs.git >/dev/null &&
402 sleep 1 && touch merge &&
403 GIT_CONFIG="$git_config" cvs -Q update &&
404 test_cmp merge ../expected'
408 cat >expected.C
<<EOF
416 for i
in 1 2 3 4 5 6 7 8
418 echo Line
$i >>expected.C
421 test_expect_success
'cvs update (conflict merge)' \
422 '( echo LINE 0 && cat merge ) >merge.tmp &&
423 mv merge.tmp merge &&
425 git commit -q -m "Merge test (conflict)" &&
426 git push gitcvs.git >/dev/null &&
428 GIT_CONFIG="$git_config" cvs -Q update &&
429 test_cmp merge ../expected.C'
432 test_expect_success
'cvs update (-C)' \
434 GIT_CONFIG="$git_config" cvs -Q update -C &&
435 test_cmp merge ../merge'
438 test_expect_success
'cvs update (merge no-op)' \
439 'echo Line 9 >>merge &&
440 cp merge cvswork/merge &&
442 git commit -q -m "Merge test (no-op)" &&
443 git push gitcvs.git >/dev/null &&
445 sleep 1 && touch merge &&
446 GIT_CONFIG="$git_config" cvs -Q update &&
447 test_cmp merge ../merge'
450 test_expect_success
'cvs update (-p)' '
451 touch really-empty &&
452 echo Line 1 > no-lf &&
453 printf "Line 2" >> no-lf &&
454 git add really-empty no-lf &&
455 git commit -q -m "Update -p test" &&
456 git push gitcvs.git >/dev/null &&
458 GIT_CONFIG="$git_config" cvs update &&
459 for i in merge no-lf empty really-empty; do
460 GIT_CONFIG="$git_config" cvs update -p "$i" >$i.out &&
461 test_cmp $i.out ../$i || return 1
466 test_expect_success
'cvs update (module list supports packed refs)' '
467 GIT_DIR="$SERVERDIR" git pack-refs --all &&
468 GIT_CONFIG="$git_config" cvs -n up -d 2> out &&
469 grep "cvs update: New directory \`main'\''" < out
477 test_expect_success
'cvs status' '
479 echo Line > status.dir/status.file &&
480 echo Line > status.file &&
481 git add status.dir status.file &&
482 git commit -q -m "Status test" &&
483 git push gitcvs.git >/dev/null &&
485 GIT_CONFIG="$git_config" cvs update &&
486 GIT_CONFIG="$git_config" cvs status | grep "^File: status.file" >../out &&
487 test_line_count = 2 ../out
491 test_expect_success
'cvs status (nonrecursive)' '
493 GIT_CONFIG="$git_config" cvs status -l | grep "^File: status.file" >../out &&
494 test_line_count = 1 ../out
498 test_expect_success
'cvs status (no subdirs in header)' '
500 GIT_CONFIG="$git_config" cvs status | grep ^File: >../out &&
509 test_expect_success
'cvs co -c (shows module database)' '
510 GIT_CONFIG="$git_config" cvs co -c > out &&
511 grep "^main[ ][ ]*main$" <out &&
512 ! grep -v "^main[ ][ ]*main$" <out
519 # Known issues with git-cvsserver current log output:
520 # - Hard coded "lines: +2 -3" placeholder, instead of real numbers.
521 # - CVS normally does not internally add a blank first line
522 # or a last line with nothing but a space to log messages.
523 # - The latest cvs 1.12.x server sends +0000 timezone (with some hidden "MT"
524 # tagging in the protocol), and if cvs 1.12.x client sees the MT tags,
525 # it converts to local time zone. git-cvsserver doesn't do the +0000
527 # - The latest 1.12.x releases add a "commitid:" field on to the end of the
528 # "date:" line (after "lines:"). Maybe we could stick git's commit id
529 # in it? Or does CVS expect a certain number of bits (too few for
532 # Given the above, expect the following test to break if git-cvsserver's
533 # log output is improved. The test is just to ensure it doesn't
534 # accidentally get worse.
536 sed -e 's/^x//' -e 's/SP$/ /' > "$WORKDIR/expect" <<EOF
538 xRCS file: $WORKDIR/gitcvs.git/main/merge,v
545 xkeyword substitution: kv
546 xtotal revisions: 4; selected revisions: 4
548 x----------------------------
550 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
554 x----------------------------
556 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
558 xMerge test (conflict)
560 x----------------------------
562 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
566 x----------------------------
568 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
570 xMerge test (pre-merge)
572 x=============================================================================
577 test_expect_success
'cvs log' '
579 test x"$expectStat" = x"0" &&
580 GIT_CONFIG="$git_config" cvs log merge >../out &&
581 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 &&
582 test_cmp ../expect ../actual
590 test_expect_success
'cvs annotate' '
592 GIT_CONFIG="$git_config" cvs annotate merge >../out &&
593 sed -e "s/ .*//" ../out >../actual &&
594 printf "1.%d\n" 3 1 1 1 1 1 1 1 2 4 >../expect &&
595 test_cmp ../expect ../actual
599 # running via git-shell
604 test_expect_success
'create remote-cvs helper' '
605 write_script remote-cvs <<-\EOF
606 exec git shell -c "cvs server"
610 test_expect_success
'cvs server does not run with vanilla git-shell' '
613 CVS_SERVER=$WORKDIR/remote-cvs &&
619 test_expect_success
'configure git shell to run cvs server' '
620 mkdir "$HOME"/git-shell-commands &&
622 write_script "$HOME"/git-shell-commands/cvs <<-\EOF &&
623 if ! test $# = 1 && test "$1" = "server"
625 echo >&2 "git-cvsserver only handles \"server\""
628 exec git cvsserver server
631 # Should not be used, but part of the recommended setup
632 write_script "$HOME"/git-shell-commands/no-interactive-login <<-\EOF
633 echo Interactive login forbidden
637 test_expect_success
'cvs server can run with recommended config' '
640 CVS_SERVER=$WORKDIR/remote-cvs &&