Merge branch 'ml/doc-merge-updates' into maint-2.43
[alt-git.git] / t / t9400-git-cvsserver-server.sh
blob003c0b61d0ff45864630782a509a018ff4079116
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 cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
121 sed -ne \$p log | grep "^I LOVE YOU\$"
124 test_expect_success 'pserver authentication failure (non-anonymous user)' '
125 if cat request-git | git-cvsserver pserver >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 cat login-git-ok | git-cvsserver pserver >log 2>&1 &&
136 sed -ne \$p log | grep "^I LOVE YOU\$"
139 test_expect_success 'pserver authentication (login)' '
140 cat login-anonymous | git-cvsserver pserver >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 cat login-git | git-cvsserver pserver >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 cat request-relative | git-cvsserver pserver >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 cat request-conflict | git-cvsserver pserver >log 2>&1 &&
187 tail log | grep "^error 1 Conflicting roots specified$"
190 test_expect_success 'req_Root (strict paths)' '
191 cat request-anonymous | git-cvsserver --strict-paths pserver "$SERVERDIR" >log 2>&1 &&
192 sed -ne \$p log | grep "^I LOVE YOU\$"
195 test_expect_success 'req_Root failure (strict-paths)' '
196 ! cat request-anonymous |
197 git-cvsserver --strict-paths pserver "$WORKDIR" >log 2>&1
200 test_expect_success 'req_Root (w/o strict-paths)' '
201 cat request-anonymous | git-cvsserver pserver "$WORKDIR/" >log 2>&1 &&
202 sed -ne \$p log | grep "^I LOVE YOU\$"
205 test_expect_success 'req_Root failure (w/o strict-paths)' '
206 ! cat request-anonymous |
207 git-cvsserver pserver "$WORKDIR/gitcvs" >log 2>&1
210 cat >request-base <<EOF
211 BEGIN AUTH REQUEST
212 /gitcvs.git
213 anonymous
215 END AUTH REQUEST
216 Root /gitcvs.git
219 test_expect_success 'req_Root (base-path)' '
220 cat request-base | git-cvsserver --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
221 sed -ne \$p log | grep "^I LOVE YOU\$"
224 test_expect_success 'req_Root failure (base-path)' '
225 ! cat request-anonymous |
226 git-cvsserver --strict-paths --base-path "$WORKDIR" pserver "$SERVERDIR" >log 2>&1
229 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false || exit 1
231 test_expect_success 'req_Root (export-all)' '
232 cat request-anonymous | git-cvsserver --export-all pserver "$WORKDIR" >log 2>&1 &&
233 sed -ne \$p log | grep "^I LOVE YOU\$"
236 test_expect_success 'req_Root failure (export-all w/o directory list)' '
237 ! (cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 || false)'
239 test_expect_success 'req_Root (everything together)' '
240 cat request-base | git-cvsserver --export-all --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
241 sed -ne \$p log | grep "^I LOVE YOU\$"
244 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true || exit 1
246 #--------------
247 # CONFIG TESTS
248 #--------------
250 test_expect_success 'gitcvs.enabled = false' \
251 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
252 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1
253 then
254 echo unexpected cvs success
255 false
256 else
257 true
258 fi &&
259 grep "GITCVS emulation disabled" cvs.log &&
260 test ! -d cvswork2'
262 rm -fr cvswork2
263 test_expect_success 'gitcvs.ext.enabled = true' '
264 GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
265 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
266 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
267 test_cmp cvswork cvswork2
270 rm -fr cvswork2
271 test_expect_success 'gitcvs.ext.enabled = false' '
272 GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
273 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
274 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1
275 then
276 echo unexpected cvs success
277 false
278 else
279 true
280 fi &&
281 grep "GITCVS emulation disabled" cvs.log &&
282 test ! -d cvswork2
285 rm -fr cvswork2
286 test_expect_success 'gitcvs.dbname' '
287 GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
288 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
289 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
290 test_cmp cvswork cvswork2 &&
291 test -f "$SERVERDIR/gitcvs.ext.main.sqlite" &&
292 cmp "$SERVERDIR/gitcvs.main.sqlite" "$SERVERDIR/gitcvs.ext.main.sqlite"
295 rm -fr cvswork2
296 test_expect_success 'gitcvs.ext.dbname' '
297 GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
298 GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
299 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
300 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 &&
301 test_cmp cvswork cvswork2 &&
302 test -f "$SERVERDIR/gitcvs1.ext.main.sqlite" &&
303 test ! -f "$SERVERDIR/gitcvs2.ext.main.sqlite" &&
304 cmp "$SERVERDIR/gitcvs.main.sqlite" "$SERVERDIR/gitcvs1.ext.main.sqlite"
308 #------------
309 # CVS UPDATE
310 #------------
312 rm -fr "$SERVERDIR"
313 cd "$WORKDIR" &&
314 git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
315 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
316 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
317 exit 1
319 test_expect_success 'cvs update (create new file)' '
320 echo testfile1 >testfile1 &&
321 git add testfile1 &&
322 git commit -q -m "Add testfile1" &&
323 git push gitcvs.git >/dev/null &&
324 cd cvswork &&
325 GIT_CONFIG="$git_config" cvs -Q update &&
326 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
327 test_cmp testfile1 ../testfile1
330 cd "$WORKDIR"
331 test_expect_success 'cvs update (update existing file)' '
332 echo line 2 >>testfile1 &&
333 git add testfile1 &&
334 git commit -q -m "Append to testfile1" &&
335 git push gitcvs.git >/dev/null &&
336 cd cvswork &&
337 GIT_CONFIG="$git_config" cvs -Q update &&
338 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
339 test_cmp testfile1 ../testfile1
342 cd "$WORKDIR"
343 #TODO: cvsserver doesn't support update w/o -d
344 test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" '
345 mkdir test &&
346 echo >test/empty &&
347 git add test &&
348 git commit -q -m "Single Subdirectory" &&
349 git push gitcvs.git >/dev/null &&
350 cd cvswork &&
351 GIT_CONFIG="$git_config" cvs -Q update &&
352 test ! -d test
355 cd "$WORKDIR"
356 test_expect_success 'cvs update (subdirectories)' '
357 (for dir in A A/B A/B/C A/D E; do
358 mkdir $dir &&
359 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
360 git add $dir || exit 1
361 done) &&
362 git commit -q -m "deep sub directory structure" &&
363 git push gitcvs.git >/dev/null &&
364 cd cvswork &&
365 GIT_CONFIG="$git_config" cvs -Q update -d &&
366 (for dir in A A/B A/B/C A/D E; do
367 filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
368 if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
369 test_cmp "$dir/$filename" "../$dir/$filename"; then
371 else
372 exit 1
374 done)
377 cd "$WORKDIR"
378 test_expect_success 'cvs update (delete file)' '
379 git rm testfile1 &&
380 git commit -q -m "Remove testfile1" &&
381 git push gitcvs.git >/dev/null &&
382 cd cvswork &&
383 GIT_CONFIG="$git_config" cvs -Q update &&
384 test -z "$(grep testfile1 CVS/Entries)" &&
385 test ! -f testfile1
388 cd "$WORKDIR"
389 test_expect_success 'cvs update (re-add deleted file)' '
390 echo readded testfile >testfile1 &&
391 git add testfile1 &&
392 git commit -q -m "Re-Add testfile1" &&
393 git push gitcvs.git >/dev/null &&
394 cd cvswork &&
395 GIT_CONFIG="$git_config" cvs -Q update &&
396 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
397 test_cmp testfile1 ../testfile1
400 cd "$WORKDIR"
401 test_expect_success 'cvs update (merge)' '
402 echo Line 0 >expected &&
403 for i in 1 2 3 4 5 6 7
405 echo Line $i >>merge &&
406 echo Line $i >>expected || return 1
407 done &&
408 echo Line 8 >>expected &&
409 git add merge &&
410 git commit -q -m "Merge test (pre-merge)" &&
411 git push gitcvs.git >/dev/null &&
412 cd cvswork &&
413 GIT_CONFIG="$git_config" cvs -Q update &&
414 test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
415 test_cmp merge ../merge &&
416 ( echo Line 0 && cat merge ) >merge.tmp &&
417 mv merge.tmp merge &&
418 cd "$WORKDIR" &&
419 echo Line 8 >>merge &&
420 git add merge &&
421 git commit -q -m "Merge test (merge)" &&
422 git push gitcvs.git >/dev/null &&
423 cd cvswork &&
424 sleep 1 && touch merge &&
425 GIT_CONFIG="$git_config" cvs -Q update &&
426 test_cmp merge ../expected
429 cd "$WORKDIR"
431 cat >expected.C <<EOF
432 <<<<<<< merge.mine
433 Line 0
434 =======
435 LINE 0
436 >>>>>>> merge.1.3
439 for i in 1 2 3 4 5 6 7 8
441 echo Line $i >>expected.C
442 done
444 test_expect_success 'cvs update (conflict merge)' '
445 ( echo LINE 0 && cat merge ) >merge.tmp &&
446 mv merge.tmp merge &&
447 git add merge &&
448 git commit -q -m "Merge test (conflict)" &&
449 git push gitcvs.git >/dev/null &&
450 cd cvswork &&
451 GIT_CONFIG="$git_config" cvs -Q update &&
452 test_cmp merge ../expected.C
455 cd "$WORKDIR"
456 test_expect_success 'cvs update (-C)' '
457 cd cvswork &&
458 GIT_CONFIG="$git_config" cvs -Q update -C &&
459 test_cmp merge ../merge
462 cd "$WORKDIR"
463 test_expect_success 'cvs update (merge no-op)' '
464 echo Line 9 >>merge &&
465 cp merge cvswork/merge &&
466 git add merge &&
467 git commit -q -m "Merge test (no-op)" &&
468 git push gitcvs.git >/dev/null &&
469 cd cvswork &&
470 sleep 1 && touch merge &&
471 GIT_CONFIG="$git_config" cvs -Q update &&
472 test_cmp merge ../merge
475 cd "$WORKDIR"
476 test_expect_success 'cvs update (-p)' '
477 touch really-empty &&
478 echo Line 1 > no-lf &&
479 printf "Line 2" >> no-lf &&
480 git add really-empty no-lf &&
481 git commit -q -m "Update -p test" &&
482 git push gitcvs.git >/dev/null &&
483 cd cvswork &&
484 GIT_CONFIG="$git_config" cvs update &&
485 for i in merge no-lf empty really-empty; do
486 GIT_CONFIG="$git_config" cvs update -p "$i" >$i.out &&
487 test_cmp $i.out ../$i || return 1
488 done
491 cd "$WORKDIR"
492 test_expect_success 'cvs update (module list supports packed refs)' '
493 GIT_DIR="$SERVERDIR" git pack-refs --all &&
494 GIT_CONFIG="$git_config" cvs -n up -d 2> out &&
495 grep "cvs update: New directory \`main'\''" < out
498 #------------
499 # CVS STATUS
500 #------------
502 cd "$WORKDIR"
503 test_expect_success 'cvs status' '
504 mkdir status.dir &&
505 echo Line > status.dir/status.file &&
506 echo Line > status.file &&
507 git add status.dir status.file &&
508 git commit -q -m "Status test" &&
509 git push gitcvs.git >/dev/null &&
510 cd cvswork &&
511 GIT_CONFIG="$git_config" cvs update &&
512 GIT_CONFIG="$git_config" cvs status | grep "^File: status.file" >../out &&
513 test_line_count = 2 ../out
516 cd "$WORKDIR"
517 test_expect_success 'cvs status (nonrecursive)' '
518 cd cvswork &&
519 GIT_CONFIG="$git_config" cvs status -l | grep "^File: status.file" >../out &&
520 test_line_count = 1 ../out
523 cd "$WORKDIR"
524 test_expect_success 'cvs status (no subdirs in header)' '
525 cd cvswork &&
526 GIT_CONFIG="$git_config" cvs status | grep ^File: >../out &&
527 ! grep / <../out
530 #------------
531 # CVS CHECKOUT
532 #------------
534 cd "$WORKDIR"
535 test_expect_success 'cvs co -c (shows module database)' '
536 GIT_CONFIG="$git_config" cvs co -c > out &&
537 grep "^main[ ][ ]*main$" <out &&
538 ! grep -v "^main[ ][ ]*main$" <out
541 #------------
542 # CVS LOG
543 #------------
545 # Known issues with git-cvsserver current log output:
546 # - Hard coded "lines: +2 -3" placeholder, instead of real numbers.
547 # - CVS normally does not internally add a blank first line
548 # or a last line with nothing but a space to log messages.
549 # - The latest cvs 1.12.x server sends +0000 timezone (with some hidden "MT"
550 # tagging in the protocol), and if cvs 1.12.x client sees the MT tags,
551 # it converts to local time zone. git-cvsserver doesn't do the +0000
552 # or the MT tags...
553 # - The latest 1.12.x releases add a "commitid:" field on to the end of the
554 # "date:" line (after "lines:"). Maybe we could stick git's commit id
555 # in it? Or does CVS expect a certain number of bits (too few for
556 # a full sha1)?
558 # Given the above, expect the following test to break if git-cvsserver's
559 # log output is improved. The test is just to ensure it doesn't
560 # accidentally get worse.
562 sed -e 's/^x//' -e 's/SP$/ /' > "$WORKDIR/expect" <<EOF
564 xRCS file: $WORKDIR/gitcvs.git/main/merge,v
565 xWorking file: merge
566 xhead: 1.4
567 xbranch:
568 xlocks: strict
569 xaccess list:
570 xsymbolic names:
571 xkeyword substitution: kv
572 xtotal revisions: 4; selected revisions: 4
573 xdescription:
574 x----------------------------
575 xrevision 1.4
576 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
578 xMerge test (no-op)
580 x----------------------------
581 xrevision 1.3
582 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
584 xMerge test (conflict)
586 x----------------------------
587 xrevision 1.2
588 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
590 xMerge test (merge)
592 x----------------------------
593 xrevision 1.1
594 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
596 xMerge test (pre-merge)
598 x=============================================================================
600 expectStat="$?"
602 cd "$WORKDIR"
603 test_expect_success 'cvs log' '
604 cd cvswork &&
605 test x"$expectStat" = x"0" &&
606 GIT_CONFIG="$git_config" cvs log merge >../out &&
607 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 &&
608 test_cmp ../expect ../actual
611 #------------
612 # CVS ANNOTATE
613 #------------
615 cd "$WORKDIR"
616 test_expect_success 'cvs annotate' '
617 cd cvswork &&
618 GIT_CONFIG="$git_config" cvs annotate merge >../out &&
619 sed -e "s/ .*//" ../out >../actual &&
620 printf "1.%d\n" 3 1 1 1 1 1 1 1 2 4 >../expect &&
621 test_cmp ../expect ../actual
624 #------------
625 # running via git-shell
626 #------------
628 cd "$WORKDIR"
630 test_expect_success 'create remote-cvs helper' '
631 write_script remote-cvs <<-\EOF
632 exec git shell -c "cvs server"
636 test_expect_success 'cvs server does not run with vanilla git-shell' '
638 cd cvswork &&
639 CVS_SERVER=$WORKDIR/remote-cvs &&
640 export CVS_SERVER &&
641 ! cvs log merge
645 test_expect_success 'configure git shell to run cvs server' '
646 mkdir "$HOME"/git-shell-commands &&
648 write_script "$HOME"/git-shell-commands/cvs <<-\EOF &&
649 if ! test $# = 1 && test "$1" = "server"
650 then
651 echo >&2 "git-cvsserver only handles \"server\""
652 exit 1
654 exec git cvsserver server
657 # Should not be used, but part of the recommended setup
658 write_script "$HOME"/git-shell-commands/no-interactive-login <<-\EOF
659 echo Interactive login forbidden
663 test_expect_success 'cvs server can run with recommended config' '
665 cd cvswork &&
666 CVS_SERVER=$WORKDIR/remote-cvs &&
667 export CVS_SERVER &&
668 cvs log merge
672 test_done