Code

e42943e5b10ff6fe93ddd26a03f67b0f37a41a93
[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 # CONFIG TESTS
52 #--------------
54 test_expect_success 'gitcvs.enabled = false' \
55   'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
56    if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
57    then
58      echo unexpected cvs success
59      false
60    else
61      true
62    fi &&
63    cat cvs.log | grep -q "GITCVS emulation disabled" &&
64    test ! -d cvswork2'
66 rm -fr cvswork2
67 test_expect_success 'gitcvs.ext.enabled = true' \
68   'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
69    GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
70    GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
71    diff -q cvswork cvswork2'
73 rm -fr cvswork2
74 test_expect_success 'gitcvs.ext.enabled = false' \
75   'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
76    GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
77    if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
78    then
79      echo unexpected cvs success
80      false
81    else
82      true
83    fi &&
84    cat cvs.log | grep -q "GITCVS emulation disabled" &&
85    test ! -d cvswork2'
87 rm -fr cvswork2
88 test_expect_success 'gitcvs.dbname' \
89   'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
90    GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
91    GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
92    diff -q cvswork cvswork2 &&
93    test -f "$SERVERDIR/gitcvs.ext.master.sqlite" &&
94    cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs.ext.master.sqlite"'
96 rm -fr cvswork2
97 test_expect_success 'gitcvs.ext.dbname' \
98   'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
99    GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
100    GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
101    GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
102    diff -q cvswork cvswork2 &&
103    test -f "$SERVERDIR/gitcvs1.ext.master.sqlite" &&
104    test ! -f "$SERVERDIR/gitcvs2.ext.master.sqlite" &&
105    cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs1.ext.master.sqlite"'
108 #------------
109 # CVS UPDATE
110 #------------
112 rm -fr "$SERVERDIR"
113 cd "$WORKDIR" &&
114 git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
115 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
116 GIT_DIR="$SERVERDIR" git config --bool gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
117 exit 1
119 test_expect_success 'cvs update (create new file)' \
120   'echo testfile1 >testfile1 &&
121    git add testfile1 &&
122    git commit -q -m "Add testfile1" &&
123    git push gitcvs.git >/dev/null &&
124    cd cvswork &&
125    GIT_CONFIG="$git_config" cvs -Q update &&
126    test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
127    diff -q testfile1 ../testfile1'
129 cd "$WORKDIR"
130 test_expect_success 'cvs update (update existing file)' \
131   'echo line 2 >>testfile1 &&
132    git add testfile1 &&
133    git commit -q -m "Append to testfile1" &&
134    git push gitcvs.git >/dev/null &&
135    cd cvswork &&
136    GIT_CONFIG="$git_config" cvs -Q update &&
137    test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
138    diff -q testfile1 ../testfile1'
140 cd "$WORKDIR"
141 #TODO: cvsserver doesn't support update w/o -d
142 test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" \
143   'mkdir test &&
144    echo >test/empty &&
145    git add test &&
146    git commit -q -m "Single Subdirectory" &&
147    git push gitcvs.git >/dev/null &&
148    cd cvswork &&
149    GIT_CONFIG="$git_config" cvs -Q update &&
150    test ! -d test'
152 cd "$WORKDIR"
153 test_expect_success 'cvs update (subdirectories)' \
154   '(for dir in A A/B A/B/C A/D E; do
155       mkdir $dir &&
156       echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")"  &&
157       git add $dir;
158    done) &&
159    git commit -q -m "deep sub directory structure" &&
160    git push gitcvs.git >/dev/null &&
161    cd cvswork &&
162    GIT_CONFIG="$git_config" cvs -Q update -d &&
163    (for dir in A A/B A/B/C A/D E; do
164       filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
165       if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
166            diff -q "$dir/$filename" "../$dir/$filename"; then
167         :
168       else
169         echo >failure
170       fi
171     done) &&
172    test ! -f failure'
174 cd "$WORKDIR"
175 test_expect_success 'cvs update (delete file)' \
176   'git rm testfile1 &&
177    git commit -q -m "Remove testfile1" &&
178    git push gitcvs.git >/dev/null &&
179    cd cvswork &&
180    GIT_CONFIG="$git_config" cvs -Q update &&
181    test -z "$(grep testfile1 CVS/Entries)" &&
182    test ! -f testfile1'
184 cd "$WORKDIR"
185 test_expect_success 'cvs update (re-add deleted file)' \
186   'echo readded testfile >testfile1 &&
187    git add testfile1 &&
188    git commit -q -m "Re-Add testfile1" &&
189    git push gitcvs.git >/dev/null &&
190    cd cvswork &&
191    GIT_CONFIG="$git_config" cvs -Q update &&
192    test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
193    diff -q testfile1 ../testfile1'
195 cd "$WORKDIR"
196 test_expect_success 'cvs update (merge)' \
197   'echo Line 0 >expected &&
198    for i in 1 2 3 4 5 6 7
199    do
200      echo Line $i >>merge
201      echo Line $i >>expected
202    done &&
203    echo Line 8 >>expected &&
204    git add merge &&
205    git commit -q -m "Merge test (pre-merge)" &&
206    git push gitcvs.git >/dev/null &&
207    cd cvswork &&
208    GIT_CONFIG="$git_config" cvs -Q update &&
209    test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
210    diff -q merge ../merge &&
211    ( echo Line 0; cat merge ) >merge.tmp &&
212    mv merge.tmp merge &&
213    cd "$WORKDIR" &&
214    echo Line 8 >>merge &&
215    git add merge &&
216    git commit -q -m "Merge test (merge)" &&
217    git push gitcvs.git >/dev/null &&
218    cd cvswork &&
219    GIT_CONFIG="$git_config" cvs -Q update &&
220    diff -q merge ../expected'
222 cd "$WORKDIR"
224 cat >expected.C <<EOF
225 <<<<<<< merge.mine
226 Line 0
227 =======
228 LINE 0
229 >>>>>>> merge.3
230 EOF
232 for i in 1 2 3 4 5 6 7 8
233 do
234   echo Line $i >>expected.C
235 done
237 test_expect_success 'cvs update (conflict merge)' \
238   '( echo LINE 0; cat merge ) >merge.tmp &&
239    mv merge.tmp merge &&
240    git add merge &&
241    git commit -q -m "Merge test (conflict)" &&
242    git push gitcvs.git >/dev/null &&
243    cd cvswork &&
244    GIT_CONFIG="$git_config" cvs -Q update &&
245    diff -q merge ../expected.C'
247 cd "$WORKDIR"
248 test_expect_success 'cvs update (-C)' \
249   'cd cvswork &&
250    GIT_CONFIG="$git_config" cvs -Q update -C &&
251    diff -q merge ../merge'
253 cd "$WORKDIR"
254 test_expect_success 'cvs update (merge no-op)' \
255    'echo Line 9 >>merge &&
256     cp merge cvswork/merge &&
257     git add merge &&
258     git commit -q -m "Merge test (no-op)" &&
259     git push gitcvs.git >/dev/null &&
260     cd cvswork &&
261     GIT_CONFIG="$git_config" cvs -Q update &&
262     diff -q merge ../merge'
264 test_done