Merge branch 'maint'
[git.git] / t / t9400-git-cvsserver-server.sh
blob41dcf646d132e35ca37ab6cc75fc2a7e70cc765e
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 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
123 cat >request-conflict <<EOF
124 BEGIN AUTH REQUEST
125 $SERVERDIR
126 anonymous
128 END AUTH REQUEST
129 Root $WORKDIR
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$"'
147 #--------------
148 # CONFIG TESTS
149 #--------------
151 test_expect_success 'gitcvs.enabled = false' \
152 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
153 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
154 then
155 echo unexpected cvs success
156 false
157 else
158 true
159 fi &&
160 cat cvs.log | grep -q "GITCVS emulation disabled" &&
161 test ! -d cvswork2'
163 rm -fr cvswork2
164 test_expect_success 'gitcvs.ext.enabled = true' \
165 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
166 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
167 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
168 diff -q cvswork cvswork2'
170 rm -fr cvswork2
171 test_expect_success 'gitcvs.ext.enabled = false' \
172 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
173 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
174 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
175 then
176 echo unexpected cvs success
177 false
178 else
179 true
180 fi &&
181 cat cvs.log | grep -q "GITCVS emulation disabled" &&
182 test ! -d cvswork2'
184 rm -fr cvswork2
185 test_expect_success 'gitcvs.dbname' \
186 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
187 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
188 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
189 diff -q cvswork cvswork2 &&
190 test -f "$SERVERDIR/gitcvs.ext.master.sqlite" &&
191 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs.ext.master.sqlite"'
193 rm -fr cvswork2
194 test_expect_success 'gitcvs.ext.dbname' \
195 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
196 GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
197 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
198 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
199 diff -q cvswork cvswork2 &&
200 test -f "$SERVERDIR/gitcvs1.ext.master.sqlite" &&
201 test ! -f "$SERVERDIR/gitcvs2.ext.master.sqlite" &&
202 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs1.ext.master.sqlite"'
205 #------------
206 # CVS UPDATE
207 #------------
209 rm -fr "$SERVERDIR"
210 cd "$WORKDIR" &&
211 git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
212 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
213 GIT_DIR="$SERVERDIR" git config --bool gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
214 exit 1
216 test_expect_success 'cvs update (create new file)' \
217 'echo testfile1 >testfile1 &&
218 git add testfile1 &&
219 git commit -q -m "Add testfile1" &&
220 git push gitcvs.git >/dev/null &&
221 cd cvswork &&
222 GIT_CONFIG="$git_config" cvs -Q update &&
223 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
224 diff -q testfile1 ../testfile1'
226 cd "$WORKDIR"
227 test_expect_success 'cvs update (update existing file)' \
228 'echo line 2 >>testfile1 &&
229 git add testfile1 &&
230 git commit -q -m "Append to testfile1" &&
231 git push gitcvs.git >/dev/null &&
232 cd cvswork &&
233 GIT_CONFIG="$git_config" cvs -Q update &&
234 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
235 diff -q testfile1 ../testfile1'
237 cd "$WORKDIR"
238 #TODO: cvsserver doesn't support update w/o -d
239 test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" \
240 'mkdir test &&
241 echo >test/empty &&
242 git add test &&
243 git commit -q -m "Single Subdirectory" &&
244 git push gitcvs.git >/dev/null &&
245 cd cvswork &&
246 GIT_CONFIG="$git_config" cvs -Q update &&
247 test ! -d test'
249 cd "$WORKDIR"
250 test_expect_success 'cvs update (subdirectories)' \
251 '(for dir in A A/B A/B/C A/D E; do
252 mkdir $dir &&
253 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
254 git add $dir;
255 done) &&
256 git commit -q -m "deep sub directory structure" &&
257 git push gitcvs.git >/dev/null &&
258 cd cvswork &&
259 GIT_CONFIG="$git_config" cvs -Q update -d &&
260 (for dir in A A/B A/B/C A/D E; do
261 filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
262 if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
263 diff -q "$dir/$filename" "../$dir/$filename"; then
265 else
266 echo >failure
268 done) &&
269 test ! -f failure'
271 cd "$WORKDIR"
272 test_expect_success 'cvs update (delete file)' \
273 'git rm testfile1 &&
274 git commit -q -m "Remove testfile1" &&
275 git push gitcvs.git >/dev/null &&
276 cd cvswork &&
277 GIT_CONFIG="$git_config" cvs -Q update &&
278 test -z "$(grep testfile1 CVS/Entries)" &&
279 test ! -f testfile1'
281 cd "$WORKDIR"
282 test_expect_success 'cvs update (re-add deleted file)' \
283 'echo readded testfile >testfile1 &&
284 git add testfile1 &&
285 git commit -q -m "Re-Add testfile1" &&
286 git push gitcvs.git >/dev/null &&
287 cd cvswork &&
288 GIT_CONFIG="$git_config" cvs -Q update &&
289 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
290 diff -q testfile1 ../testfile1'
292 cd "$WORKDIR"
293 test_expect_success 'cvs update (merge)' \
294 'echo Line 0 >expected &&
295 for i in 1 2 3 4 5 6 7
297 echo Line $i >>merge
298 echo Line $i >>expected
299 done &&
300 echo Line 8 >>expected &&
301 git add merge &&
302 git commit -q -m "Merge test (pre-merge)" &&
303 git push gitcvs.git >/dev/null &&
304 cd cvswork &&
305 GIT_CONFIG="$git_config" cvs -Q update &&
306 test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
307 diff -q merge ../merge &&
308 ( echo Line 0; cat merge ) >merge.tmp &&
309 mv merge.tmp merge &&
310 cd "$WORKDIR" &&
311 echo Line 8 >>merge &&
312 git add merge &&
313 git commit -q -m "Merge test (merge)" &&
314 git push gitcvs.git >/dev/null &&
315 cd cvswork &&
316 sleep 1 && touch merge &&
317 GIT_CONFIG="$git_config" cvs -Q update &&
318 diff -q merge ../expected'
320 cd "$WORKDIR"
322 cat >expected.C <<EOF
323 <<<<<<< merge.mine
324 Line 0
325 =======
326 LINE 0
327 >>>>>>> merge.3
330 for i in 1 2 3 4 5 6 7 8
332 echo Line $i >>expected.C
333 done
335 test_expect_success 'cvs update (conflict merge)' \
336 '( echo LINE 0; cat merge ) >merge.tmp &&
337 mv merge.tmp merge &&
338 git add merge &&
339 git commit -q -m "Merge test (conflict)" &&
340 git push gitcvs.git >/dev/null &&
341 cd cvswork &&
342 GIT_CONFIG="$git_config" cvs -Q update &&
343 diff -q merge ../expected.C'
345 cd "$WORKDIR"
346 test_expect_success 'cvs update (-C)' \
347 'cd cvswork &&
348 GIT_CONFIG="$git_config" cvs -Q update -C &&
349 diff -q merge ../merge'
351 cd "$WORKDIR"
352 test_expect_success 'cvs update (merge no-op)' \
353 'echo Line 9 >>merge &&
354 cp merge cvswork/merge &&
355 git add merge &&
356 git commit -q -m "Merge test (no-op)" &&
357 git push gitcvs.git >/dev/null &&
358 cd cvswork &&
359 sleep 1 && touch merge &&
360 GIT_CONFIG="$git_config" cvs -Q update &&
361 diff -q merge ../merge'
363 test_done