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'
13 if ! test_have_prereq PERL; then
14 say 'skipping git cvsserver tests, perl not available'
20 say 'skipping git-cvsserver tests, cvs not found'
23 "$PERL_PATH" -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
24 say 'skipping git-cvsserver tests, Perl SQLite interface unavailable'
28 unset GIT_DIR GIT_CONFIG
30 SERVERDIR=$(pwd)/gitcvs.git
31 git_config="$SERVERDIR/config"
32 CVSROOT=":fork:$SERVERDIR"
33 CVSWORK="$(pwd)/cvswork"
34 CVS_SERVER=git-cvsserver
35 export CVSROOT CVS_SERVER
37 rm -rf "$CVSWORK" "$SERVERDIR"
38 test_expect_success 'setup' '
41 git commit -q -m "First Commit" &&
45 touch secondrootfile &&
46 git add secondrootfile &&
47 git commit -m "second root") &&
48 git pull secondroot master &&
49 git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
50 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
51 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log"
54 # note that cvs doesn't accept absolute pathnames
55 # as argument to co -d
56 test_expect_success 'basic checkout' \
57 'GIT_CONFIG="$git_config" cvs -Q co -d cvswork master &&
58 test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | head -n 1))" = "empty/1.1/"
59 test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | sed -ne \$p))" = "secondrootfile/1.1/"'
61 #------------------------
62 # PSERVER AUTHENTICATION
63 #------------------------
65 cat >request-anonymous <<EOF
73 cat >request-git <<EOF
81 cat >login-anonymous <<EOF
82 BEGIN VERIFICATION REQUEST
86 END VERIFICATION REQUEST
90 BEGIN VERIFICATION REQUEST
94 END VERIFICATION REQUEST
97 test_expect_success 'pserver authentication' \
98 'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
99 sed -ne \$p log | grep "^I LOVE YOU\$"'
101 test_expect_success 'pserver authentication failure (non-anonymous user)' \
102 'if cat request-git | git-cvsserver pserver >log 2>&1
108 sed -ne \$p log | grep "^I HATE YOU\$"'
110 test_expect_success 'pserver authentication (login)' \
111 'cat login-anonymous | git-cvsserver pserver >log 2>&1 &&
112 sed -ne \$p log | grep "^I LOVE YOU\$"'
114 test_expect_success 'pserver authentication failure (login/non-anonymous user)' \
115 'if cat login-git | git-cvsserver pserver >log 2>&1
121 sed -ne \$p log | grep "^I HATE YOU\$"'
124 # misuse pserver authentication for testing of req_Root
126 cat >request-relative <<EOF
134 cat >request-conflict <<EOF
143 test_expect_success 'req_Root failure (relative pathname)' \
144 'if cat request-relative | git-cvsserver pserver >log 2>&1
146 echo unexpected success
151 tail log | grep "^error 1 Root must be an absolute pathname$"'
153 test_expect_success 'req_Root failure (conflicting roots)' \
154 'cat request-conflict | git-cvsserver pserver >log 2>&1 &&
155 tail log | grep "^error 1 Conflicting roots specified$"'
157 test_expect_success 'req_Root (strict paths)' \
158 'cat request-anonymous | git-cvsserver --strict-paths pserver "$SERVERDIR" >log 2>&1 &&
159 sed -ne \$p log | grep "^I LOVE YOU\$"'
161 test_expect_success 'req_Root failure (strict-paths)' '
162 ! cat request-anonymous |
163 git-cvsserver --strict-paths pserver "$WORKDIR" >log 2>&1
166 test_expect_success 'req_Root (w/o strict-paths)' \
167 'cat request-anonymous | git-cvsserver pserver "$WORKDIR/" >log 2>&1 &&
168 sed -ne \$p log | grep "^I LOVE YOU\$"'
170 test_expect_success 'req_Root failure (w/o strict-paths)' '
171 ! cat request-anonymous |
172 git-cvsserver pserver "$WORKDIR/gitcvs" >log 2>&1
175 cat >request-base <<EOF
184 test_expect_success 'req_Root (base-path)' \
185 'cat request-base | git-cvsserver --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
186 sed -ne \$p log | grep "^I LOVE YOU\$"'
188 test_expect_success 'req_Root failure (base-path)' '
189 ! cat request-anonymous |
190 git-cvsserver --strict-paths --base-path "$WORKDIR" pserver "$SERVERDIR" >log 2>&1
193 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false || exit 1
195 test_expect_success 'req_Root (export-all)' \
196 'cat request-anonymous | git-cvsserver --export-all pserver "$WORKDIR" >log 2>&1 &&
197 sed -ne \$p log | grep "^I LOVE YOU\$"'
199 test_expect_success 'req_Root failure (export-all w/o whitelist)' \
200 '! (cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 || false)'
202 test_expect_success 'req_Root (everything together)' \
203 'cat request-base | git-cvsserver --export-all --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
204 sed -ne \$p log | grep "^I LOVE YOU\$"'
206 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true || exit 1
212 test_expect_success 'gitcvs.enabled = false' \
213 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
214 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
216 echo unexpected cvs success
221 grep "GITCVS emulation disabled" cvs.log &&
225 test_expect_success 'gitcvs.ext.enabled = true' \
226 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
227 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
228 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
229 diff -q cvswork cvswork2'
232 test_expect_success 'gitcvs.ext.enabled = false' \
233 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
234 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
235 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
237 echo unexpected cvs success
242 grep "GITCVS emulation disabled" cvs.log &&
246 test_expect_success 'gitcvs.dbname' \
247 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
248 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
249 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
250 diff -q cvswork cvswork2 &&
251 test -f "$SERVERDIR/gitcvs.ext.master.sqlite" &&
252 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs.ext.master.sqlite"'
255 test_expect_success 'gitcvs.ext.dbname' \
256 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
257 GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
258 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
259 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
260 diff -q cvswork cvswork2 &&
261 test -f "$SERVERDIR/gitcvs1.ext.master.sqlite" &&
262 test ! -f "$SERVERDIR/gitcvs2.ext.master.sqlite" &&
263 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs1.ext.master.sqlite"'
272 git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
273 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
274 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
277 test_expect_success 'cvs update (create new file)' \
278 'echo testfile1 >testfile1 &&
280 git commit -q -m "Add testfile1" &&
281 git push gitcvs.git >/dev/null &&
283 GIT_CONFIG="$git_config" cvs -Q update &&
284 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
285 diff -q testfile1 ../testfile1'
288 test_expect_success 'cvs update (update existing file)' \
289 'echo line 2 >>testfile1 &&
291 git commit -q -m "Append to testfile1" &&
292 git push gitcvs.git >/dev/null &&
294 GIT_CONFIG="$git_config" cvs -Q update &&
295 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
296 diff -q testfile1 ../testfile1'
299 #TODO: cvsserver doesn't support update w/o -d
300 test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" '
304 git commit -q -m "Single Subdirectory" &&
305 git push gitcvs.git >/dev/null &&
307 GIT_CONFIG="$git_config" cvs -Q update &&
312 test_expect_success 'cvs update (subdirectories)' \
313 '(for dir in A A/B A/B/C A/D E; do
315 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
318 git commit -q -m "deep sub directory structure" &&
319 git push gitcvs.git >/dev/null &&
321 GIT_CONFIG="$git_config" cvs -Q update -d &&
322 (for dir in A A/B A/B/C A/D E; do
323 filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
324 if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
325 diff -q "$dir/$filename" "../$dir/$filename"; then
334 test_expect_success 'cvs update (delete file)' \
336 git commit -q -m "Remove testfile1" &&
337 git push gitcvs.git >/dev/null &&
339 GIT_CONFIG="$git_config" cvs -Q update &&
340 test -z "$(grep testfile1 CVS/Entries)" &&
344 test_expect_success 'cvs update (re-add deleted file)' \
345 'echo readded testfile >testfile1 &&
347 git commit -q -m "Re-Add testfile1" &&
348 git push gitcvs.git >/dev/null &&
350 GIT_CONFIG="$git_config" cvs -Q update &&
351 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
352 diff -q testfile1 ../testfile1'
355 test_expect_success 'cvs update (merge)' \
356 'echo Line 0 >expected &&
357 for i in 1 2 3 4 5 6 7
360 echo Line $i >>expected
362 echo Line 8 >>expected &&
364 git commit -q -m "Merge test (pre-merge)" &&
365 git push gitcvs.git >/dev/null &&
367 GIT_CONFIG="$git_config" cvs -Q update &&
368 test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
369 diff -q merge ../merge &&
370 ( echo Line 0; cat merge ) >merge.tmp &&
371 mv merge.tmp merge &&
373 echo Line 8 >>merge &&
375 git commit -q -m "Merge test (merge)" &&
376 git push gitcvs.git >/dev/null &&
378 sleep 1 && touch merge &&
379 GIT_CONFIG="$git_config" cvs -Q update &&
380 diff -q merge ../expected'
384 cat >expected.C <<EOF
392 for i in 1 2 3 4 5 6 7 8
394 echo Line $i >>expected.C
397 test_expect_success 'cvs update (conflict merge)' \
398 '( echo LINE 0; cat merge ) >merge.tmp &&
399 mv merge.tmp merge &&
401 git commit -q -m "Merge test (conflict)" &&
402 git push gitcvs.git >/dev/null &&
404 GIT_CONFIG="$git_config" cvs -Q update &&
405 diff -q merge ../expected.C'
408 test_expect_success 'cvs update (-C)' \
410 GIT_CONFIG="$git_config" cvs -Q update -C &&
411 diff -q merge ../merge'
414 test_expect_success 'cvs update (merge no-op)' \
415 'echo Line 9 >>merge &&
416 cp merge cvswork/merge &&
418 git commit -q -m "Merge test (no-op)" &&
419 git push gitcvs.git >/dev/null &&
421 sleep 1 && touch merge &&
422 GIT_CONFIG="$git_config" cvs -Q update &&
423 diff -q merge ../merge'
426 test_expect_success 'cvs update (-p)' '
427 touch really-empty &&
428 echo Line 1 > no-lf &&
429 printf "Line 2" >> no-lf &&
430 git add really-empty no-lf &&
431 git commit -q -m "Update -p test" &&
432 git push gitcvs.git >/dev/null &&
434 GIT_CONFIG="$git_config" cvs update &&
436 for i in merge no-lf empty really-empty; do
437 GIT_CONFIG="$git_config" cvs update -p "$i" >$i.out
438 diff $i.out ../$i >>failures 2>&1
440 test -z "$(cat failures)"
444 test_expect_success 'cvs update (module list supports packed refs)' '
445 GIT_DIR="$SERVERDIR" git pack-refs --all &&
446 GIT_CONFIG="$git_config" cvs -n up -d 2> out &&
447 grep "cvs update: New directory \`master'\''" < out
455 test_expect_success 'cvs status' '
457 echo Line > status.dir/status.file &&
458 echo Line > status.file &&
459 git add status.dir status.file &&
460 git commit -q -m "Status test" &&
461 git push gitcvs.git >/dev/null &&
463 GIT_CONFIG="$git_config" cvs update &&
464 GIT_CONFIG="$git_config" cvs status | grep "^File: status.file" >../out &&
465 test $(wc -l <../out) = 2
469 test_expect_success 'cvs status (nonrecursive)' '
471 GIT_CONFIG="$git_config" cvs status -l | grep "^File: status.file" >../out &&
472 test $(wc -l <../out) = 1
476 test_expect_success 'cvs status (no subdirs in header)' '
478 GIT_CONFIG="$git_config" cvs status | grep ^File: >../out &&
487 test_expect_success 'cvs co -c (shows module database)' '
488 GIT_CONFIG="$git_config" cvs co -c > out &&
489 grep "^master[ ]\+master$" < out &&
490 ! grep -v "^master[ ]\+master$" < out
498 test_expect_success 'cvs annotate' '
500 GIT_CONFIG="$git_config" cvs annotate merge >../out &&
501 sed -e "s/ .*//" ../out >../actual &&
502 for i in 3 1 1 1 1 1 1 1 2 4; do echo 1.$i; done >../expect &&
503 test_cmp ../expect ../actual