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 test_expect_success
'skipping git-cvsserver tests, cvs not found' :
20 perl
-e 'use DBI; use DBD::SQLite' >/dev
/null
2>&1 ||
{
21 test_expect_success
'skipping git-cvsserver tests, Perl SQLite interface unavailable' :
26 unset GIT_DIR GIT_CONFIG
28 SERVERDIR
=$
(pwd)/gitcvs.git
29 git_config
="$SERVERDIR/config"
30 CVSROOT
=":fork:$SERVERDIR"
31 CVSWORK
="$(pwd)/cvswork"
32 CVS_SERVER
=git-cvsserver
33 export CVSROOT CVS_SERVER
35 rm -rf "$CVSWORK" "$SERVERDIR"
36 test_expect_success
'setup' '
39 git commit -q -m "First Commit" &&
43 touch secondrootfile &&
44 git add secondrootfile &&
45 git commit -m "second root") &&
46 git pull secondroot master &&
47 git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
48 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
49 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log"
52 # note that cvs doesn't accept absolute pathnames
53 # as argument to co -d
54 test_expect_success
'basic checkout' \
55 'GIT_CONFIG="$git_config" cvs -Q co -d cvswork master &&
56 test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | head -n 1))" = "empty/1.1/"
57 test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | sed -ne \$p))" = "secondrootfile/1.1/"'
59 #------------------------
60 # PSERVER AUTHENTICATION
61 #------------------------
63 cat >request-anonymous
<<EOF
71 cat >request-git
<<EOF
79 cat >login-anonymous
<<EOF
80 BEGIN VERIFICATION REQUEST
84 END VERIFICATION REQUEST
88 BEGIN VERIFICATION REQUEST
92 END VERIFICATION REQUEST
95 test_expect_success
'pserver authentication' \
96 'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
97 sed -ne \$p log | grep "^I LOVE YOU$"'
99 test_expect_success
'pserver authentication failure (non-anonymous user)' \
100 'if cat request-git | git-cvsserver pserver >log 2>&1
106 sed -ne \$p log | grep "^I HATE YOU$"'
108 test_expect_success
'pserver authentication (login)' \
109 'cat login-anonymous | git-cvsserver pserver >log 2>&1 &&
110 sed -ne \$p log | grep "^I LOVE YOU$"'
112 test_expect_success
'pserver authentication failure (login/non-anonymous user)' \
113 'if cat login-git | git-cvsserver pserver >log 2>&1
119 sed -ne \$p log | grep "^I HATE YOU$"'
122 # misuse pserver authentication for testing of req_Root
124 cat >request-relative
<<EOF
132 cat >request-conflict
<<EOF
141 test_expect_success
'req_Root failure (relative pathname)' \
142 'if cat request-relative | git-cvsserver pserver >log 2>&1
144 echo unexpected success
149 tail log | grep "^error 1 Root must be an absolute pathname$"'
151 test_expect_success
'req_Root failure (conflicting roots)' \
152 'cat request-conflict | git-cvsserver pserver >log 2>&1 &&
153 tail log | grep "^error 1 Conflicting roots specified$"'
155 test_expect_success
'req_Root (strict paths)' \
156 'cat request-anonymous | git-cvsserver --strict-paths pserver "$SERVERDIR" >log 2>&1 &&
157 sed -ne \$p log | grep "^I LOVE YOU$"'
159 test_expect_success
'req_Root failure (strict-paths)' '
160 ! cat request-anonymous |
161 git-cvsserver --strict-paths pserver "$WORKDIR" >log 2>&1
164 test_expect_success
'req_Root (w/o strict-paths)' \
165 'cat request-anonymous | git-cvsserver pserver "$WORKDIR/" >log 2>&1 &&
166 sed -ne \$p log | grep "^I LOVE YOU$"'
168 test_expect_success
'req_Root failure (w/o strict-paths)' '
169 ! cat request-anonymous |
170 git-cvsserver pserver "$WORKDIR/gitcvs" >log 2>&1
173 cat >request-base
<<EOF
182 test_expect_success
'req_Root (base-path)' \
183 'cat request-base | git-cvsserver --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
184 sed -ne \$p log | grep "^I LOVE YOU$"'
186 test_expect_success
'req_Root failure (base-path)' '
187 ! cat request-anonymous |
188 git-cvsserver --strict-paths --base-path "$WORKDIR" pserver "$SERVERDIR" >log 2>&1
191 GIT_DIR
="$SERVERDIR" git config
--bool gitcvs.enabled false ||
exit 1
193 test_expect_success
'req_Root (export-all)' \
194 'cat request-anonymous | git-cvsserver --export-all pserver "$WORKDIR" >log 2>&1 &&
195 sed -ne \$p log | grep "^I LOVE YOU$"'
197 test_expect_success
'req_Root failure (export-all w/o whitelist)' \
198 '! (cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 || false)'
200 test_expect_success
'req_Root (everything together)' \
201 'cat request-base | git-cvsserver --export-all --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
202 sed -ne \$p log | grep "^I LOVE YOU$"'
204 GIT_DIR
="$SERVERDIR" git config
--bool gitcvs.enabled true ||
exit 1
210 test_expect_success
'gitcvs.enabled = false' \
211 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
212 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
214 echo unexpected cvs success
219 grep "GITCVS emulation disabled" cvs.log &&
223 test_expect_success
'gitcvs.ext.enabled = true' \
224 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
225 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
226 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
227 diff -q cvswork cvswork2'
230 test_expect_success
'gitcvs.ext.enabled = false' \
231 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
232 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
233 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
235 echo unexpected cvs success
240 grep "GITCVS emulation disabled" cvs.log &&
244 test_expect_success
'gitcvs.dbname' \
245 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
246 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
247 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
248 diff -q cvswork cvswork2 &&
249 test -f "$SERVERDIR/gitcvs.ext.master.sqlite" &&
250 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs.ext.master.sqlite"'
253 test_expect_success
'gitcvs.ext.dbname' \
254 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
255 GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
256 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
257 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
258 diff -q cvswork cvswork2 &&
259 test -f "$SERVERDIR/gitcvs1.ext.master.sqlite" &&
260 test ! -f "$SERVERDIR/gitcvs2.ext.master.sqlite" &&
261 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs1.ext.master.sqlite"'
270 git clone
-q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev
/null
2>&1 &&
271 GIT_DIR
="$SERVERDIR" git config
--bool gitcvs.enabled true
&&
272 GIT_DIR
="$SERVERDIR" git config gitcvs.logfile
"$SERVERDIR/gitcvs.log" ||
275 test_expect_success
'cvs update (create new file)' \
276 'echo testfile1 >testfile1 &&
278 git commit -q -m "Add testfile1" &&
279 git push gitcvs.git >/dev/null &&
281 GIT_CONFIG="$git_config" cvs -Q update &&
282 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
283 diff -q testfile1 ../testfile1'
286 test_expect_success
'cvs update (update existing file)' \
287 'echo line 2 >>testfile1 &&
289 git commit -q -m "Append to testfile1" &&
290 git push gitcvs.git >/dev/null &&
292 GIT_CONFIG="$git_config" cvs -Q update &&
293 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
294 diff -q testfile1 ../testfile1'
297 #TODO: cvsserver doesn't support update w/o -d
298 test_expect_failure
"cvs update w/o -d doesn't create subdir (TODO)" '
302 git commit -q -m "Single Subdirectory" &&
303 git push gitcvs.git >/dev/null &&
305 GIT_CONFIG="$git_config" cvs -Q update &&
310 test_expect_success
'cvs update (subdirectories)' \
311 '(for dir in A A/B A/B/C A/D E; do
313 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
316 git commit -q -m "deep sub directory structure" &&
317 git push gitcvs.git >/dev/null &&
319 GIT_CONFIG="$git_config" cvs -Q update -d &&
320 (for dir in A A/B A/B/C A/D E; do
321 filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
322 if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
323 diff -q "$dir/$filename" "../$dir/$filename"; then
332 test_expect_success
'cvs update (delete file)' \
334 git commit -q -m "Remove testfile1" &&
335 git push gitcvs.git >/dev/null &&
337 GIT_CONFIG="$git_config" cvs -Q update &&
338 test -z "$(grep testfile1 CVS/Entries)" &&
342 test_expect_success
'cvs update (re-add deleted file)' \
343 'echo readded testfile >testfile1 &&
345 git commit -q -m "Re-Add testfile1" &&
346 git push gitcvs.git >/dev/null &&
348 GIT_CONFIG="$git_config" cvs -Q update &&
349 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
350 diff -q testfile1 ../testfile1'
353 test_expect_success
'cvs update (merge)' \
354 'echo Line 0 >expected &&
355 for i in 1 2 3 4 5 6 7
358 echo Line $i >>expected
360 echo Line 8 >>expected &&
362 git commit -q -m "Merge test (pre-merge)" &&
363 git push gitcvs.git >/dev/null &&
365 GIT_CONFIG="$git_config" cvs -Q update &&
366 test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
367 diff -q merge ../merge &&
368 ( echo Line 0; cat merge ) >merge.tmp &&
369 mv merge.tmp merge &&
371 echo Line 8 >>merge &&
373 git commit -q -m "Merge test (merge)" &&
374 git push gitcvs.git >/dev/null &&
376 sleep 1 && touch merge &&
377 GIT_CONFIG="$git_config" cvs -Q update &&
378 diff -q merge ../expected'
382 cat >expected.C
<<EOF
390 for i
in 1 2 3 4 5 6 7 8
392 echo Line
$i >>expected.C
395 test_expect_success
'cvs update (conflict merge)' \
396 '( echo LINE 0; cat merge ) >merge.tmp &&
397 mv merge.tmp merge &&
399 git commit -q -m "Merge test (conflict)" &&
400 git push gitcvs.git >/dev/null &&
402 GIT_CONFIG="$git_config" cvs -Q update &&
403 diff -q merge ../expected.C'
406 test_expect_success
'cvs update (-C)' \
408 GIT_CONFIG="$git_config" cvs -Q update -C &&
409 diff -q merge ../merge'
412 test_expect_success
'cvs update (merge no-op)' \
413 'echo Line 9 >>merge &&
414 cp merge cvswork/merge &&
416 git commit -q -m "Merge test (no-op)" &&
417 git push gitcvs.git >/dev/null &&
419 sleep 1 && touch merge &&
420 GIT_CONFIG="$git_config" cvs -Q update &&
421 diff -q merge ../merge'
424 test_expect_success
'cvs update (-p)' '
425 touch really-empty &&
426 echo Line 1 > no-lf &&
427 echo -n Line 2 >> no-lf &&
428 git add really-empty no-lf &&
429 git commit -q -m "Update -p test" &&
430 git push gitcvs.git >/dev/null &&
432 GIT_CONFIG="$git_config" cvs update &&
434 for i in merge no-lf empty really-empty; do
435 GIT_CONFIG="$git_config" cvs update -p "$i" >$i.out
436 diff $i.out ../$i >>failures 2>&1
438 test -z "$(cat failures)"
446 test_expect_success
'cvs status' '
448 echo Line > status.dir/status.file &&
449 echo Line > status.file &&
450 git add status.dir status.file &&
451 git commit -q -m "Status test" &&
452 git push gitcvs.git >/dev/null &&
454 GIT_CONFIG="$git_config" cvs update &&
455 GIT_CONFIG="$git_config" cvs status | grep "^File: status.file" >../out &&
456 test $(wc -l <../out) = 2
460 test_expect_success
'cvs status (nonrecursive)' '
462 GIT_CONFIG="$git_config" cvs status -l | grep "^File: status.file" >../out &&
463 test $(wc -l <../out) = 1
467 test_expect_success
'cvs status (no subdirs in header)' '
469 GIT_CONFIG="$git_config" cvs status | grep ^File: >../out &&
478 test_expect_success
'cvs co -c (shows module database)' '
479 GIT_CONFIG="$git_config" cvs co -c > out &&
480 grep "^master[ ]\+master$" < out &&
481 ! grep -v "^master[ ]\+master$" < out