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")" &&
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
359 test_expect_success
'cvs update (delete file)' \
361 git commit -q -m "Remove testfile1" &&
362 git push gitcvs.git >/dev/null &&
364 GIT_CONFIG="$git_config" cvs -Q update &&
365 test -z "$(grep testfile1 CVS/Entries)" &&
369 test_expect_success
'cvs update (re-add deleted file)' \
370 'echo readded testfile >testfile1 &&
372 git commit -q -m "Re-Add testfile1" &&
373 git push gitcvs.git >/dev/null &&
375 GIT_CONFIG="$git_config" cvs -Q update &&
376 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
377 test_cmp testfile1 ../testfile1'
380 test_expect_success
'cvs update (merge)' \
381 'echo Line 0 >expected &&
382 for i in 1 2 3 4 5 6 7
384 echo Line $i >>merge &&
385 echo Line $i >>expected
387 echo Line 8 >>expected &&
389 git commit -q -m "Merge test (pre-merge)" &&
390 git push gitcvs.git >/dev/null &&
392 GIT_CONFIG="$git_config" cvs -Q update &&
393 test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
394 test_cmp merge ../merge &&
395 ( echo Line 0 && cat merge ) >merge.tmp &&
396 mv merge.tmp merge &&
398 echo Line 8 >>merge &&
400 git commit -q -m "Merge test (merge)" &&
401 git push gitcvs.git >/dev/null &&
403 sleep 1 && touch merge &&
404 GIT_CONFIG="$git_config" cvs -Q update &&
405 test_cmp merge ../expected'
409 cat >expected.C
<<EOF
417 for i
in 1 2 3 4 5 6 7 8
419 echo Line
$i >>expected.C
422 test_expect_success
'cvs update (conflict merge)' \
423 '( echo LINE 0 && cat merge ) >merge.tmp &&
424 mv merge.tmp merge &&
426 git commit -q -m "Merge test (conflict)" &&
427 git push gitcvs.git >/dev/null &&
429 GIT_CONFIG="$git_config" cvs -Q update &&
430 test_cmp merge ../expected.C'
433 test_expect_success
'cvs update (-C)' \
435 GIT_CONFIG="$git_config" cvs -Q update -C &&
436 test_cmp merge ../merge'
439 test_expect_success
'cvs update (merge no-op)' \
440 'echo Line 9 >>merge &&
441 cp merge cvswork/merge &&
443 git commit -q -m "Merge test (no-op)" &&
444 git push gitcvs.git >/dev/null &&
446 sleep 1 && touch merge &&
447 GIT_CONFIG="$git_config" cvs -Q update &&
448 test_cmp merge ../merge'
451 test_expect_success
'cvs update (-p)' '
452 touch really-empty &&
453 echo Line 1 > no-lf &&
454 printf "Line 2" >> no-lf &&
455 git add really-empty no-lf &&
456 git commit -q -m "Update -p test" &&
457 git push gitcvs.git >/dev/null &&
459 GIT_CONFIG="$git_config" cvs update &&
460 for i in merge no-lf empty really-empty; do
461 GIT_CONFIG="$git_config" cvs update -p "$i" >$i.out &&
462 test_cmp $i.out ../$i || return 1
467 test_expect_success
'cvs update (module list supports packed refs)' '
468 GIT_DIR="$SERVERDIR" git pack-refs --all &&
469 GIT_CONFIG="$git_config" cvs -n up -d 2> out &&
470 grep "cvs update: New directory \`main'\''" < out
478 test_expect_success
'cvs status' '
480 echo Line > status.dir/status.file &&
481 echo Line > status.file &&
482 git add status.dir status.file &&
483 git commit -q -m "Status test" &&
484 git push gitcvs.git >/dev/null &&
486 GIT_CONFIG="$git_config" cvs update &&
487 GIT_CONFIG="$git_config" cvs status | grep "^File: status.file" >../out &&
488 test_line_count = 2 ../out
492 test_expect_success
'cvs status (nonrecursive)' '
494 GIT_CONFIG="$git_config" cvs status -l | grep "^File: status.file" >../out &&
495 test_line_count = 1 ../out
499 test_expect_success
'cvs status (no subdirs in header)' '
501 GIT_CONFIG="$git_config" cvs status | grep ^File: >../out &&
510 test_expect_success
'cvs co -c (shows module database)' '
511 GIT_CONFIG="$git_config" cvs co -c > out &&
512 grep "^main[ ][ ]*main$" <out &&
513 ! grep -v "^main[ ][ ]*main$" <out
520 # Known issues with git-cvsserver current log output:
521 # - Hard coded "lines: +2 -3" placeholder, instead of real numbers.
522 # - CVS normally does not internally add a blank first line
523 # or a last line with nothing but a space to log messages.
524 # - The latest cvs 1.12.x server sends +0000 timezone (with some hidden "MT"
525 # tagging in the protocol), and if cvs 1.12.x client sees the MT tags,
526 # it converts to local time zone. git-cvsserver doesn't do the +0000
528 # - The latest 1.12.x releases add a "commitid:" field on to the end of the
529 # "date:" line (after "lines:"). Maybe we could stick git's commit id
530 # in it? Or does CVS expect a certain number of bits (too few for
533 # Given the above, expect the following test to break if git-cvsserver's
534 # log output is improved. The test is just to ensure it doesn't
535 # accidentally get worse.
537 sed -e 's/^x//' -e 's/SP$/ /' > "$WORKDIR/expect" <<EOF
539 xRCS file: $WORKDIR/gitcvs.git/main/merge,v
546 xkeyword substitution: kv
547 xtotal revisions: 4; selected revisions: 4
549 x----------------------------
551 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
555 x----------------------------
557 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
559 xMerge test (conflict)
561 x----------------------------
563 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
567 x----------------------------
569 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
571 xMerge test (pre-merge)
573 x=============================================================================
578 test_expect_success
'cvs log' '
580 test x"$expectStat" = x"0" &&
581 GIT_CONFIG="$git_config" cvs log merge >../out &&
582 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 &&
583 test_cmp ../expect ../actual
591 test_expect_success
'cvs annotate' '
593 GIT_CONFIG="$git_config" cvs annotate merge >../out &&
594 sed -e "s/ .*//" ../out >../actual &&
595 for i in 3 1 1 1 1 1 1 1 2 4; do echo 1.$i; done >../expect &&
596 test_cmp ../expect ../actual
600 # running via git-shell
605 test_expect_success
'create remote-cvs helper' '
606 write_script remote-cvs <<-\EOF
607 exec git shell -c "cvs server"
611 test_expect_success
'cvs server does not run with vanilla git-shell' '
614 CVS_SERVER=$WORKDIR/remote-cvs &&
620 test_expect_success
'configure git shell to run cvs server' '
621 mkdir "$HOME"/git-shell-commands &&
623 write_script "$HOME"/git-shell-commands/cvs <<-\EOF &&
624 if ! test $# = 1 && test "$1" = "server"
626 echo >&2 "git-cvsserver only handles \"server\""
629 exec git cvsserver server
632 # Should not be used, but part of the recommended setup
633 write_script "$HOME"/git-shell-commands/no-interactive-login <<-\EOF
634 echo Interactive login forbidden
638 test_expect_success
'cvs server can run with recommended config' '
641 CVS_SERVER=$WORKDIR/remote-cvs &&