Prevent case sensitive commit
[git/jr.git] / t / t9400-git-cvsserver-server.sh
blob641303e0a18c1c9958e4dae86d1fcdee644dbcff
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 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$"'
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
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 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false || exit 1
178 test_expect_success 'req_Root (export-all)' \
179 'cat request-anonymous | git-cvsserver --export-all pserver $WORKDIR >log 2>&1 &&
180 tail -n1 log | grep -q "^I LOVE YOU$"'
182 test_expect_failure 'req_Root failure (export-all w/o whitelist)' \
183 'cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 ||
184 false'
186 test_expect_success 'req_Root (everything together)' \
187 'cat request-base | git-cvsserver --export-all --strict-paths --base-path $WORKDIR/ pserver $SERVERDIR >log 2>&1 &&
188 tail -n1 log | grep -q "^I LOVE YOU$"'
190 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true || exit 1
192 #--------------
193 # CONFIG TESTS
194 #--------------
196 test_expect_success 'gitcvs.enabled = false' \
197 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
198 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
199 then
200 echo unexpected cvs success
201 false
202 else
203 true
204 fi &&
205 cat cvs.log | grep -q "GITCVS emulation disabled" &&
206 test ! -d cvswork2'
208 rm -fr cvswork2
209 test_expect_success 'gitcvs.ext.enabled = true' \
210 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
211 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
212 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
213 diff -q cvswork cvswork2'
215 rm -fr cvswork2
216 test_expect_success 'gitcvs.ext.enabled = false' \
217 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
218 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
219 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
220 then
221 echo unexpected cvs success
222 false
223 else
224 true
225 fi &&
226 cat cvs.log | grep -q "GITCVS emulation disabled" &&
227 test ! -d cvswork2'
229 rm -fr cvswork2
230 test_expect_success 'gitcvs.dbname' \
231 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
232 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
233 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
234 diff -q cvswork cvswork2 &&
235 test -f "$SERVERDIR/gitcvs.ext.master.sqlite" &&
236 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs.ext.master.sqlite"'
238 rm -fr cvswork2
239 test_expect_success 'gitcvs.ext.dbname' \
240 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
241 GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
242 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
243 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
244 diff -q cvswork cvswork2 &&
245 test -f "$SERVERDIR/gitcvs1.ext.master.sqlite" &&
246 test ! -f "$SERVERDIR/gitcvs2.ext.master.sqlite" &&
247 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs1.ext.master.sqlite"'
250 #------------
251 # CVS UPDATE
252 #------------
254 rm -fr "$SERVERDIR"
255 cd "$WORKDIR" &&
256 git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
257 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
258 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
259 exit 1
261 test_expect_success 'cvs update (create new file)' \
262 'echo testfile1 >testfile1 &&
263 git add testfile1 &&
264 git commit -q -m "Add testfile1" &&
265 git push gitcvs.git >/dev/null &&
266 cd cvswork &&
267 GIT_CONFIG="$git_config" cvs -Q update &&
268 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
269 diff -q testfile1 ../testfile1'
271 cd "$WORKDIR"
272 test_expect_success 'cvs update (update existing file)' \
273 'echo line 2 >>testfile1 &&
274 git add testfile1 &&
275 git commit -q -m "Append to testfile1" &&
276 git push gitcvs.git >/dev/null &&
277 cd cvswork &&
278 GIT_CONFIG="$git_config" cvs -Q update &&
279 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
280 diff -q testfile1 ../testfile1'
282 cd "$WORKDIR"
283 #TODO: cvsserver doesn't support update w/o -d
284 test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" \
285 'mkdir test &&
286 echo >test/empty &&
287 git add test &&
288 git commit -q -m "Single Subdirectory" &&
289 git push gitcvs.git >/dev/null &&
290 cd cvswork &&
291 GIT_CONFIG="$git_config" cvs -Q update &&
292 test ! -d test'
294 cd "$WORKDIR"
295 test_expect_success 'cvs update (subdirectories)' \
296 '(for dir in A A/B A/B/C A/D E; do
297 mkdir $dir &&
298 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
299 git add $dir;
300 done) &&
301 git commit -q -m "deep sub directory structure" &&
302 git push gitcvs.git >/dev/null &&
303 cd cvswork &&
304 GIT_CONFIG="$git_config" cvs -Q update -d &&
305 (for dir in A A/B A/B/C A/D E; do
306 filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
307 if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
308 diff -q "$dir/$filename" "../$dir/$filename"; then
310 else
311 echo >failure
313 done) &&
314 test ! -f failure'
316 cd "$WORKDIR"
317 test_expect_success 'cvs update (delete file)' \
318 'git rm testfile1 &&
319 git commit -q -m "Remove testfile1" &&
320 git push gitcvs.git >/dev/null &&
321 cd cvswork &&
322 GIT_CONFIG="$git_config" cvs -Q update &&
323 test -z "$(grep testfile1 CVS/Entries)" &&
324 test ! -f testfile1'
326 cd "$WORKDIR"
327 test_expect_success 'cvs update (re-add deleted file)' \
328 'echo readded testfile >testfile1 &&
329 git add testfile1 &&
330 git commit -q -m "Re-Add testfile1" &&
331 git push gitcvs.git >/dev/null &&
332 cd cvswork &&
333 GIT_CONFIG="$git_config" cvs -Q update &&
334 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
335 diff -q testfile1 ../testfile1'
337 cd "$WORKDIR"
338 test_expect_success 'cvs update (merge)' \
339 'echo Line 0 >expected &&
340 for i in 1 2 3 4 5 6 7
342 echo Line $i >>merge
343 echo Line $i >>expected
344 done &&
345 echo Line 8 >>expected &&
346 git add merge &&
347 git commit -q -m "Merge test (pre-merge)" &&
348 git push gitcvs.git >/dev/null &&
349 cd cvswork &&
350 GIT_CONFIG="$git_config" cvs -Q update &&
351 test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
352 diff -q merge ../merge &&
353 ( echo Line 0; cat merge ) >merge.tmp &&
354 mv merge.tmp merge &&
355 cd "$WORKDIR" &&
356 echo Line 8 >>merge &&
357 git add merge &&
358 git commit -q -m "Merge test (merge)" &&
359 git push gitcvs.git >/dev/null &&
360 cd cvswork &&
361 sleep 1 && touch merge &&
362 GIT_CONFIG="$git_config" cvs -Q update &&
363 diff -q merge ../expected'
365 cd "$WORKDIR"
367 cat >expected.C <<EOF
368 <<<<<<< merge.mine
369 Line 0
370 =======
371 LINE 0
372 >>>>>>> merge.3
375 for i in 1 2 3 4 5 6 7 8
377 echo Line $i >>expected.C
378 done
380 test_expect_success 'cvs update (conflict merge)' \
381 '( echo LINE 0; cat merge ) >merge.tmp &&
382 mv merge.tmp merge &&
383 git add merge &&
384 git commit -q -m "Merge test (conflict)" &&
385 git push gitcvs.git >/dev/null &&
386 cd cvswork &&
387 GIT_CONFIG="$git_config" cvs -Q update &&
388 diff -q merge ../expected.C'
390 cd "$WORKDIR"
391 test_expect_success 'cvs update (-C)' \
392 'cd cvswork &&
393 GIT_CONFIG="$git_config" cvs -Q update -C &&
394 diff -q merge ../merge'
396 cd "$WORKDIR"
397 test_expect_success 'cvs update (merge no-op)' \
398 'echo Line 9 >>merge &&
399 cp merge cvswork/merge &&
400 git add merge &&
401 git commit -q -m "Merge test (no-op)" &&
402 git push gitcvs.git >/dev/null &&
403 cd cvswork &&
404 sleep 1 && touch merge &&
405 GIT_CONFIG="$git_config" cvs -Q update &&
406 diff -q merge ../merge'
408 test_done