Code

9b69452d6f4836f637c28854ea0660afbedb62b8
[git.git] / t / t9400-git-cvsserver-server.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Frank Lichtenheld
4 #
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
19 fi
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
24 }
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 echo >empty &&
37   git add empty &&
38   git commit -q -m "First Commit" &&
39   git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
40   GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
41   GIT_DIR="$SERVERDIR" git config --bool gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
42   exit 1
44 # note that cvs doesn't accept absolute pathnames
45 # as argument to co -d
46 test_expect_success 'basic checkout' \
47   'GIT_CONFIG="$git_config" cvs -Q co -d cvswork master &&
48    test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5))" = "empty/1.1/"'
50 #------------------------
51 # PSERVER AUTHENTICATION
52 #------------------------
54 cat >request-anonymous  <<EOF
55 BEGIN AUTH REQUEST
56 $SERVERDIR
57 anonymous
59 END AUTH REQUEST
60 EOF
62 cat >request-git  <<EOF
63 BEGIN AUTH REQUEST
64 $SERVERDIR
65 git
67 END AUTH REQUEST
68 EOF
70 cat >login-anonymous <<EOF
71 BEGIN VERIFICATION REQUEST
72 $SERVERDIR
73 anonymous
75 END VERIFICATION REQUEST
76 EOF
78 cat >login-git <<EOF
79 BEGIN VERIFICATION REQUEST
80 $SERVERDIR
81 git
83 END VERIFICATION REQUEST
84 EOF
86 test_expect_success 'pserver authentication' \
87   'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
88    tail -n1 log | grep -q "^I LOVE YOU$"'
90 test_expect_success 'pserver authentication failure (non-anonymous user)' \
91   'if cat request-git | git-cvsserver pserver >log 2>&1
92    then
93        false
94    else
95        true
96    fi &&
97    tail -n1 log | grep -q "^I HATE YOU$"'
99 test_expect_success 'pserver authentication (login)' \
100   'cat login-anonymous | git-cvsserver pserver >log 2>&1 &&
101    tail -n1 log | grep -q "^I LOVE YOU$"'
103 test_expect_success 'pserver authentication failure (login/non-anonymous user)' \
104   'if cat login-git | git-cvsserver pserver >log 2>&1
105    then
106        false
107    else
108        true
109    fi &&
110    tail -n1 log | grep -q "^I HATE YOU$"'
113 # misuse pserver authentication for testing of req_Root
115 cat >request-relative  <<EOF
116 BEGIN AUTH REQUEST
117 gitcvs.git
118 anonymous
120 END AUTH REQUEST
121 EOF
123 cat >request-conflict  <<EOF
124 BEGIN AUTH REQUEST
125 $SERVERDIR
126 anonymous
128 END AUTH REQUEST
129 Root $WORKDIR
130 EOF
132 test_expect_success 'req_Root failure (relative pathname)' \
133   'if cat request-relative | git-cvsserver pserver >log 2>&1
134    then
135        echo unexpected success
136        false
137    else
138        true
139    fi &&
140    tail log | grep -q "^error 1 Root must be an absolute pathname$"'
142 test_expect_success 'req_Root failure (conflicting roots)' \
143   'cat request-conflict | git-cvsserver pserver >log 2>&1 &&
144    tail log | grep -q "^error 1 Conflicting roots specified$"'
146 test_expect_success 'req_Root (strict paths)' \
147   'cat request-anonymous | git-cvsserver --strict-paths pserver $SERVERDIR >log 2>&1 &&
148    tail -n1 log | grep -q "^I LOVE YOU$"'
150 test_expect_failure 'req_Root failure (strict-paths)' \
151   'cat request-anonymous | git-cvsserver --strict-paths pserver $WORKDIR >log 2>&1'
153 test_expect_success 'req_Root (w/o strict-paths)' \
154   'cat request-anonymous | git-cvsserver pserver $WORKDIR/ >log 2>&1 &&
155    tail -n1 log | grep -q "^I LOVE YOU$"'
157 test_expect_failure 'req_Root failure (w/o strict-paths)' \
158   'cat request-anonymous | git-cvsserver pserver $WORKDIR/gitcvs >log 2>&1'
160 cat >request-base  <<EOF
161 BEGIN AUTH REQUEST
162 /gitcvs.git
163 anonymous
165 END AUTH REQUEST
166 Root /gitcvs.git
167 EOF
169 test_expect_success 'req_Root (base-path)' \
170   'cat request-base | git-cvsserver --strict-paths --base-path $WORKDIR/ pserver $SERVERDIR >log 2>&1 &&
171    tail -n1 log | grep -q "^I LOVE YOU$"'
173 test_expect_failure 'req_Root failure (base-path)' \
174   'cat request-anonymous | git-cvsserver --strict-paths --base-path $WORKDIR pserver $SERVERDIR >log 2>&1'
176 #--------------
177 # CONFIG TESTS
178 #--------------
180 test_expect_success 'gitcvs.enabled = false' \
181   'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
182    if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
183    then
184      echo unexpected cvs success
185      false
186    else
187      true
188    fi &&
189    cat cvs.log | grep -q "GITCVS emulation disabled" &&
190    test ! -d cvswork2'
192 rm -fr cvswork2
193 test_expect_success 'gitcvs.ext.enabled = true' \
194   'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
195    GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
196    GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
197    diff -q cvswork cvswork2'
199 rm -fr cvswork2
200 test_expect_success 'gitcvs.ext.enabled = false' \
201   'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
202    GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
203    if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
204    then
205      echo unexpected cvs success
206      false
207    else
208      true
209    fi &&
210    cat cvs.log | grep -q "GITCVS emulation disabled" &&
211    test ! -d cvswork2'
213 rm -fr cvswork2
214 test_expect_success 'gitcvs.dbname' \
215   'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
216    GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
217    GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
218    diff -q cvswork cvswork2 &&
219    test -f "$SERVERDIR/gitcvs.ext.master.sqlite" &&
220    cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs.ext.master.sqlite"'
222 rm -fr cvswork2
223 test_expect_success 'gitcvs.ext.dbname' \
224   'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
225    GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
226    GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
227    GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
228    diff -q cvswork cvswork2 &&
229    test -f "$SERVERDIR/gitcvs1.ext.master.sqlite" &&
230    test ! -f "$SERVERDIR/gitcvs2.ext.master.sqlite" &&
231    cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs1.ext.master.sqlite"'
234 #------------
235 # CVS UPDATE
236 #------------
238 rm -fr "$SERVERDIR"
239 cd "$WORKDIR" &&
240 git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
241 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
242 GIT_DIR="$SERVERDIR" git config --bool gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
243 exit 1
245 test_expect_success 'cvs update (create new file)' \
246   'echo testfile1 >testfile1 &&
247    git add testfile1 &&
248    git commit -q -m "Add testfile1" &&
249    git push gitcvs.git >/dev/null &&
250    cd cvswork &&
251    GIT_CONFIG="$git_config" cvs -Q update &&
252    test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
253    diff -q testfile1 ../testfile1'
255 cd "$WORKDIR"
256 test_expect_success 'cvs update (update existing file)' \
257   'echo line 2 >>testfile1 &&
258    git add testfile1 &&
259    git commit -q -m "Append to testfile1" &&
260    git push gitcvs.git >/dev/null &&
261    cd cvswork &&
262    GIT_CONFIG="$git_config" cvs -Q update &&
263    test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
264    diff -q testfile1 ../testfile1'
266 cd "$WORKDIR"
267 #TODO: cvsserver doesn't support update w/o -d
268 test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" \
269   'mkdir test &&
270    echo >test/empty &&
271    git add test &&
272    git commit -q -m "Single Subdirectory" &&
273    git push gitcvs.git >/dev/null &&
274    cd cvswork &&
275    GIT_CONFIG="$git_config" cvs -Q update &&
276    test ! -d test'
278 cd "$WORKDIR"
279 test_expect_success 'cvs update (subdirectories)' \
280   '(for dir in A A/B A/B/C A/D E; do
281       mkdir $dir &&
282       echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")"  &&
283       git add $dir;
284    done) &&
285    git commit -q -m "deep sub directory structure" &&
286    git push gitcvs.git >/dev/null &&
287    cd cvswork &&
288    GIT_CONFIG="$git_config" cvs -Q update -d &&
289    (for dir in A A/B A/B/C A/D E; do
290       filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
291       if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
292            diff -q "$dir/$filename" "../$dir/$filename"; then
293         :
294       else
295         echo >failure
296       fi
297     done) &&
298    test ! -f failure'
300 cd "$WORKDIR"
301 test_expect_success 'cvs update (delete file)' \
302   'git rm testfile1 &&
303    git commit -q -m "Remove testfile1" &&
304    git push gitcvs.git >/dev/null &&
305    cd cvswork &&
306    GIT_CONFIG="$git_config" cvs -Q update &&
307    test -z "$(grep testfile1 CVS/Entries)" &&
308    test ! -f testfile1'
310 cd "$WORKDIR"
311 test_expect_success 'cvs update (re-add deleted file)' \
312   'echo readded testfile >testfile1 &&
313    git add testfile1 &&
314    git commit -q -m "Re-Add testfile1" &&
315    git push gitcvs.git >/dev/null &&
316    cd cvswork &&
317    GIT_CONFIG="$git_config" cvs -Q update &&
318    test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
319    diff -q testfile1 ../testfile1'
321 cd "$WORKDIR"
322 test_expect_success 'cvs update (merge)' \
323   'echo Line 0 >expected &&
324    for i in 1 2 3 4 5 6 7
325    do
326      echo Line $i >>merge
327      echo Line $i >>expected
328    done &&
329    echo Line 8 >>expected &&
330    git add merge &&
331    git commit -q -m "Merge test (pre-merge)" &&
332    git push gitcvs.git >/dev/null &&
333    cd cvswork &&
334    GIT_CONFIG="$git_config" cvs -Q update &&
335    test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
336    diff -q merge ../merge &&
337    ( echo Line 0; cat merge ) >merge.tmp &&
338    mv merge.tmp merge &&
339    cd "$WORKDIR" &&
340    echo Line 8 >>merge &&
341    git add merge &&
342    git commit -q -m "Merge test (merge)" &&
343    git push gitcvs.git >/dev/null &&
344    cd cvswork &&
345    sleep 1 && touch merge &&
346    GIT_CONFIG="$git_config" cvs -Q update &&
347    diff -q merge ../expected'
349 cd "$WORKDIR"
351 cat >expected.C <<EOF
352 <<<<<<< merge.mine
353 Line 0
354 =======
355 LINE 0
356 >>>>>>> merge.3
357 EOF
359 for i in 1 2 3 4 5 6 7 8
360 do
361   echo Line $i >>expected.C
362 done
364 test_expect_success 'cvs update (conflict merge)' \
365   '( echo LINE 0; cat merge ) >merge.tmp &&
366    mv merge.tmp merge &&
367    git add merge &&
368    git commit -q -m "Merge test (conflict)" &&
369    git push gitcvs.git >/dev/null &&
370    cd cvswork &&
371    GIT_CONFIG="$git_config" cvs -Q update &&
372    diff -q merge ../expected.C'
374 cd "$WORKDIR"
375 test_expect_success 'cvs update (-C)' \
376   'cd cvswork &&
377    GIT_CONFIG="$git_config" cvs -Q update -C &&
378    diff -q merge ../merge'
380 cd "$WORKDIR"
381 test_expect_success 'cvs update (merge no-op)' \
382    'echo Line 9 >>merge &&
383     cp merge cvswork/merge &&
384     git add merge &&
385     git commit -q -m "Merge test (no-op)" &&
386     git push gitcvs.git >/dev/null &&
387     cd cvswork &&
388     sleep 1 && touch merge &&
389     GIT_CONFIG="$git_config" cvs -Q update &&
390     diff -q merge ../merge'
392 test_done