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'
16 say
'skipping git-cvsserver tests, cvs not found'
19 perl
-e 'use DBI; use DBD::SQLite' >/dev
/null
2>&1 ||
{
20 say
'skipping git-cvsserver tests, Perl SQLite interface unavailable'
24 unset GIT_DIR GIT_CONFIG
26 SERVERDIR
=$
(pwd)/gitcvs.git
27 git_config
="$SERVERDIR/config"
28 CVSROOT
=":fork:$SERVERDIR"
29 CVSWORK
="$(pwd)/cvswork"
30 CVS_SERVER
=git-cvsserver
31 export CVSROOT CVS_SERVER
33 rm -rf "$CVSWORK" "$SERVERDIR"
34 test_expect_success
'setup' '
37 git commit -q -m "First Commit" &&
41 touch secondrootfile &&
42 git add secondrootfile &&
43 git commit -m "second root") &&
44 git pull secondroot master &&
45 git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
46 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
47 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log"
50 # note that cvs doesn't accept absolute pathnames
51 # as argument to co -d
52 test_expect_success
'basic checkout' \
53 'GIT_CONFIG="$git_config" cvs -Q co -d cvswork master &&
54 test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | head -n 1))" = "empty/1.1/"
55 test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | sed -ne \$p))" = "secondrootfile/1.1/"'
57 #------------------------
58 # PSERVER AUTHENTICATION
59 #------------------------
61 cat >request-anonymous
<<EOF
69 cat >request-git
<<EOF
77 cat >login-anonymous
<<EOF
78 BEGIN VERIFICATION REQUEST
82 END VERIFICATION REQUEST
86 BEGIN VERIFICATION REQUEST
90 END VERIFICATION REQUEST
93 test_expect_success
'pserver authentication' \
94 'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
95 sed -ne \$p log | grep "^I LOVE YOU$"'
97 test_expect_success
'pserver authentication failure (non-anonymous user)' \
98 'if cat request-git | git-cvsserver pserver >log 2>&1
104 sed -ne \$p log | grep "^I HATE YOU$"'
106 test_expect_success
'pserver authentication (login)' \
107 'cat login-anonymous | git-cvsserver pserver >log 2>&1 &&
108 sed -ne \$p log | grep "^I LOVE YOU$"'
110 test_expect_success
'pserver authentication failure (login/non-anonymous user)' \
111 'if cat login-git | git-cvsserver pserver >log 2>&1
117 sed -ne \$p log | grep "^I HATE YOU$"'
120 # misuse pserver authentication for testing of req_Root
122 cat >request-relative
<<EOF
130 cat >request-conflict
<<EOF
139 test_expect_success
'req_Root failure (relative pathname)' \
140 'if cat request-relative | git-cvsserver pserver >log 2>&1
142 echo unexpected success
147 tail log | grep "^error 1 Root must be an absolute pathname$"'
149 test_expect_success
'req_Root failure (conflicting roots)' \
150 'cat request-conflict | git-cvsserver pserver >log 2>&1 &&
151 tail log | grep "^error 1 Conflicting roots specified$"'
153 test_expect_success
'req_Root (strict paths)' \
154 'cat request-anonymous | git-cvsserver --strict-paths pserver "$SERVERDIR" >log 2>&1 &&
155 sed -ne \$p log | grep "^I LOVE YOU$"'
157 test_expect_success
'req_Root failure (strict-paths)' '
158 ! cat request-anonymous |
159 git-cvsserver --strict-paths pserver "$WORKDIR" >log 2>&1
162 test_expect_success
'req_Root (w/o strict-paths)' \
163 'cat request-anonymous | git-cvsserver pserver "$WORKDIR/" >log 2>&1 &&
164 sed -ne \$p log | grep "^I LOVE YOU$"'
166 test_expect_success
'req_Root failure (w/o strict-paths)' '
167 ! cat request-anonymous |
168 git-cvsserver pserver "$WORKDIR/gitcvs" >log 2>&1
171 cat >request-base
<<EOF
180 test_expect_success
'req_Root (base-path)' \
181 'cat request-base | git-cvsserver --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
182 sed -ne \$p log | grep "^I LOVE YOU$"'
184 test_expect_success
'req_Root failure (base-path)' '
185 ! cat request-anonymous |
186 git-cvsserver --strict-paths --base-path "$WORKDIR" pserver "$SERVERDIR" >log 2>&1
189 GIT_DIR
="$SERVERDIR" git config
--bool gitcvs.enabled false ||
exit 1
191 test_expect_success
'req_Root (export-all)' \
192 'cat request-anonymous | git-cvsserver --export-all pserver "$WORKDIR" >log 2>&1 &&
193 sed -ne \$p log | grep "^I LOVE YOU$"'
195 test_expect_success
'req_Root failure (export-all w/o whitelist)' \
196 '! (cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 || false)'
198 test_expect_success
'req_Root (everything together)' \
199 'cat request-base | git-cvsserver --export-all --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
200 sed -ne \$p log | grep "^I LOVE YOU$"'
202 GIT_DIR
="$SERVERDIR" git config
--bool gitcvs.enabled true ||
exit 1
208 test_expect_success
'gitcvs.enabled = false' \
209 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
210 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
212 echo unexpected cvs success
217 grep "GITCVS emulation disabled" cvs.log &&
221 test_expect_success
'gitcvs.ext.enabled = true' \
222 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
223 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
224 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
225 diff -q cvswork cvswork2'
228 test_expect_success
'gitcvs.ext.enabled = false' \
229 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
230 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
231 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
233 echo unexpected cvs success
238 grep "GITCVS emulation disabled" cvs.log &&
242 test_expect_success
'gitcvs.dbname' \
243 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
244 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
245 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
246 diff -q cvswork cvswork2 &&
247 test -f "$SERVERDIR/gitcvs.ext.master.sqlite" &&
248 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs.ext.master.sqlite"'
251 test_expect_success
'gitcvs.ext.dbname' \
252 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
253 GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
254 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
255 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
256 diff -q cvswork cvswork2 &&
257 test -f "$SERVERDIR/gitcvs1.ext.master.sqlite" &&
258 test ! -f "$SERVERDIR/gitcvs2.ext.master.sqlite" &&
259 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs1.ext.master.sqlite"'
268 git clone
-q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev
/null
2>&1 &&
269 GIT_DIR
="$SERVERDIR" git config
--bool gitcvs.enabled true
&&
270 GIT_DIR
="$SERVERDIR" git config gitcvs.logfile
"$SERVERDIR/gitcvs.log" ||
273 test_expect_success
'cvs update (create new file)' \
274 'echo testfile1 >testfile1 &&
276 git commit -q -m "Add testfile1" &&
277 git push gitcvs.git >/dev/null &&
279 GIT_CONFIG="$git_config" cvs -Q update &&
280 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
281 diff -q testfile1 ../testfile1'
284 test_expect_success
'cvs update (update existing file)' \
285 'echo line 2 >>testfile1 &&
287 git commit -q -m "Append to testfile1" &&
288 git push gitcvs.git >/dev/null &&
290 GIT_CONFIG="$git_config" cvs -Q update &&
291 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
292 diff -q testfile1 ../testfile1'
295 #TODO: cvsserver doesn't support update w/o -d
296 test_expect_failure
"cvs update w/o -d doesn't create subdir (TODO)" '
300 git commit -q -m "Single Subdirectory" &&
301 git push gitcvs.git >/dev/null &&
303 GIT_CONFIG="$git_config" cvs -Q update &&
308 test_expect_success
'cvs update (subdirectories)' \
309 '(for dir in A A/B A/B/C A/D E; do
311 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
314 git commit -q -m "deep sub directory structure" &&
315 git push gitcvs.git >/dev/null &&
317 GIT_CONFIG="$git_config" cvs -Q update -d &&
318 (for dir in A A/B A/B/C A/D E; do
319 filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
320 if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
321 diff -q "$dir/$filename" "../$dir/$filename"; then
330 test_expect_success
'cvs update (delete file)' \
332 git commit -q -m "Remove testfile1" &&
333 git push gitcvs.git >/dev/null &&
335 GIT_CONFIG="$git_config" cvs -Q update &&
336 test -z "$(grep testfile1 CVS/Entries)" &&
340 test_expect_success
'cvs update (re-add deleted file)' \
341 'echo readded testfile >testfile1 &&
343 git commit -q -m "Re-Add testfile1" &&
344 git push gitcvs.git >/dev/null &&
346 GIT_CONFIG="$git_config" cvs -Q update &&
347 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
348 diff -q testfile1 ../testfile1'
351 test_expect_success
'cvs update (merge)' \
352 'echo Line 0 >expected &&
353 for i in 1 2 3 4 5 6 7
356 echo Line $i >>expected
358 echo Line 8 >>expected &&
360 git commit -q -m "Merge test (pre-merge)" &&
361 git push gitcvs.git >/dev/null &&
363 GIT_CONFIG="$git_config" cvs -Q update &&
364 test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
365 diff -q merge ../merge &&
366 ( echo Line 0; cat merge ) >merge.tmp &&
367 mv merge.tmp merge &&
369 echo Line 8 >>merge &&
371 git commit -q -m "Merge test (merge)" &&
372 git push gitcvs.git >/dev/null &&
374 sleep 1 && touch merge &&
375 GIT_CONFIG="$git_config" cvs -Q update &&
376 diff -q merge ../expected'
380 cat >expected.C
<<EOF
388 for i
in 1 2 3 4 5 6 7 8
390 echo Line
$i >>expected.C
393 test_expect_success
'cvs update (conflict merge)' \
394 '( echo LINE 0; cat merge ) >merge.tmp &&
395 mv merge.tmp merge &&
397 git commit -q -m "Merge test (conflict)" &&
398 git push gitcvs.git >/dev/null &&
400 GIT_CONFIG="$git_config" cvs -Q update &&
401 diff -q merge ../expected.C'
404 test_expect_success
'cvs update (-C)' \
406 GIT_CONFIG="$git_config" cvs -Q update -C &&
407 diff -q merge ../merge'
410 test_expect_success
'cvs update (merge no-op)' \
411 'echo Line 9 >>merge &&
412 cp merge cvswork/merge &&
414 git commit -q -m "Merge test (no-op)" &&
415 git push gitcvs.git >/dev/null &&
417 sleep 1 && touch merge &&
418 GIT_CONFIG="$git_config" cvs -Q update &&
419 diff -q merge ../merge'
422 test_expect_success
'cvs update (-p)' '
423 touch really-empty &&
424 echo Line 1 > no-lf &&
425 printf "Line 2" >> no-lf &&
426 git add really-empty no-lf &&
427 git commit -q -m "Update -p test" &&
428 git push gitcvs.git >/dev/null &&
430 GIT_CONFIG="$git_config" cvs update &&
432 for i in merge no-lf empty really-empty; do
433 GIT_CONFIG="$git_config" cvs update -p "$i" >$i.out
434 diff $i.out ../$i >>failures 2>&1
436 test -z "$(cat failures)"
440 test_expect_success
'cvs update (module list supports packed refs)' '
441 GIT_DIR="$SERVERDIR" git pack-refs --all &&
442 GIT_CONFIG="$git_config" cvs -n up -d 2> out &&
443 grep "cvs update: New directory \`master'\''" < out
451 test_expect_success
'cvs status' '
453 echo Line > status.dir/status.file &&
454 echo Line > status.file &&
455 git add status.dir status.file &&
456 git commit -q -m "Status test" &&
457 git push gitcvs.git >/dev/null &&
459 GIT_CONFIG="$git_config" cvs update &&
460 GIT_CONFIG="$git_config" cvs status | grep "^File: status.file" >../out &&
461 test $(wc -l <../out) = 2
465 test_expect_success
'cvs status (nonrecursive)' '
467 GIT_CONFIG="$git_config" cvs status -l | grep "^File: status.file" >../out &&
468 test $(wc -l <../out) = 1
472 test_expect_success
'cvs status (no subdirs in header)' '
474 GIT_CONFIG="$git_config" cvs status | grep ^File: >../out &&
483 test_expect_success
'cvs co -c (shows module database)' '
484 GIT_CONFIG="$git_config" cvs co -c > out &&
485 grep "^master[ ]\+master$" < out &&
486 ! grep -v "^master[ ]\+master$" < out
494 test_expect_success
'cvs annotate' '
496 GIT_CONFIG="$git_config" cvs annotate merge >../out &&
497 sed -e "s/ .*//" ../out >../actual &&
498 for i in 3 1 1 1 1 1 1 1 2 4; do echo 1.$i; done >../expect &&
499 test_cmp ../expect ../actual