t9400: Work around CVS' deficiencies
[git/spearce.git] / t / t9400-git-cvsserver-server.sh
blob76a9b1a5d2f5ce5b36a065b967d8b8038395b865
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 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 test_expect_success 'pserver authentication' \
71 'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
72 tail -n1 log | grep -q "^I LOVE YOU$"'
74 test_expect_success 'pserver authentication failure (non-anonymous user)' \
75 'if cat request-git | git-cvsserver pserver >log 2>&1
76 then
77 false
78 else
79 true
80 fi &&
81 tail -n1 log | grep -q "^I HATE YOU$"'
84 #--------------
85 # CONFIG TESTS
86 #--------------
88 test_expect_success 'gitcvs.enabled = false' \
89 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
90 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
91 then
92 echo unexpected cvs success
93 false
94 else
95 true
96 fi &&
97 cat cvs.log | grep -q "GITCVS emulation disabled" &&
98 test ! -d cvswork2'
100 rm -fr cvswork2
101 test_expect_success 'gitcvs.ext.enabled = true' \
102 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
103 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
104 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
105 diff -q cvswork cvswork2'
107 rm -fr cvswork2
108 test_expect_success 'gitcvs.ext.enabled = false' \
109 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
110 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
111 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
112 then
113 echo unexpected cvs success
114 false
115 else
116 true
117 fi &&
118 cat cvs.log | grep -q "GITCVS emulation disabled" &&
119 test ! -d cvswork2'
121 rm -fr cvswork2
122 test_expect_success 'gitcvs.dbname' \
123 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
124 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
125 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
126 diff -q cvswork cvswork2 &&
127 test -f "$SERVERDIR/gitcvs.ext.master.sqlite" &&
128 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs.ext.master.sqlite"'
130 rm -fr cvswork2
131 test_expect_success 'gitcvs.ext.dbname' \
132 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
133 GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
134 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
135 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
136 diff -q cvswork cvswork2 &&
137 test -f "$SERVERDIR/gitcvs1.ext.master.sqlite" &&
138 test ! -f "$SERVERDIR/gitcvs2.ext.master.sqlite" &&
139 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs1.ext.master.sqlite"'
142 #------------
143 # CVS UPDATE
144 #------------
146 rm -fr "$SERVERDIR"
147 cd "$WORKDIR" &&
148 git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
149 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
150 GIT_DIR="$SERVERDIR" git config --bool gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
151 exit 1
153 test_expect_success 'cvs update (create new file)' \
154 'echo testfile1 >testfile1 &&
155 git add testfile1 &&
156 git commit -q -m "Add testfile1" &&
157 git push gitcvs.git >/dev/null &&
158 cd cvswork &&
159 GIT_CONFIG="$git_config" cvs -Q update &&
160 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
161 diff -q testfile1 ../testfile1'
163 cd "$WORKDIR"
164 test_expect_success 'cvs update (update existing file)' \
165 'echo line 2 >>testfile1 &&
166 git add testfile1 &&
167 git commit -q -m "Append to testfile1" &&
168 git push gitcvs.git >/dev/null &&
169 cd cvswork &&
170 GIT_CONFIG="$git_config" cvs -Q update &&
171 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
172 diff -q testfile1 ../testfile1'
174 cd "$WORKDIR"
175 #TODO: cvsserver doesn't support update w/o -d
176 test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" \
177 'mkdir test &&
178 echo >test/empty &&
179 git add test &&
180 git commit -q -m "Single Subdirectory" &&
181 git push gitcvs.git >/dev/null &&
182 cd cvswork &&
183 GIT_CONFIG="$git_config" cvs -Q update &&
184 test ! -d test'
186 cd "$WORKDIR"
187 test_expect_success 'cvs update (subdirectories)' \
188 '(for dir in A A/B A/B/C A/D E; do
189 mkdir $dir &&
190 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
191 git add $dir;
192 done) &&
193 git commit -q -m "deep sub directory structure" &&
194 git push gitcvs.git >/dev/null &&
195 cd cvswork &&
196 GIT_CONFIG="$git_config" cvs -Q update -d &&
197 (for dir in A A/B A/B/C A/D E; do
198 filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
199 if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
200 diff -q "$dir/$filename" "../$dir/$filename"; then
202 else
203 echo >failure
205 done) &&
206 test ! -f failure'
208 cd "$WORKDIR"
209 test_expect_success 'cvs update (delete file)' \
210 'git rm testfile1 &&
211 git commit -q -m "Remove testfile1" &&
212 git push gitcvs.git >/dev/null &&
213 cd cvswork &&
214 GIT_CONFIG="$git_config" cvs -Q update &&
215 test -z "$(grep testfile1 CVS/Entries)" &&
216 test ! -f testfile1'
218 cd "$WORKDIR"
219 test_expect_success 'cvs update (re-add deleted file)' \
220 'echo readded testfile >testfile1 &&
221 git add testfile1 &&
222 git commit -q -m "Re-Add testfile1" &&
223 git push gitcvs.git >/dev/null &&
224 cd cvswork &&
225 GIT_CONFIG="$git_config" cvs -Q update &&
226 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
227 diff -q testfile1 ../testfile1'
229 cd "$WORKDIR"
230 test_expect_success 'cvs update (merge)' \
231 'echo Line 0 >expected &&
232 for i in 1 2 3 4 5 6 7
234 echo Line $i >>merge
235 echo Line $i >>expected
236 done &&
237 echo Line 8 >>expected &&
238 git add merge &&
239 git commit -q -m "Merge test (pre-merge)" &&
240 git push gitcvs.git >/dev/null &&
241 cd cvswork &&
242 GIT_CONFIG="$git_config" cvs -Q update &&
243 test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
244 diff -q merge ../merge &&
245 ( echo Line 0; cat merge ) >merge.tmp &&
246 mv merge.tmp merge &&
247 cd "$WORKDIR" &&
248 echo Line 8 >>merge &&
249 git add merge &&
250 git commit -q -m "Merge test (merge)" &&
251 git push gitcvs.git >/dev/null &&
252 cd cvswork &&
253 sleep 1 && touch merge &&
254 GIT_CONFIG="$git_config" cvs -Q update &&
255 diff -q merge ../expected'
257 cd "$WORKDIR"
259 cat >expected.C <<EOF
260 <<<<<<< merge.mine
261 Line 0
262 =======
263 LINE 0
264 >>>>>>> merge.3
267 for i in 1 2 3 4 5 6 7 8
269 echo Line $i >>expected.C
270 done
272 test_expect_success 'cvs update (conflict merge)' \
273 '( echo LINE 0; cat merge ) >merge.tmp &&
274 mv merge.tmp merge &&
275 git add merge &&
276 git commit -q -m "Merge test (conflict)" &&
277 git push gitcvs.git >/dev/null &&
278 cd cvswork &&
279 GIT_CONFIG="$git_config" cvs -Q update &&
280 diff -q merge ../expected.C'
282 cd "$WORKDIR"
283 test_expect_success 'cvs update (-C)' \
284 'cd cvswork &&
285 GIT_CONFIG="$git_config" cvs -Q update -C &&
286 diff -q merge ../merge'
288 cd "$WORKDIR"
289 test_expect_success 'cvs update (merge no-op)' \
290 'echo Line 9 >>merge &&
291 cp merge cvswork/merge &&
292 git add merge &&
293 git commit -q -m "Merge test (no-op)" &&
294 git push gitcvs.git >/dev/null &&
295 cd cvswork &&
296 sleep 1 && touch merge &&
297 GIT_CONFIG="$git_config" cvs -Q update &&
298 diff -q merge ../merge'
300 test_done