Merge branch 'rj/cygwin-has-dev-tty'
[git/gitster.git] / t / t9400-git-cvsserver-server.sh
blobe499c7f955125eb25ce0dfdcd78012adf8cf4d7a
1 #!/bin/sh
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
14 . ./test-lib.sh
16 if ! test_have_prereq PERL; then
17 skip_all='skipping git cvsserver tests, perl not available'
18 test_done
20 cvs >/dev/null 2>&1
21 if test $? -ne 1
22 then
23 skip_all='skipping git-cvsserver tests, cvs not found'
24 test_done
26 perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
27 skip_all='skipping git-cvsserver tests, Perl SQLite interface unavailable'
28 test_done
31 WORKDIR=$PWD
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")'
40 then
41 PWDHASH='lac2ItudM3.KM'
42 else
43 PWDHASH='$2b$10$t8fGvE/a9eLmfOLzsZme2uOa2QtoMYwIxq9wZA6aBKtF1Yb7FJIzi'
46 rm -rf "$CVSWORK" "$SERVERDIR"
47 test_expect_success 'setup' '
48 git config push.default matching &&
49 echo >empty &&
50 git add empty &&
51 git commit -q -m "First Commit" &&
52 mkdir secondroot &&
53 ( cd secondroot &&
54 git init &&
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
80 BEGIN AUTH REQUEST
81 $SERVERDIR
82 anonymous
84 END AUTH REQUEST
85 EOF
87 cat >request-git <<EOF
88 BEGIN AUTH REQUEST
89 $SERVERDIR
90 git
92 END AUTH REQUEST
93 EOF
95 cat >login-anonymous <<EOF
96 BEGIN VERIFICATION REQUEST
97 $SERVERDIR
98 anonymous
100 END VERIFICATION REQUEST
103 cat >login-git <<EOF
104 BEGIN VERIFICATION REQUEST
105 $SERVERDIR
108 END VERIFICATION REQUEST
111 cat >login-git-ok <<EOF
112 BEGIN VERIFICATION REQUEST
113 $SERVERDIR
114 cvsuser
115 Ah<Z:yZZ30 e
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
126 then
127 false
128 else
129 true
130 fi &&
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
146 then
147 false
148 else
149 true
150 fi &&
151 sed -ne \$p log | grep "^I HATE YOU\$"
155 # misuse pserver authentication for testing of req_Root
157 cat >request-relative <<EOF
158 BEGIN AUTH REQUEST
159 gitcvs.git
160 anonymous
162 END AUTH REQUEST
165 cat >request-conflict <<EOF
166 BEGIN AUTH REQUEST
167 $SERVERDIR
168 anonymous
170 END AUTH REQUEST
171 Root $WORKDIR
174 test_expect_success 'req_Root failure (relative pathname)' '
175 if git-cvsserver pserver <request-relative >log 2>&1
176 then
177 echo unexpected success
178 false
179 else
180 true
181 fi &&
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
209 BEGIN AUTH REQUEST
210 /gitcvs.git
211 anonymous
213 END AUTH REQUEST
214 Root /gitcvs.git
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
243 #--------------
244 # CONFIG TESTS
245 #--------------
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
250 then
251 echo unexpected cvs success
252 false
253 else
254 true
255 fi &&
256 grep "GITCVS emulation disabled" cvs.log &&
257 test ! -d cvswork2'
259 rm -fr cvswork2
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
267 rm -fr 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
272 then
273 echo unexpected cvs success
274 false
275 else
276 true
277 fi &&
278 grep "GITCVS emulation disabled" cvs.log &&
279 test ! -d cvswork2
282 rm -fr cvswork2
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"
292 rm -fr cvswork2
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"
305 #------------
306 # CVS UPDATE
307 #------------
309 rm -fr "$SERVERDIR"
310 cd "$WORKDIR" &&
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" ||
314 exit 1
316 test_expect_success 'cvs update (create new file)' '
317 echo testfile1 >testfile1 &&
318 git add testfile1 &&
319 git commit -q -m "Add testfile1" &&
320 git push gitcvs.git >/dev/null &&
321 cd cvswork &&
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
327 cd "$WORKDIR"
328 test_expect_success 'cvs update (update existing file)' '
329 echo line 2 >>testfile1 &&
330 git add testfile1 &&
331 git commit -q -m "Append to testfile1" &&
332 git push gitcvs.git >/dev/null &&
333 cd cvswork &&
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
339 cd "$WORKDIR"
340 #TODO: cvsserver doesn't support update w/o -d
341 test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" '
342 mkdir test &&
343 echo >test/empty &&
344 git add test &&
345 git commit -q -m "Single Subdirectory" &&
346 git push gitcvs.git >/dev/null &&
347 cd cvswork &&
348 GIT_CONFIG="$git_config" cvs -Q update &&
349 test ! -d test
352 cd "$WORKDIR"
353 test_expect_success 'cvs update (subdirectories)' '
354 (for dir in A A/B A/B/C A/D E; do
355 mkdir $dir &&
356 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
357 git add $dir || exit 1
358 done) &&
359 git commit -q -m "deep sub directory structure" &&
360 git push gitcvs.git >/dev/null &&
361 cd cvswork &&
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
368 else
369 exit 1
371 done)
374 cd "$WORKDIR"
375 test_expect_success 'cvs update (delete file)' '
376 git rm testfile1 &&
377 git commit -q -m "Remove testfile1" &&
378 git push gitcvs.git >/dev/null &&
379 cd cvswork &&
380 GIT_CONFIG="$git_config" cvs -Q update &&
381 test -z "$(grep testfile1 CVS/Entries)" &&
382 test ! -f testfile1
385 cd "$WORKDIR"
386 test_expect_success 'cvs update (re-add deleted file)' '
387 echo readded testfile >testfile1 &&
388 git add testfile1 &&
389 git commit -q -m "Re-Add testfile1" &&
390 git push gitcvs.git >/dev/null &&
391 cd cvswork &&
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
397 cd "$WORKDIR"
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
404 done &&
405 echo Line 8 >>expected &&
406 git add merge &&
407 git commit -q -m "Merge test (pre-merge)" &&
408 git push gitcvs.git >/dev/null &&
409 cd cvswork &&
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 &&
415 cd "$WORKDIR" &&
416 echo Line 8 >>merge &&
417 git add merge &&
418 git commit -q -m "Merge test (merge)" &&
419 git push gitcvs.git >/dev/null &&
420 cd cvswork &&
421 sleep 1 && touch merge &&
422 GIT_CONFIG="$git_config" cvs -Q update &&
423 test_cmp merge ../expected
426 cd "$WORKDIR"
428 cat >expected.C <<EOF
429 <<<<<<< merge.mine
430 Line 0
431 =======
432 LINE 0
433 >>>>>>> merge.1.3
436 for i in 1 2 3 4 5 6 7 8
438 echo Line $i >>expected.C
439 done
441 test_expect_success 'cvs update (conflict merge)' '
442 ( echo LINE 0 && cat merge ) >merge.tmp &&
443 mv merge.tmp merge &&
444 git add merge &&
445 git commit -q -m "Merge test (conflict)" &&
446 git push gitcvs.git >/dev/null &&
447 cd cvswork &&
448 GIT_CONFIG="$git_config" cvs -Q update &&
449 test_cmp merge ../expected.C
452 cd "$WORKDIR"
453 test_expect_success 'cvs update (-C)' '
454 cd cvswork &&
455 GIT_CONFIG="$git_config" cvs -Q update -C &&
456 test_cmp merge ../merge
459 cd "$WORKDIR"
460 test_expect_success 'cvs update (merge no-op)' '
461 echo Line 9 >>merge &&
462 cp merge cvswork/merge &&
463 git add merge &&
464 git commit -q -m "Merge test (no-op)" &&
465 git push gitcvs.git >/dev/null &&
466 cd cvswork &&
467 sleep 1 && touch merge &&
468 GIT_CONFIG="$git_config" cvs -Q update &&
469 test_cmp merge ../merge
472 cd "$WORKDIR"
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 &&
480 cd cvswork &&
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
485 done
488 cd "$WORKDIR"
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
495 #------------
496 # CVS STATUS
497 #------------
499 cd "$WORKDIR"
500 test_expect_success 'cvs status' '
501 mkdir status.dir &&
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 &&
507 cd cvswork &&
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
513 cd "$WORKDIR"
514 test_expect_success 'cvs status (nonrecursive)' '
515 cd cvswork &&
516 GIT_CONFIG="$git_config" cvs status -l | grep "^File: status.file" >../out &&
517 test_line_count = 1 ../out
520 cd "$WORKDIR"
521 test_expect_success 'cvs status (no subdirs in header)' '
522 cd cvswork &&
523 GIT_CONFIG="$git_config" cvs status | grep ^File: >../out &&
524 ! grep / <../out
527 #------------
528 # CVS CHECKOUT
529 #------------
531 cd "$WORKDIR"
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
538 #------------
539 # CVS LOG
540 #------------
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
549 # or the MT tags...
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
553 # a full sha1)?
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
562 xWorking file: merge
563 xhead: 1.4
564 xbranch:
565 xlocks: strict
566 xaccess list:
567 xsymbolic names:
568 xkeyword substitution: kv
569 xtotal revisions: 4; selected revisions: 4
570 xdescription:
571 x----------------------------
572 xrevision 1.4
573 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
575 xMerge test (no-op)
577 x----------------------------
578 xrevision 1.3
579 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
581 xMerge test (conflict)
583 x----------------------------
584 xrevision 1.2
585 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
587 xMerge test (merge)
589 x----------------------------
590 xrevision 1.1
591 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
593 xMerge test (pre-merge)
595 x=============================================================================
597 expectStat="$?"
599 cd "$WORKDIR"
600 test_expect_success 'cvs log' '
601 cd cvswork &&
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
608 #------------
609 # CVS ANNOTATE
610 #------------
612 cd "$WORKDIR"
613 test_expect_success 'cvs annotate' '
614 cd cvswork &&
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
621 #------------
622 # running via git-shell
623 #------------
625 cd "$WORKDIR"
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' '
635 cd cvswork &&
636 CVS_SERVER=$WORKDIR/remote-cvs &&
637 export CVS_SERVER &&
638 ! cvs log merge
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"
647 then
648 echo >&2 "git-cvsserver only handles \"server\""
649 exit 1
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' '
662 cd cvswork &&
663 CVS_SERVER=$WORKDIR/remote-cvs &&
664 export CVS_SERVER &&
665 cvs log merge
669 test_done