392f890ce61c4eff15ce2269e034004d35cf1570
1#!/bin/sh
2#
3# Copyright (c) 2007 Frank Lichtenheld
4#
5
6test_description='git-cvsserver access
7
8tests read access to a git repository with the
9cvs CLI client via git-cvsserver server'
10
11. ./test-lib.sh
12
13cvs >/dev/null 2>&1
14if test $? -ne 1
15then
16 test_expect_success 'skipping git-cvsserver tests, cvs not found' :
17 test_done
18 exit
19fi
20perl -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}
25
26unset GIT_DIR GIT_CONFIG
27WORKDIR=$(pwd)
28SERVERDIR=$(pwd)/gitcvs.git
29git_config="$SERVERDIR/config"
30CVSROOT=":fork:$SERVERDIR"
31CVSWORK="$(pwd)/cvswork"
32CVS_SERVER=git-cvsserver
33export CVSROOT CVS_SERVER
34
35rm -rf "$CVSWORK" "$SERVERDIR"
36echo >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
43
44# note that cvs doesn't accept absolute pathnames
45# as argument to co -d
46test_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/"'
49
50#------------------------
51# PSERVER AUTHENTICATION
52#------------------------
53
54cat >request-anonymous <<EOF
55BEGIN AUTH REQUEST
56$SERVERDIR
57anonymous
58
59END AUTH REQUEST
60EOF
61
62cat >request-git <<EOF
63BEGIN AUTH REQUEST
64$SERVERDIR
65git
66
67END AUTH REQUEST
68EOF
69
70cat >login-anonymous <<EOF
71BEGIN VERIFICATION REQUEST
72$SERVERDIR
73anonymous
74
75END VERIFICATION REQUEST
76EOF
77
78cat >login-git <<EOF
79BEGIN VERIFICATION REQUEST
80$SERVERDIR
81git
82
83END VERIFICATION REQUEST
84EOF
85
86test_expect_success 'pserver authentication' \
87 'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
88 tail -n1 log | grep -q "^I LOVE YOU$"'
89
90test_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$"'
98
99test_expect_success 'pserver authentication (login)' \
100 'cat login-anonymous | git-cvsserver pserver >log 2>&1 &&
101 tail -n1 log | grep -q "^I LOVE YOU$"'
102
103test_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$"'
111
112
113# misuse pserver authentication for testing of req_Root
114
115cat >request-relative <<EOF
116BEGIN AUTH REQUEST
117gitcvs.git
118anonymous
119
120END AUTH REQUEST
121EOF
122
123cat >request-conflict <<EOF
124BEGIN AUTH REQUEST
125$SERVERDIR
126anonymous
127
128END AUTH REQUEST
129Root $WORKDIR
130EOF
131
132test_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$"'
141
142test_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$"'
145
146test_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$"'
149
150test_expect_failure 'req_Root failure (strict-paths)' \
151 'cat request-anonymous | git-cvsserver --strict-paths pserver $WORKDIR >log 2>&1'
152
153test_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$"'
156
157test_expect_failure 'req_Root failure (w/o strict-paths)' \
158 'cat request-anonymous | git-cvsserver pserver $WORKDIR/gitcvs >log 2>&1'
159
160cat >request-base <<EOF
161BEGIN AUTH REQUEST
162/gitcvs.git
163anonymous
164
165END AUTH REQUEST
166EOF
167
168test_expect_success 'req_Root (base-path)' \
169 'cat request-base | git-cvsserver --strict-paths --base-path $WORKDIR/ pserver $SERVERDIR >log 2>&1 &&
170 tail -n1 log | grep -q "^I LOVE YOU$"'
171
172test_expect_failure 'req_Root failure (base-path)' \
173 'cat request-anonymous | git-cvsserver --strict-paths --base-path $WORKDIR pserver $SERVERDIR >log 2>&1'
174
175#--------------
176# CONFIG TESTS
177#--------------
178
179test_expect_success 'gitcvs.enabled = false' \
180 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
181 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
182 then
183 echo unexpected cvs success
184 false
185 else
186 true
187 fi &&
188 cat cvs.log | grep -q "GITCVS emulation disabled" &&
189 test ! -d cvswork2'
190
191rm -fr cvswork2
192test_expect_success 'gitcvs.ext.enabled = true' \
193 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
194 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
195 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
196 diff -q cvswork cvswork2'
197
198rm -fr cvswork2
199test_expect_success 'gitcvs.ext.enabled = false' \
200 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
201 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
202 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
203 then
204 echo unexpected cvs success
205 false
206 else
207 true
208 fi &&
209 cat cvs.log | grep -q "GITCVS emulation disabled" &&
210 test ! -d cvswork2'
211
212rm -fr cvswork2
213test_expect_success 'gitcvs.dbname' \
214 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
215 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
216 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
217 diff -q cvswork cvswork2 &&
218 test -f "$SERVERDIR/gitcvs.ext.master.sqlite" &&
219 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs.ext.master.sqlite"'
220
221rm -fr cvswork2
222test_expect_success 'gitcvs.ext.dbname' \
223 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
224 GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
225 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
226 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
227 diff -q cvswork cvswork2 &&
228 test -f "$SERVERDIR/gitcvs1.ext.master.sqlite" &&
229 test ! -f "$SERVERDIR/gitcvs2.ext.master.sqlite" &&
230 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs1.ext.master.sqlite"'
231
232
233#------------
234# CVS UPDATE
235#------------
236
237rm -fr "$SERVERDIR"
238cd "$WORKDIR" &&
239git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
240GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
241GIT_DIR="$SERVERDIR" git config --bool gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
242exit 1
243
244test_expect_success 'cvs update (create new file)' \
245 'echo testfile1 >testfile1 &&
246 git add testfile1 &&
247 git commit -q -m "Add testfile1" &&
248 git push gitcvs.git >/dev/null &&
249 cd cvswork &&
250 GIT_CONFIG="$git_config" cvs -Q update &&
251 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
252 diff -q testfile1 ../testfile1'
253
254cd "$WORKDIR"
255test_expect_success 'cvs update (update existing file)' \
256 'echo line 2 >>testfile1 &&
257 git add testfile1 &&
258 git commit -q -m "Append to testfile1" &&
259 git push gitcvs.git >/dev/null &&
260 cd cvswork &&
261 GIT_CONFIG="$git_config" cvs -Q update &&
262 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
263 diff -q testfile1 ../testfile1'
264
265cd "$WORKDIR"
266#TODO: cvsserver doesn't support update w/o -d
267test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" \
268 'mkdir test &&
269 echo >test/empty &&
270 git add test &&
271 git commit -q -m "Single Subdirectory" &&
272 git push gitcvs.git >/dev/null &&
273 cd cvswork &&
274 GIT_CONFIG="$git_config" cvs -Q update &&
275 test ! -d test'
276
277cd "$WORKDIR"
278test_expect_success 'cvs update (subdirectories)' \
279 '(for dir in A A/B A/B/C A/D E; do
280 mkdir $dir &&
281 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
282 git add $dir;
283 done) &&
284 git commit -q -m "deep sub directory structure" &&
285 git push gitcvs.git >/dev/null &&
286 cd cvswork &&
287 GIT_CONFIG="$git_config" cvs -Q update -d &&
288 (for dir in A A/B A/B/C A/D E; do
289 filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
290 if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
291 diff -q "$dir/$filename" "../$dir/$filename"; then
292 :
293 else
294 echo >failure
295 fi
296 done) &&
297 test ! -f failure'
298
299cd "$WORKDIR"
300test_expect_success 'cvs update (delete file)' \
301 'git rm testfile1 &&
302 git commit -q -m "Remove testfile1" &&
303 git push gitcvs.git >/dev/null &&
304 cd cvswork &&
305 GIT_CONFIG="$git_config" cvs -Q update &&
306 test -z "$(grep testfile1 CVS/Entries)" &&
307 test ! -f testfile1'
308
309cd "$WORKDIR"
310test_expect_success 'cvs update (re-add deleted file)' \
311 'echo readded testfile >testfile1 &&
312 git add testfile1 &&
313 git commit -q -m "Re-Add testfile1" &&
314 git push gitcvs.git >/dev/null &&
315 cd cvswork &&
316 GIT_CONFIG="$git_config" cvs -Q update &&
317 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
318 diff -q testfile1 ../testfile1'
319
320cd "$WORKDIR"
321test_expect_success 'cvs update (merge)' \
322 'echo Line 0 >expected &&
323 for i in 1 2 3 4 5 6 7
324 do
325 echo Line $i >>merge
326 echo Line $i >>expected
327 done &&
328 echo Line 8 >>expected &&
329 git add merge &&
330 git commit -q -m "Merge test (pre-merge)" &&
331 git push gitcvs.git >/dev/null &&
332 cd cvswork &&
333 GIT_CONFIG="$git_config" cvs -Q update &&
334 test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
335 diff -q merge ../merge &&
336 ( echo Line 0; cat merge ) >merge.tmp &&
337 mv merge.tmp merge &&
338 cd "$WORKDIR" &&
339 echo Line 8 >>merge &&
340 git add merge &&
341 git commit -q -m "Merge test (merge)" &&
342 git push gitcvs.git >/dev/null &&
343 cd cvswork &&
344 sleep 1 && touch merge &&
345 GIT_CONFIG="$git_config" cvs -Q update &&
346 diff -q merge ../expected'
347
348cd "$WORKDIR"
349
350cat >expected.C <<EOF
351<<<<<<< merge.mine
352Line 0
353=======
354LINE 0
355>>>>>>> merge.3
356EOF
357
358for i in 1 2 3 4 5 6 7 8
359do
360 echo Line $i >>expected.C
361done
362
363test_expect_success 'cvs update (conflict merge)' \
364 '( echo LINE 0; cat merge ) >merge.tmp &&
365 mv merge.tmp merge &&
366 git add merge &&
367 git commit -q -m "Merge test (conflict)" &&
368 git push gitcvs.git >/dev/null &&
369 cd cvswork &&
370 GIT_CONFIG="$git_config" cvs -Q update &&
371 diff -q merge ../expected.C'
372
373cd "$WORKDIR"
374test_expect_success 'cvs update (-C)' \
375 'cd cvswork &&
376 GIT_CONFIG="$git_config" cvs -Q update -C &&
377 diff -q merge ../merge'
378
379cd "$WORKDIR"
380test_expect_success 'cvs update (merge no-op)' \
381 'echo Line 9 >>merge &&
382 cp merge cvswork/merge &&
383 git add merge &&
384 git commit -q -m "Merge test (no-op)" &&
385 git push gitcvs.git >/dev/null &&
386 cd cvswork &&
387 sleep 1 && touch merge &&
388 GIT_CONFIG="$git_config" cvs -Q update &&
389 diff -q merge ../merge'
390
391test_done