l10n: README: fix typo
[alt-git.git] / t / t9400-git-cvsserver-server.sh
blob210ddf09e3094ebe5fa00599db22106813f4229e
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/"'
74 #------------------------
75 # PSERVER AUTHENTICATION
76 #------------------------
78 cat >request-anonymous <<EOF
79 BEGIN AUTH REQUEST
80 $SERVERDIR
81 anonymous
83 END AUTH REQUEST
84 EOF
86 cat >request-git <<EOF
87 BEGIN AUTH REQUEST
88 $SERVERDIR
89 git
91 END AUTH REQUEST
92 EOF
94 cat >login-anonymous <<EOF
95 BEGIN VERIFICATION REQUEST
96 $SERVERDIR
97 anonymous
99 END VERIFICATION REQUEST
102 cat >login-git <<EOF
103 BEGIN VERIFICATION REQUEST
104 $SERVERDIR
107 END VERIFICATION REQUEST
110 cat >login-git-ok <<EOF
111 BEGIN VERIFICATION REQUEST
112 $SERVERDIR
113 cvsuser
114 Ah<Z:yZZ30 e
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
124 then
125 false
126 else
127 true
128 fi &&
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
141 then
142 false
143 else
144 true
145 fi &&
146 sed -ne \$p log | grep "^I HATE YOU\$"'
149 # misuse pserver authentication for testing of req_Root
151 cat >request-relative <<EOF
152 BEGIN AUTH REQUEST
153 gitcvs.git
154 anonymous
156 END AUTH REQUEST
159 cat >request-conflict <<EOF
160 BEGIN AUTH REQUEST
161 $SERVERDIR
162 anonymous
164 END AUTH REQUEST
165 Root $WORKDIR
168 test_expect_success 'req_Root failure (relative pathname)' \
169 'if cat request-relative | git-cvsserver pserver >log 2>&1
170 then
171 echo unexpected success
172 false
173 else
174 true
175 fi &&
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
201 BEGIN AUTH REQUEST
202 /gitcvs.git
203 anonymous
205 END AUTH REQUEST
206 Root /gitcvs.git
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
233 #--------------
234 # CONFIG TESTS
235 #--------------
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
240 then
241 echo unexpected cvs success
242 false
243 else
244 true
245 fi &&
246 grep "GITCVS emulation disabled" cvs.log &&
247 test ! -d cvswork2'
249 rm -fr cvswork2
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'
256 rm -fr 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
261 then
262 echo unexpected cvs success
263 false
264 else
265 true
266 fi &&
267 grep "GITCVS emulation disabled" cvs.log &&
268 test ! -d cvswork2'
270 rm -fr cvswork2
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"'
279 rm -fr cvswork2
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"'
291 #------------
292 # CVS UPDATE
293 #------------
295 rm -fr "$SERVERDIR"
296 cd "$WORKDIR" &&
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" ||
300 exit 1
302 test_expect_success 'cvs update (create new file)' \
303 'echo testfile1 >testfile1 &&
304 git add testfile1 &&
305 git commit -q -m "Add testfile1" &&
306 git push gitcvs.git >/dev/null &&
307 cd cvswork &&
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'
312 cd "$WORKDIR"
313 test_expect_success 'cvs update (update existing file)' \
314 'echo line 2 >>testfile1 &&
315 git add testfile1 &&
316 git commit -q -m "Append to testfile1" &&
317 git push gitcvs.git >/dev/null &&
318 cd cvswork &&
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'
323 cd "$WORKDIR"
324 #TODO: cvsserver doesn't support update w/o -d
325 test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" '
326 mkdir test &&
327 echo >test/empty &&
328 git add test &&
329 git commit -q -m "Single Subdirectory" &&
330 git push gitcvs.git >/dev/null &&
331 cd cvswork &&
332 GIT_CONFIG="$git_config" cvs -Q update &&
333 test ! -d test
336 cd "$WORKDIR"
337 test_expect_success 'cvs update (subdirectories)' \
338 '(for dir in A A/B A/B/C A/D E; do
339 mkdir $dir &&
340 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
341 git add $dir || exit 1
342 done) &&
343 git commit -q -m "deep sub directory structure" &&
344 git push gitcvs.git >/dev/null &&
345 cd cvswork &&
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
352 else
353 exit 1
355 done)'
357 cd "$WORKDIR"
358 test_expect_success 'cvs update (delete file)' \
359 'git rm testfile1 &&
360 git commit -q -m "Remove testfile1" &&
361 git push gitcvs.git >/dev/null &&
362 cd cvswork &&
363 GIT_CONFIG="$git_config" cvs -Q update &&
364 test -z "$(grep testfile1 CVS/Entries)" &&
365 test ! -f testfile1'
367 cd "$WORKDIR"
368 test_expect_success 'cvs update (re-add deleted file)' \
369 'echo readded testfile >testfile1 &&
370 git add testfile1 &&
371 git commit -q -m "Re-Add testfile1" &&
372 git push gitcvs.git >/dev/null &&
373 cd cvswork &&
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'
378 cd "$WORKDIR"
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
385 done &&
386 echo Line 8 >>expected &&
387 git add merge &&
388 git commit -q -m "Merge test (pre-merge)" &&
389 git push gitcvs.git >/dev/null &&
390 cd cvswork &&
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 &&
396 cd "$WORKDIR" &&
397 echo Line 8 >>merge &&
398 git add merge &&
399 git commit -q -m "Merge test (merge)" &&
400 git push gitcvs.git >/dev/null &&
401 cd cvswork &&
402 sleep 1 && touch merge &&
403 GIT_CONFIG="$git_config" cvs -Q update &&
404 test_cmp merge ../expected'
406 cd "$WORKDIR"
408 cat >expected.C <<EOF
409 <<<<<<< merge.mine
410 Line 0
411 =======
412 LINE 0
413 >>>>>>> merge.1.3
416 for i in 1 2 3 4 5 6 7 8
418 echo Line $i >>expected.C
419 done
421 test_expect_success 'cvs update (conflict merge)' \
422 '( echo LINE 0 && cat merge ) >merge.tmp &&
423 mv merge.tmp merge &&
424 git add merge &&
425 git commit -q -m "Merge test (conflict)" &&
426 git push gitcvs.git >/dev/null &&
427 cd cvswork &&
428 GIT_CONFIG="$git_config" cvs -Q update &&
429 test_cmp merge ../expected.C'
431 cd "$WORKDIR"
432 test_expect_success 'cvs update (-C)' \
433 'cd cvswork &&
434 GIT_CONFIG="$git_config" cvs -Q update -C &&
435 test_cmp merge ../merge'
437 cd "$WORKDIR"
438 test_expect_success 'cvs update (merge no-op)' \
439 'echo Line 9 >>merge &&
440 cp merge cvswork/merge &&
441 git add merge &&
442 git commit -q -m "Merge test (no-op)" &&
443 git push gitcvs.git >/dev/null &&
444 cd cvswork &&
445 sleep 1 && touch merge &&
446 GIT_CONFIG="$git_config" cvs -Q update &&
447 test_cmp merge ../merge'
449 cd "$WORKDIR"
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 &&
457 cd cvswork &&
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
462 done
465 cd "$WORKDIR"
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
472 #------------
473 # CVS STATUS
474 #------------
476 cd "$WORKDIR"
477 test_expect_success 'cvs status' '
478 mkdir status.dir &&
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 &&
484 cd cvswork &&
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
490 cd "$WORKDIR"
491 test_expect_success 'cvs status (nonrecursive)' '
492 cd cvswork &&
493 GIT_CONFIG="$git_config" cvs status -l | grep "^File: status.file" >../out &&
494 test_line_count = 1 ../out
497 cd "$WORKDIR"
498 test_expect_success 'cvs status (no subdirs in header)' '
499 cd cvswork &&
500 GIT_CONFIG="$git_config" cvs status | grep ^File: >../out &&
501 ! grep / <../out
504 #------------
505 # CVS CHECKOUT
506 #------------
508 cd "$WORKDIR"
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
515 #------------
516 # CVS LOG
517 #------------
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
526 # or the MT tags...
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
530 # a full sha1)?
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
539 xWorking file: merge
540 xhead: 1.4
541 xbranch:
542 xlocks: strict
543 xaccess list:
544 xsymbolic names:
545 xkeyword substitution: kv
546 xtotal revisions: 4; selected revisions: 4
547 xdescription:
548 x----------------------------
549 xrevision 1.4
550 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
552 xMerge test (no-op)
554 x----------------------------
555 xrevision 1.3
556 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
558 xMerge test (conflict)
560 x----------------------------
561 xrevision 1.2
562 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
564 xMerge test (merge)
566 x----------------------------
567 xrevision 1.1
568 xdate: __DATE__; author: author; state: Exp; lines: +2 -3
570 xMerge test (pre-merge)
572 x=============================================================================
574 expectStat="$?"
576 cd "$WORKDIR"
577 test_expect_success 'cvs log' '
578 cd cvswork &&
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
585 #------------
586 # CVS ANNOTATE
587 #------------
589 cd "$WORKDIR"
590 test_expect_success 'cvs annotate' '
591 cd cvswork &&
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
598 #------------
599 # running via git-shell
600 #------------
602 cd "$WORKDIR"
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' '
612 cd cvswork &&
613 CVS_SERVER=$WORKDIR/remote-cvs &&
614 export CVS_SERVER &&
615 ! cvs log merge
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"
624 then
625 echo >&2 "git-cvsserver only handles \"server\""
626 exit 1
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' '
639 cd cvswork &&
640 CVS_SERVER=$WORKDIR/remote-cvs &&
641 export CVS_SERVER &&
642 cvs log merge
646 test_done