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 rm -rf "$CVSWORK" "$SERVERDIR"
40 test_expect_success 'setup' '
41 git config push.default matching &&
44 git commit -q -m "First Commit" &&
48 touch secondrootfile &&
49 git add secondrootfile &&
50 git commit -m "second root") &&
51 git fetch secondroot main &&
52 git merge --allow-unrelated-histories FETCH_HEAD &&
53 git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
54 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
55 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" &&
56 GIT_DIR="$SERVERDIR" git config gitcvs.authdb "$SERVERDIR/auth.db" &&
57 echo cvsuser:cvGVEarMLnhlA > "$SERVERDIR/auth.db"
60 # note that cvs doesn't accept absolute pathnames
61 # as argument to co -d
62 test_expect_success 'basic checkout' \
63 'GIT_CONFIG="$git_config" cvs -Q co -d cvswork main &&
64 test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | head -n 1))" = "empty/1.1/" &&
65 test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | sed -ne \$p))" = "secondrootfile/1.1/"'
67 #------------------------
68 # PSERVER AUTHENTICATION
69 #------------------------
71 cat >request-anonymous <<EOF
79 cat >request-git <<EOF
87 cat >login-anonymous <<EOF
88 BEGIN VERIFICATION REQUEST
92 END VERIFICATION REQUEST
96 BEGIN VERIFICATION REQUEST
100 END VERIFICATION REQUEST
103 cat >login-git-ok <<EOF
104 BEGIN VERIFICATION REQUEST
108 END VERIFICATION REQUEST
111 test_expect_success 'pserver authentication' \
112 'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
113 sed -ne \$p log | grep "^I LOVE YOU\$"'
115 test_expect_success 'pserver authentication failure (non-anonymous user)' \
116 'if cat request-git | git-cvsserver pserver >log 2>&1
122 sed -ne \$p log | grep "^I HATE YOU\$"'
124 test_expect_success 'pserver authentication success (non-anonymous user with password)' \
125 'cat login-git-ok | git-cvsserver pserver >log 2>&1 &&
126 sed -ne \$p log | grep "^I LOVE YOU\$"'
128 test_expect_success 'pserver authentication (login)' \
129 'cat login-anonymous | git-cvsserver pserver >log 2>&1 &&
130 sed -ne \$p log | grep "^I LOVE YOU\$"'
132 test_expect_success 'pserver authentication failure (login/non-anonymous user)' \
133 'if cat login-git | git-cvsserver pserver >log 2>&1
139 sed -ne \$p log | grep "^I HATE YOU\$"'
142 # misuse pserver authentication for testing of req_Root
144 cat >request-relative <<EOF
152 cat >request-conflict <<EOF
161 test_expect_success 'req_Root failure (relative pathname)' \
162 'if cat request-relative | git-cvsserver pserver >log 2>&1
164 echo unexpected success
169 tail log | grep "^error 1 Root must be an absolute pathname$"'
171 test_expect_success 'req_Root failure (conflicting roots)' \
172 'cat request-conflict | git-cvsserver pserver >log 2>&1 &&
173 tail log | grep "^error 1 Conflicting roots specified$"'
175 test_expect_success 'req_Root (strict paths)' \
176 'cat request-anonymous | git-cvsserver --strict-paths pserver "$SERVERDIR" >log 2>&1 &&
177 sed -ne \$p log | grep "^I LOVE YOU\$"'
179 test_expect_success 'req_Root failure (strict-paths)' '
180 ! cat request-anonymous |
181 git-cvsserver --strict-paths pserver "$WORKDIR" >log 2>&1
184 test_expect_success 'req_Root (w/o strict-paths)' \
185 'cat request-anonymous | git-cvsserver pserver "$WORKDIR/" >log 2>&1 &&
186 sed -ne \$p log | grep "^I LOVE YOU\$"'
188 test_expect_success 'req_Root failure (w/o strict-paths)' '
189 ! cat request-anonymous |
190 git-cvsserver pserver "$WORKDIR/gitcvs" >log 2>&1
193 cat >request-base <<EOF
202 test_expect_success 'req_Root (base-path)' \
203 'cat request-base | git-cvsserver --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
204 sed -ne \$p log | grep "^I LOVE YOU\$"'
206 test_expect_success 'req_Root failure (base-path)' '
207 ! cat request-anonymous |
208 git-cvsserver --strict-paths --base-path "$WORKDIR" pserver "$SERVERDIR" >log 2>&1
211 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false || exit 1
213 test_expect_success 'req_Root (export-all)' \
214 'cat request-anonymous | git-cvsserver --export-all pserver "$WORKDIR" >log 2>&1 &&
215 sed -ne \$p log | grep "^I LOVE YOU\$"'
217 test_expect_success 'req_Root failure (export-all w/o whitelist)' \
218 '! (cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 || false)'
220 test_expect_success 'req_Root (everything together)' \
221 'cat request-base | git-cvsserver --export-all --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
222 sed -ne \$p log | grep "^I LOVE YOU\$"'
224 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true || exit 1
230 test_expect_success 'gitcvs.enabled = false' \
231 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
232 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1
234 echo unexpected cvs success
239 grep "GITCVS emulation disabled" cvs.log &&
243 test_expect_success 'gitcvs.ext.enabled = true' \
244 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
245 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
246 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
247 test_cmp cvswork cvswork2'
250 test_expect_success 'gitcvs.ext.enabled = false' \
251 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
252 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
253 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1
255 echo unexpected cvs success
260 grep "GITCVS emulation disabled" cvs.log &&
264 test_expect_success 'gitcvs.dbname' \
265 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
266 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
267 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
268 test_cmp cvswork cvswork2 &&
269 test -f "$SERVERDIR/gitcvs.ext.main.sqlite" &&
270 cmp "$SERVERDIR/gitcvs.main.sqlite" "$SERVERDIR/gitcvs.ext.main.sqlite"'
273 test_expect_success 'gitcvs.ext.dbname' \
274 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
275 GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
276 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
277 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
278 test_cmp cvswork cvswork2 &&
279 test -f "$SERVERDIR/gitcvs1.ext.main.sqlite" &&
280 test ! -f "$SERVERDIR/gitcvs2.ext.main.sqlite" &&
281 cmp "$SERVERDIR/gitcvs.main.sqlite" "$SERVERDIR/gitcvs1.ext.main.sqlite"'
290 git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
291 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
292 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
295 test_expect_success 'cvs update (create new file)' \
296 'echo testfile1 >testfile1 &&
298 git commit -q -m "Add testfile1" &&
299 git push gitcvs.git >/dev/null &&
301 GIT_CONFIG="$git_config" cvs -Q update &&
302 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
303 test_cmp testfile1 ../testfile1'
306 test_expect_success 'cvs update (update existing file)' \
307 'echo line 2 >>testfile1 &&
309 git commit -q -m "Append to testfile1" &&
310 git push gitcvs.git >/dev/null &&
312 GIT_CONFIG="$git_config" cvs -Q update &&
313 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
314 test_cmp testfile1 ../testfile1'
317 #TODO: cvsserver doesn't support update w/o -d
318 test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" '
322 git commit -q -m "Single Subdirectory" &&
323 git push gitcvs.git >/dev/null &&
325 GIT_CONFIG="$git_config" cvs -Q update &&
330 test_expect_success 'cvs update (subdirectories)' \
331 '(for dir in A A/B A/B/C A/D E; do
333 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
336 git commit -q -m "deep sub directory structure" &&
337 git push gitcvs.git >/dev/null &&
339 GIT_CONFIG="$git_config" cvs -Q update -d &&
340 (for dir in A A/B A/B/C A/D E; do
341 filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
342 if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
343 test_cmp "$dir/$filename" "../$dir/$filename"; then
352 test_expect_success 'cvs update (delete file)' \
354 git commit -q -m "Remove testfile1" &&
355 git push gitcvs.git >/dev/null &&
357 GIT_CONFIG="$git_config" cvs -Q update &&
358 test -z "$(grep testfile1 CVS/Entries)" &&
362 test_expect_success 'cvs update (re-add deleted file)' \
363 'echo readded testfile >testfile1 &&
365 git commit -q -m "Re-Add testfile1" &&
366 git push gitcvs.git >/dev/null &&
368 GIT_CONFIG="$git_config" cvs -Q update &&
369 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
370 test_cmp testfile1 ../testfile1'
373 test_expect_success 'cvs update (merge)' \
374 'echo Line 0 >expected &&
375 for i in 1 2 3 4 5 6 7
377 echo Line $i >>merge &&
378 echo Line $i >>expected
380 echo Line 8 >>expected &&
382 git commit -q -m "Merge test (pre-merge)" &&
383 git push gitcvs.git >/dev/null &&
385 GIT_CONFIG="$git_config" cvs -Q update &&
386 test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
387 test_cmp merge ../merge &&
388 ( echo Line 0 && cat merge ) >merge.tmp &&
389 mv merge.tmp merge &&
391 echo Line 8 >>merge &&
393 git commit -q -m "Merge test (merge)" &&
394 git push gitcvs.git >/dev/null &&
396 sleep 1 && touch merge &&
397 GIT_CONFIG="$git_config" cvs -Q update &&
398 test_cmp merge ../expected'
402 cat >expected.C <<EOF
410 for i in 1 2 3 4 5 6 7 8
412 echo Line $i >>expected.C
415 test_expect_success 'cvs update (conflict merge)' \
416 '( echo LINE 0 && cat merge ) >merge.tmp &&
417 mv merge.tmp merge &&
419 git commit -q -m "Merge test (conflict)" &&
420 git push gitcvs.git >/dev/null &&
422 GIT_CONFIG="$git_config" cvs -Q update &&
423 test_cmp merge ../expected.C'
426 test_expect_success 'cvs update (-C)' \
428 GIT_CONFIG="$git_config" cvs -Q update -C &&
429 test_cmp merge ../merge'
432 test_expect_success 'cvs update (merge no-op)' \
433 'echo Line 9 >>merge &&
434 cp merge cvswork/merge &&
436 git commit -q -m "Merge test (no-op)" &&
437 git push gitcvs.git >/dev/null &&
439 sleep 1 && touch merge &&
440 GIT_CONFIG="$git_config" cvs -Q update &&
441 test_cmp merge ../merge'
444 test_expect_success 'cvs update (-p)' '
445 touch really-empty &&
446 echo Line 1 > no-lf &&
447 printf "Line 2" >> no-lf &&
448 git add really-empty no-lf &&
449 git commit -q -m "Update -p test" &&
450 git push gitcvs.git >/dev/null &&
452 GIT_CONFIG="$git_config" cvs update &&
453 for i in merge no-lf empty really-empty; do
454 GIT_CONFIG="$git_config" cvs update -p "$i" >$i.out &&
455 test_cmp $i.out ../$i || return 1
460 test_expect_success 'cvs update (module list supports packed refs)' '
461 GIT_DIR="$SERVERDIR" git pack-refs --all &&
462 GIT_CONFIG="$git_config" cvs -n up -d 2> out &&
463 grep "cvs update: New directory \`main'\''" < out
471 test_expect_success 'cvs status' '
473 echo Line > status.dir/status.file &&
474 echo Line > status.file &&
475 git add status.dir status.file &&
476 git commit -q -m "Status test" &&
477 git push gitcvs.git >/dev/null &&
479 GIT_CONFIG="$git_config" cvs update &&
480 GIT_CONFIG="$git_config" cvs status | grep "^File: status.file" >../out &&
481 test_line_count = 2 ../out
485 test_expect_success 'cvs status (nonrecursive)' '
487 GIT_CONFIG="$git_config" cvs status -l | grep "^File: status.file" >../out &&
488 test_line_count = 1 ../out
492 test_expect_success 'cvs status (no subdirs in header)' '
494 GIT_CONFIG="$git_config" cvs status | grep ^File: >../out &&
503 test_expect_success 'cvs co -c (shows module database)' '
504 GIT_CONFIG="$git_config" cvs co -c > out &&
505 grep "^main[ ][ ]*main$" <out &&
506 ! grep -v "^main[ ][ ]*main$" <out
513 # Known issues with git-cvsserver current log output:
514 # - Hard coded "lines: +2 -3" placeholder, instead of real numbers.
515 # - CVS normally does not internally add a blank first line
516 # or a last line with nothing but a space to log messages.
517 # - The latest cvs 1.12.x server sends +0000 timezone (with some hidden "MT"
518 # tagging in the protocol), and if cvs 1.12.x client sees the MT tags,
519 # it converts to local time zone. git-cvsserver doesn't do the +0000
521 # - The latest 1.12.x releases add a "commitid:" field on to the end of the
522 # "date:" line (after "lines:"). Maybe we could stick git's commit id
523 # in it? Or does CVS expect a certain number of bits (too few for
526 # Given the above, expect the following test to break if git-cvsserver's
527 # log output is improved. The test is just to ensure it doesn't
528 # accidentally get worse.
530 sed -e 's/^x//' -e 's/SP$/ /' > "$WORKDIR/expect" <<EOF
532 xRCS file: $WORKDIR/gitcvs.git/main/merge,v
539 xkeyword substitution: kv
540 xtotal revisions: 4; selected revisions: 4
542 x----------------------------
544 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
548 x----------------------------
550 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
552 xMerge test (conflict)
554 x----------------------------
556 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
560 x----------------------------
562 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
564 xMerge test (pre-merge)
566 x=============================================================================
571 test_expect_success 'cvs log' '
573 test x"$expectStat" = x"0" &&
574 GIT_CONFIG="$git_config" cvs log merge >../out &&
575 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 &&
576 test_cmp ../expect ../actual
584 test_expect_success 'cvs annotate' '
586 GIT_CONFIG="$git_config" cvs annotate merge >../out &&
587 sed -e "s/ .*//" ../out >../actual &&
588 for i in 3 1 1 1 1 1 1 1 2 4; do echo 1.$i; done >../expect &&
589 test_cmp ../expect ../actual
593 # running via git-shell
598 test_expect_success 'create remote-cvs helper' '
599 write_script remote-cvs <<-\EOF
600 exec git shell -c "cvs server"
604 test_expect_success 'cvs server does not run with vanilla git-shell' '
607 CVS_SERVER=$WORKDIR/remote-cvs &&
613 test_expect_success 'configure git shell to run cvs server' '
614 mkdir "$HOME"/git-shell-commands &&
616 write_script "$HOME"/git-shell-commands/cvs <<-\EOF &&
617 if ! test $# = 1 && test "$1" = "server"
619 echo >&2 "git-cvsserver only handles \"server\""
622 exec git cvsserver server
625 # Should not be used, but part of the recommended setup
626 write_script "$HOME"/git-shell-commands/no-interactive-login <<-\EOF
627 echo Interactive login forbidden
631 test_expect_success 'cvs server can run with recommended config' '
634 CVS_SERVER=$WORKDIR/remote-cvs &&