instaweb: use 'browser.<tool>.path' config option if it's set.
[git/dscho.git] / t / t9400-git-cvsserver-server.sh
blob75d1ce433d3110e6fe24be00aef8dcc7592d8082
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 test_expect_success 'skipping git-cvsserver tests, cvs not found' :
17 test_done
18 exit
20 perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
21 test_expect_success 'skipping git-cvsserver tests, Perl SQLite interface unavailable' :
22 test_done
23 exit
26 unset GIT_DIR GIT_CONFIG
27 WORKDIR=$(pwd)
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' '
37 echo >empty &&
38 git add empty &&
39 git commit -q -m "First Commit" &&
40 mkdir secondroot &&
41 ( cd secondroot &&
42 git init &&
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 | tail -n 1))" = "secondrootfile/1.1/"'
59 #------------------------
60 # PSERVER AUTHENTICATION
61 #------------------------
63 cat >request-anonymous <<EOF
64 BEGIN AUTH REQUEST
65 $SERVERDIR
66 anonymous
68 END AUTH REQUEST
69 EOF
71 cat >request-git <<EOF
72 BEGIN AUTH REQUEST
73 $SERVERDIR
74 git
76 END AUTH REQUEST
77 EOF
79 cat >login-anonymous <<EOF
80 BEGIN VERIFICATION REQUEST
81 $SERVERDIR
82 anonymous
84 END VERIFICATION REQUEST
85 EOF
87 cat >login-git <<EOF
88 BEGIN VERIFICATION REQUEST
89 $SERVERDIR
90 git
92 END VERIFICATION REQUEST
93 EOF
95 test_expect_success 'pserver authentication' \
96 'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
97 tail -n1 log | grep -q "^I LOVE YOU$"'
99 test_expect_success 'pserver authentication failure (non-anonymous user)' \
100 'if cat request-git | git-cvsserver pserver >log 2>&1
101 then
102 false
103 else
104 true
105 fi &&
106 tail -n1 log | grep -q "^I HATE YOU$"'
108 test_expect_success 'pserver authentication (login)' \
109 'cat login-anonymous | git-cvsserver pserver >log 2>&1 &&
110 tail -n1 log | grep -q "^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
114 then
115 false
116 else
117 true
118 fi &&
119 tail -n1 log | grep -q "^I HATE YOU$"'
122 # misuse pserver authentication for testing of req_Root
124 cat >request-relative <<EOF
125 BEGIN AUTH REQUEST
126 gitcvs.git
127 anonymous
129 END AUTH REQUEST
132 cat >request-conflict <<EOF
133 BEGIN AUTH REQUEST
134 $SERVERDIR
135 anonymous
137 END AUTH REQUEST
138 Root $WORKDIR
141 test_expect_success 'req_Root failure (relative pathname)' \
142 'if cat request-relative | git-cvsserver pserver >log 2>&1
143 then
144 echo unexpected success
145 false
146 else
147 true
148 fi &&
149 tail log | grep -q "^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 -q "^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 tail -n1 log | grep -q "^I LOVE YOU$"'
159 test_expect_failure 'req_Root failure (strict-paths)' \
160 'cat request-anonymous | 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 tail -n1 log | grep -q "^I LOVE YOU$"'
166 test_expect_failure 'req_Root failure (w/o strict-paths)' \
167 'cat request-anonymous | git-cvsserver pserver $WORKDIR/gitcvs >log 2>&1'
169 cat >request-base <<EOF
170 BEGIN AUTH REQUEST
171 /gitcvs.git
172 anonymous
174 END AUTH REQUEST
175 Root /gitcvs.git
178 test_expect_success 'req_Root (base-path)' \
179 'cat request-base | git-cvsserver --strict-paths --base-path $WORKDIR/ pserver $SERVERDIR >log 2>&1 &&
180 tail -n1 log | grep -q "^I LOVE YOU$"'
182 test_expect_failure 'req_Root failure (base-path)' \
183 'cat request-anonymous | git-cvsserver --strict-paths --base-path $WORKDIR pserver $SERVERDIR >log 2>&1'
185 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false || exit 1
187 test_expect_success 'req_Root (export-all)' \
188 'cat request-anonymous | git-cvsserver --export-all pserver $WORKDIR >log 2>&1 &&
189 tail -n1 log | grep -q "^I LOVE YOU$"'
191 test_expect_failure 'req_Root failure (export-all w/o whitelist)' \
192 'cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 ||
193 false'
195 test_expect_success 'req_Root (everything together)' \
196 'cat request-base | git-cvsserver --export-all --strict-paths --base-path $WORKDIR/ pserver $SERVERDIR >log 2>&1 &&
197 tail -n1 log | grep -q "^I LOVE YOU$"'
199 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true || exit 1
201 #--------------
202 # CONFIG TESTS
203 #--------------
205 test_expect_success 'gitcvs.enabled = false' \
206 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
207 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
208 then
209 echo unexpected cvs success
210 false
211 else
212 true
213 fi &&
214 cat cvs.log | grep -q "GITCVS emulation disabled" &&
215 test ! -d cvswork2'
217 rm -fr cvswork2
218 test_expect_success 'gitcvs.ext.enabled = true' \
219 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
220 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
221 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
222 diff -q cvswork cvswork2'
224 rm -fr cvswork2
225 test_expect_success 'gitcvs.ext.enabled = false' \
226 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
227 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
228 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
229 then
230 echo unexpected cvs success
231 false
232 else
233 true
234 fi &&
235 cat cvs.log | grep -q "GITCVS emulation disabled" &&
236 test ! -d cvswork2'
238 rm -fr cvswork2
239 test_expect_success 'gitcvs.dbname' \
240 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
241 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
242 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
243 diff -q cvswork cvswork2 &&
244 test -f "$SERVERDIR/gitcvs.ext.master.sqlite" &&
245 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs.ext.master.sqlite"'
247 rm -fr cvswork2
248 test_expect_success 'gitcvs.ext.dbname' \
249 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
250 GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
251 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
252 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
253 diff -q cvswork cvswork2 &&
254 test -f "$SERVERDIR/gitcvs1.ext.master.sqlite" &&
255 test ! -f "$SERVERDIR/gitcvs2.ext.master.sqlite" &&
256 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs1.ext.master.sqlite"'
259 #------------
260 # CVS UPDATE
261 #------------
263 rm -fr "$SERVERDIR"
264 cd "$WORKDIR" &&
265 git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
266 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
267 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
268 exit 1
270 test_expect_success 'cvs update (create new file)' \
271 'echo testfile1 >testfile1 &&
272 git add testfile1 &&
273 git commit -q -m "Add testfile1" &&
274 git push gitcvs.git >/dev/null &&
275 cd cvswork &&
276 GIT_CONFIG="$git_config" cvs -Q update &&
277 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
278 diff -q testfile1 ../testfile1'
280 cd "$WORKDIR"
281 test_expect_success 'cvs update (update existing file)' \
282 'echo line 2 >>testfile1 &&
283 git add testfile1 &&
284 git commit -q -m "Append to testfile1" &&
285 git push gitcvs.git >/dev/null &&
286 cd cvswork &&
287 GIT_CONFIG="$git_config" cvs -Q update &&
288 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
289 diff -q testfile1 ../testfile1'
291 cd "$WORKDIR"
292 #TODO: cvsserver doesn't support update w/o -d
293 test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" \
294 'mkdir test &&
295 echo >test/empty &&
296 git add test &&
297 git commit -q -m "Single Subdirectory" &&
298 git push gitcvs.git >/dev/null &&
299 cd cvswork &&
300 GIT_CONFIG="$git_config" cvs -Q update &&
301 test ! -d test'
303 cd "$WORKDIR"
304 test_expect_success 'cvs update (subdirectories)' \
305 '(for dir in A A/B A/B/C A/D E; do
306 mkdir $dir &&
307 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
308 git add $dir;
309 done) &&
310 git commit -q -m "deep sub directory structure" &&
311 git push gitcvs.git >/dev/null &&
312 cd cvswork &&
313 GIT_CONFIG="$git_config" cvs -Q update -d &&
314 (for dir in A A/B A/B/C A/D E; do
315 filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
316 if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
317 diff -q "$dir/$filename" "../$dir/$filename"; then
319 else
320 echo >failure
322 done) &&
323 test ! -f failure'
325 cd "$WORKDIR"
326 test_expect_success 'cvs update (delete file)' \
327 'git rm testfile1 &&
328 git commit -q -m "Remove testfile1" &&
329 git push gitcvs.git >/dev/null &&
330 cd cvswork &&
331 GIT_CONFIG="$git_config" cvs -Q update &&
332 test -z "$(grep testfile1 CVS/Entries)" &&
333 test ! -f testfile1'
335 cd "$WORKDIR"
336 test_expect_success 'cvs update (re-add deleted file)' \
337 'echo readded testfile >testfile1 &&
338 git add testfile1 &&
339 git commit -q -m "Re-Add testfile1" &&
340 git push gitcvs.git >/dev/null &&
341 cd cvswork &&
342 GIT_CONFIG="$git_config" cvs -Q update &&
343 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
344 diff -q testfile1 ../testfile1'
346 cd "$WORKDIR"
347 test_expect_success 'cvs update (merge)' \
348 'echo Line 0 >expected &&
349 for i in 1 2 3 4 5 6 7
351 echo Line $i >>merge
352 echo Line $i >>expected
353 done &&
354 echo Line 8 >>expected &&
355 git add merge &&
356 git commit -q -m "Merge test (pre-merge)" &&
357 git push gitcvs.git >/dev/null &&
358 cd cvswork &&
359 GIT_CONFIG="$git_config" cvs -Q update &&
360 test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
361 diff -q merge ../merge &&
362 ( echo Line 0; cat merge ) >merge.tmp &&
363 mv merge.tmp merge &&
364 cd "$WORKDIR" &&
365 echo Line 8 >>merge &&
366 git add merge &&
367 git commit -q -m "Merge test (merge)" &&
368 git push gitcvs.git >/dev/null &&
369 cd cvswork &&
370 sleep 1 && touch merge &&
371 GIT_CONFIG="$git_config" cvs -Q update &&
372 diff -q merge ../expected'
374 cd "$WORKDIR"
376 cat >expected.C <<EOF
377 <<<<<<< merge.mine
378 Line 0
379 =======
380 LINE 0
381 >>>>>>> merge.3
384 for i in 1 2 3 4 5 6 7 8
386 echo Line $i >>expected.C
387 done
389 test_expect_success 'cvs update (conflict merge)' \
390 '( echo LINE 0; cat merge ) >merge.tmp &&
391 mv merge.tmp merge &&
392 git add merge &&
393 git commit -q -m "Merge test (conflict)" &&
394 git push gitcvs.git >/dev/null &&
395 cd cvswork &&
396 GIT_CONFIG="$git_config" cvs -Q update &&
397 diff -q merge ../expected.C'
399 cd "$WORKDIR"
400 test_expect_success 'cvs update (-C)' \
401 'cd cvswork &&
402 GIT_CONFIG="$git_config" cvs -Q update -C &&
403 diff -q merge ../merge'
405 cd "$WORKDIR"
406 test_expect_success 'cvs update (merge no-op)' \
407 'echo Line 9 >>merge &&
408 cp merge cvswork/merge &&
409 git add merge &&
410 git commit -q -m "Merge test (no-op)" &&
411 git push gitcvs.git >/dev/null &&
412 cd cvswork &&
413 sleep 1 && touch merge &&
414 GIT_CONFIG="$git_config" cvs -Q update &&
415 diff -q merge ../merge'
417 test_done