make get_short_ref a public function
[git/spearce.git] / t / t9400-git-cvsserver-server.sh
blob39185db6c962ee95caf35cc5ad9d26f228224f44
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 . ./test-lib.sh
13 cvs >/dev/null 2>&1
14 if test $? -ne 1
15 then
16 say 'skipping git-cvsserver tests, cvs not found'
17 test_done
19 perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
20 say 'skipping git-cvsserver tests, Perl SQLite interface unavailable'
21 test_done
24 unset GIT_DIR GIT_CONFIG
25 WORKDIR=$(pwd)
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' '
35 echo >empty &&
36 git add empty &&
37 git commit -q -m "First Commit" &&
38 mkdir secondroot &&
39 ( cd secondroot &&
40 git init &&
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
62 BEGIN AUTH REQUEST
63 $SERVERDIR
64 anonymous
66 END AUTH REQUEST
67 EOF
69 cat >request-git <<EOF
70 BEGIN AUTH REQUEST
71 $SERVERDIR
72 git
74 END AUTH REQUEST
75 EOF
77 cat >login-anonymous <<EOF
78 BEGIN VERIFICATION REQUEST
79 $SERVERDIR
80 anonymous
82 END VERIFICATION REQUEST
83 EOF
85 cat >login-git <<EOF
86 BEGIN VERIFICATION REQUEST
87 $SERVERDIR
88 git
90 END VERIFICATION REQUEST
91 EOF
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
99 then
100 false
101 else
102 true
103 fi &&
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
112 then
113 false
114 else
115 true
116 fi &&
117 sed -ne \$p log | grep "^I HATE YOU$"'
120 # misuse pserver authentication for testing of req_Root
122 cat >request-relative <<EOF
123 BEGIN AUTH REQUEST
124 gitcvs.git
125 anonymous
127 END AUTH REQUEST
130 cat >request-conflict <<EOF
131 BEGIN AUTH REQUEST
132 $SERVERDIR
133 anonymous
135 END AUTH REQUEST
136 Root $WORKDIR
139 test_expect_success 'req_Root failure (relative pathname)' \
140 'if cat request-relative | git-cvsserver pserver >log 2>&1
141 then
142 echo unexpected success
143 false
144 else
145 true
146 fi &&
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
172 BEGIN AUTH REQUEST
173 /gitcvs.git
174 anonymous
176 END AUTH REQUEST
177 Root /gitcvs.git
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
204 #--------------
205 # CONFIG TESTS
206 #--------------
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
211 then
212 echo unexpected cvs success
213 false
214 else
215 true
216 fi &&
217 grep "GITCVS emulation disabled" cvs.log &&
218 test ! -d cvswork2'
220 rm -fr cvswork2
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'
227 rm -fr 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
232 then
233 echo unexpected cvs success
234 false
235 else
236 true
237 fi &&
238 grep "GITCVS emulation disabled" cvs.log &&
239 test ! -d cvswork2'
241 rm -fr cvswork2
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"'
250 rm -fr cvswork2
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"'
262 #------------
263 # CVS UPDATE
264 #------------
266 rm -fr "$SERVERDIR"
267 cd "$WORKDIR" &&
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" ||
271 exit 1
273 test_expect_success 'cvs update (create new file)' \
274 'echo testfile1 >testfile1 &&
275 git add testfile1 &&
276 git commit -q -m "Add testfile1" &&
277 git push gitcvs.git >/dev/null &&
278 cd cvswork &&
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'
283 cd "$WORKDIR"
284 test_expect_success 'cvs update (update existing file)' \
285 'echo line 2 >>testfile1 &&
286 git add testfile1 &&
287 git commit -q -m "Append to testfile1" &&
288 git push gitcvs.git >/dev/null &&
289 cd cvswork &&
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'
294 cd "$WORKDIR"
295 #TODO: cvsserver doesn't support update w/o -d
296 test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" '
297 mkdir test &&
298 echo >test/empty &&
299 git add test &&
300 git commit -q -m "Single Subdirectory" &&
301 git push gitcvs.git >/dev/null &&
302 cd cvswork &&
303 GIT_CONFIG="$git_config" cvs -Q update &&
304 test ! -d test
307 cd "$WORKDIR"
308 test_expect_success 'cvs update (subdirectories)' \
309 '(for dir in A A/B A/B/C A/D E; do
310 mkdir $dir &&
311 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
312 git add $dir;
313 done) &&
314 git commit -q -m "deep sub directory structure" &&
315 git push gitcvs.git >/dev/null &&
316 cd cvswork &&
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
323 else
324 echo >failure
326 done) &&
327 test ! -f failure'
329 cd "$WORKDIR"
330 test_expect_success 'cvs update (delete file)' \
331 'git rm testfile1 &&
332 git commit -q -m "Remove testfile1" &&
333 git push gitcvs.git >/dev/null &&
334 cd cvswork &&
335 GIT_CONFIG="$git_config" cvs -Q update &&
336 test -z "$(grep testfile1 CVS/Entries)" &&
337 test ! -f testfile1'
339 cd "$WORKDIR"
340 test_expect_success 'cvs update (re-add deleted file)' \
341 'echo readded testfile >testfile1 &&
342 git add testfile1 &&
343 git commit -q -m "Re-Add testfile1" &&
344 git push gitcvs.git >/dev/null &&
345 cd cvswork &&
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'
350 cd "$WORKDIR"
351 test_expect_success 'cvs update (merge)' \
352 'echo Line 0 >expected &&
353 for i in 1 2 3 4 5 6 7
355 echo Line $i >>merge
356 echo Line $i >>expected
357 done &&
358 echo Line 8 >>expected &&
359 git add merge &&
360 git commit -q -m "Merge test (pre-merge)" &&
361 git push gitcvs.git >/dev/null &&
362 cd cvswork &&
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 &&
368 cd "$WORKDIR" &&
369 echo Line 8 >>merge &&
370 git add merge &&
371 git commit -q -m "Merge test (merge)" &&
372 git push gitcvs.git >/dev/null &&
373 cd cvswork &&
374 sleep 1 && touch merge &&
375 GIT_CONFIG="$git_config" cvs -Q update &&
376 diff -q merge ../expected'
378 cd "$WORKDIR"
380 cat >expected.C <<EOF
381 <<<<<<< merge.mine
382 Line 0
383 =======
384 LINE 0
385 >>>>>>> merge.3
388 for i in 1 2 3 4 5 6 7 8
390 echo Line $i >>expected.C
391 done
393 test_expect_success 'cvs update (conflict merge)' \
394 '( echo LINE 0; cat merge ) >merge.tmp &&
395 mv merge.tmp merge &&
396 git add merge &&
397 git commit -q -m "Merge test (conflict)" &&
398 git push gitcvs.git >/dev/null &&
399 cd cvswork &&
400 GIT_CONFIG="$git_config" cvs -Q update &&
401 diff -q merge ../expected.C'
403 cd "$WORKDIR"
404 test_expect_success 'cvs update (-C)' \
405 'cd cvswork &&
406 GIT_CONFIG="$git_config" cvs -Q update -C &&
407 diff -q merge ../merge'
409 cd "$WORKDIR"
410 test_expect_success 'cvs update (merge no-op)' \
411 'echo Line 9 >>merge &&
412 cp merge cvswork/merge &&
413 git add merge &&
414 git commit -q -m "Merge test (no-op)" &&
415 git push gitcvs.git >/dev/null &&
416 cd cvswork &&
417 sleep 1 && touch merge &&
418 GIT_CONFIG="$git_config" cvs -Q update &&
419 diff -q merge ../merge'
421 cd "$WORKDIR"
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 &&
429 cd cvswork &&
430 GIT_CONFIG="$git_config" cvs update &&
431 rm -f failures &&
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
435 done &&
436 test -z "$(cat failures)"
439 cd "$WORKDIR"
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
446 #------------
447 # CVS STATUS
448 #------------
450 cd "$WORKDIR"
451 test_expect_success 'cvs status' '
452 mkdir status.dir &&
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 &&
458 cd cvswork &&
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
464 cd "$WORKDIR"
465 test_expect_success 'cvs status (nonrecursive)' '
466 cd cvswork &&
467 GIT_CONFIG="$git_config" cvs status -l | grep "^File: status.file" >../out &&
468 test $(wc -l <../out) = 1
471 cd "$WORKDIR"
472 test_expect_success 'cvs status (no subdirs in header)' '
473 cd cvswork &&
474 GIT_CONFIG="$git_config" cvs status | grep ^File: >../out &&
475 ! grep / <../out
478 #------------
479 # CVS CHECKOUT
480 #------------
482 cd "$WORKDIR"
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
489 #------------
490 # CVS ANNOTATE
491 #------------
493 cd "$WORKDIR"
494 test_expect_success 'cvs annotate' '
495 cd cvswork &&
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
502 test_done