]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9400-git-cvsserver-server.sh
cvsserver: Do not include status output for subdirectories if -l is passed
[thirdparty/git.git] / t / t9400-git-cvsserver-server.sh
CommitLineData
b3b53439
FL
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
469be5b2
JH
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}
b3b53439
FL
25
26unset GIT_DIR GIT_CONFIG
27WORKDIR=$(pwd)
28SERVERDIR=$(pwd)/gitcvs.git
a25907da 29git_config="$SERVERDIR/config"
b3b53439 30CVSROOT=":fork:$SERVERDIR"
a25907da 31CVSWORK="$(pwd)/cvswork"
b3b53439
FL
32CVS_SERVER=git-cvsserver
33export CVSROOT CVS_SERVER
34
35rm -rf "$CVSWORK" "$SERVERDIR"
75493765
SP
36test_expect_success 'setup' '
37 echo >empty &&
b3b53439
FL
38 git add empty &&
39 git commit -q -m "First Commit" &&
e509db99
SP
40 mkdir secondroot &&
41 ( cd secondroot &&
42 git init &&
43 touch secondrootfile &&
44 git add secondrootfile &&
45 git commit -m "second root") &&
46 git pull secondroot master &&
b3b53439
FL
47 git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
48 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
75493765
SP
49 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log"
50'
b3b53439
FL
51
52# note that cvs doesn't accept absolute pathnames
53# as argument to co -d
54test_expect_success 'basic checkout' \
a25907da 55 'GIT_CONFIG="$git_config" cvs -Q co -d cvswork master &&
e509db99 56 test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | head -n 1))" = "empty/1.1/"
b4ce54fc 57 test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | sed -ne \$p))" = "secondrootfile/1.1/"'
b3b53439 58
240ba7f2
FL
59#------------------------
60# PSERVER AUTHENTICATION
61#------------------------
62
63cat >request-anonymous <<EOF
64BEGIN AUTH REQUEST
65$SERVERDIR
66anonymous
67
68END AUTH REQUEST
69EOF
70
71cat >request-git <<EOF
72BEGIN AUTH REQUEST
73$SERVERDIR
74git
75
76END AUTH REQUEST
77EOF
78
24a97d84
FL
79cat >login-anonymous <<EOF
80BEGIN VERIFICATION REQUEST
81$SERVERDIR
82anonymous
83
84END VERIFICATION REQUEST
85EOF
86
87cat >login-git <<EOF
88BEGIN VERIFICATION REQUEST
89$SERVERDIR
90git
91
92END VERIFICATION REQUEST
93EOF
94
240ba7f2
FL
95test_expect_success 'pserver authentication' \
96 'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
b4ce54fc 97 sed -ne \$p log | grep "^I LOVE YOU$"'
240ba7f2
FL
98
99test_expect_success 'pserver authentication failure (non-anonymous user)' \
100 'if cat request-git | git-cvsserver pserver >log 2>&1
101 then
102 false
103 else
104 true
105 fi &&
b4ce54fc 106 sed -ne \$p log | grep "^I HATE YOU$"'
240ba7f2 107
24a97d84
FL
108test_expect_success 'pserver authentication (login)' \
109 'cat login-anonymous | git-cvsserver pserver >log 2>&1 &&
b4ce54fc 110 sed -ne \$p log | grep "^I LOVE YOU$"'
24a97d84
FL
111
112test_expect_success 'pserver authentication failure (login/non-anonymous user)' \
113 'if cat login-git | git-cvsserver pserver >log 2>&1
114 then
115 false
116 else
117 true
118 fi &&
b4ce54fc 119 sed -ne \$p log | grep "^I HATE YOU$"'
24a97d84 120
240ba7f2 121
4890888d
FL
122# misuse pserver authentication for testing of req_Root
123
124cat >request-relative <<EOF
125BEGIN AUTH REQUEST
126gitcvs.git
127anonymous
128
129END AUTH REQUEST
130EOF
131
132cat >request-conflict <<EOF
133BEGIN AUTH REQUEST
134$SERVERDIR
135anonymous
136
137END AUTH REQUEST
138Root $WORKDIR
139EOF
140
141test_expect_success 'req_Root failure (relative pathname)' \
142 'if cat request-relative | git-cvsserver pserver >log 2>&1
143 then
144 echo unexpected success
145 false
146 else
147 true
148 fi &&
aadbe44f 149 tail log | grep "^error 1 Root must be an absolute pathname$"'
4890888d
FL
150
151test_expect_success 'req_Root failure (conflicting roots)' \
152 'cat request-conflict | git-cvsserver pserver >log 2>&1 &&
aadbe44f 153 tail log | grep "^error 1 Conflicting roots specified$"'
4890888d 154
693b6327
FL
155test_expect_success 'req_Root (strict paths)' \
156 'cat request-anonymous | git-cvsserver --strict-paths pserver $SERVERDIR >log 2>&1 &&
b4ce54fc 157 sed -ne \$p log | grep "^I LOVE YOU$"'
693b6327 158
41ac414e
JH
159test_expect_success 'req_Root failure (strict-paths)' '
160 ! cat request-anonymous |
161 git-cvsserver --strict-paths pserver $WORKDIR >log 2>&1
162'
693b6327
FL
163
164test_expect_success 'req_Root (w/o strict-paths)' \
165 'cat request-anonymous | git-cvsserver pserver $WORKDIR/ >log 2>&1 &&
b4ce54fc 166 sed -ne \$p log | grep "^I LOVE YOU$"'
693b6327 167
41ac414e
JH
168test_expect_success 'req_Root failure (w/o strict-paths)' '
169 ! cat request-anonymous |
170 git-cvsserver pserver $WORKDIR/gitcvs >log 2>&1
171'
693b6327
FL
172
173cat >request-base <<EOF
174BEGIN AUTH REQUEST
175/gitcvs.git
176anonymous
177
178END AUTH REQUEST
fd1cd91e 179Root /gitcvs.git
693b6327
FL
180EOF
181
182test_expect_success 'req_Root (base-path)' \
183 'cat request-base | git-cvsserver --strict-paths --base-path $WORKDIR/ pserver $SERVERDIR >log 2>&1 &&
b4ce54fc 184 sed -ne \$p log | grep "^I LOVE YOU$"'
693b6327 185
41ac414e
JH
186test_expect_success 'req_Root failure (base-path)' '
187 ! cat request-anonymous |
188 git-cvsserver --strict-paths --base-path $WORKDIR pserver $SERVERDIR >log 2>&1
189'
4890888d 190
226bccb9
FL
191GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false || exit 1
192
193test_expect_success 'req_Root (export-all)' \
194 'cat request-anonymous | git-cvsserver --export-all pserver $WORKDIR >log 2>&1 &&
b4ce54fc 195 sed -ne \$p log | grep "^I LOVE YOU$"'
226bccb9 196
41ac414e
JH
197test_expect_success 'req_Root failure (export-all w/o whitelist)' \
198 '! (cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 || false)'
226bccb9
FL
199
200test_expect_success 'req_Root (everything together)' \
201 'cat request-base | git-cvsserver --export-all --strict-paths --base-path $WORKDIR/ pserver $SERVERDIR >log 2>&1 &&
b4ce54fc 202 sed -ne \$p log | grep "^I LOVE YOU$"'
226bccb9
FL
203
204GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true || exit 1
205
1d431b22
FL
206#--------------
207# CONFIG TESTS
208#--------------
209
210test_expect_success 'gitcvs.enabled = false' \
211 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
212 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
213 then
214 echo unexpected cvs success
215 false
216 else
217 true
218 fi &&
aadbe44f 219 grep "GITCVS emulation disabled" cvs.log &&
1d431b22
FL
220 test ! -d cvswork2'
221
222rm -fr cvswork2
223test_expect_success 'gitcvs.ext.enabled = true' \
224 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
225 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
226 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
227 diff -q cvswork cvswork2'
228
229rm -fr cvswork2
230test_expect_success 'gitcvs.ext.enabled = false' \
231 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
232 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
233 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
234 then
235 echo unexpected cvs success
236 false
237 else
238 true
239 fi &&
aadbe44f 240 grep "GITCVS emulation disabled" cvs.log &&
1d431b22
FL
241 test ! -d cvswork2'
242
243rm -fr cvswork2
244test_expect_success 'gitcvs.dbname' \
245 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
246 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
247 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
248 diff -q cvswork cvswork2 &&
249 test -f "$SERVERDIR/gitcvs.ext.master.sqlite" &&
250 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs.ext.master.sqlite"'
251
252rm -fr cvswork2
253test_expect_success 'gitcvs.ext.dbname' \
254 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
255 GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
256 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
257 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
258 diff -q cvswork cvswork2 &&
259 test -f "$SERVERDIR/gitcvs1.ext.master.sqlite" &&
260 test ! -f "$SERVERDIR/gitcvs2.ext.master.sqlite" &&
261 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs1.ext.master.sqlite"'
262
263
264#------------
265# CVS UPDATE
266#------------
267
268rm -fr "$SERVERDIR"
269cd "$WORKDIR" &&
270git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
271GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
db1696b8 272GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
1d431b22
FL
273exit 1
274
b3b53439
FL
275test_expect_success 'cvs update (create new file)' \
276 'echo testfile1 >testfile1 &&
277 git add testfile1 &&
278 git commit -q -m "Add testfile1" &&
279 git push gitcvs.git >/dev/null &&
280 cd cvswork &&
a25907da 281 GIT_CONFIG="$git_config" cvs -Q update &&
b3b53439
FL
282 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
283 diff -q testfile1 ../testfile1'
284
285cd "$WORKDIR"
286test_expect_success 'cvs update (update existing file)' \
287 'echo line 2 >>testfile1 &&
288 git add testfile1 &&
289 git commit -q -m "Append to testfile1" &&
290 git push gitcvs.git >/dev/null &&
291 cd cvswork &&
a25907da 292 GIT_CONFIG="$git_config" cvs -Q update &&
b3b53439
FL
293 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
294 diff -q testfile1 ../testfile1'
295
296cd "$WORKDIR"
297#TODO: cvsserver doesn't support update w/o -d
41ac414e
JH
298test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" '
299 mkdir test &&
b3b53439
FL
300 echo >test/empty &&
301 git add test &&
302 git commit -q -m "Single Subdirectory" &&
303 git push gitcvs.git >/dev/null &&
304 cd cvswork &&
a25907da 305 GIT_CONFIG="$git_config" cvs -Q update &&
41ac414e
JH
306 test ! -d test
307'
b3b53439
FL
308
309cd "$WORKDIR"
310test_expect_success 'cvs update (subdirectories)' \
311 '(for dir in A A/B A/B/C A/D E; do
312 mkdir $dir &&
313 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
314 git add $dir;
315 done) &&
316 git commit -q -m "deep sub directory structure" &&
317 git push gitcvs.git >/dev/null &&
318 cd cvswork &&
a25907da 319 GIT_CONFIG="$git_config" cvs -Q update -d &&
b3b53439
FL
320 (for dir in A A/B A/B/C A/D E; do
321 filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
322 if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
323 diff -q "$dir/$filename" "../$dir/$filename"; then
324 :
325 else
326 echo >failure
327 fi
328 done) &&
329 test ! -f failure'
330
331cd "$WORKDIR"
332test_expect_success 'cvs update (delete file)' \
333 'git rm testfile1 &&
334 git commit -q -m "Remove testfile1" &&
335 git push gitcvs.git >/dev/null &&
336 cd cvswork &&
a25907da 337 GIT_CONFIG="$git_config" cvs -Q update &&
b3b53439
FL
338 test -z "$(grep testfile1 CVS/Entries)" &&
339 test ! -f testfile1'
340
341cd "$WORKDIR"
342test_expect_success 'cvs update (re-add deleted file)' \
343 'echo readded testfile >testfile1 &&
344 git add testfile1 &&
345 git commit -q -m "Re-Add testfile1" &&
346 git push gitcvs.git >/dev/null &&
347 cd cvswork &&
a25907da 348 GIT_CONFIG="$git_config" cvs -Q update &&
b3b53439
FL
349 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
350 diff -q testfile1 ../testfile1'
351
1978659a
FL
352cd "$WORKDIR"
353test_expect_success 'cvs update (merge)' \
354 'echo Line 0 >expected &&
355 for i in 1 2 3 4 5 6 7
356 do
357 echo Line $i >>merge
358 echo Line $i >>expected
359 done &&
360 echo Line 8 >>expected &&
361 git add merge &&
362 git commit -q -m "Merge test (pre-merge)" &&
363 git push gitcvs.git >/dev/null &&
364 cd cvswork &&
365 GIT_CONFIG="$git_config" cvs -Q update &&
366 test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
367 diff -q merge ../merge &&
368 ( echo Line 0; cat merge ) >merge.tmp &&
369 mv merge.tmp merge &&
370 cd "$WORKDIR" &&
371 echo Line 8 >>merge &&
372 git add merge &&
373 git commit -q -m "Merge test (merge)" &&
374 git push gitcvs.git >/dev/null &&
375 cd cvswork &&
b3c81cff 376 sleep 1 && touch merge &&
1978659a
FL
377 GIT_CONFIG="$git_config" cvs -Q update &&
378 diff -q merge ../expected'
379
380cd "$WORKDIR"
381
382cat >expected.C <<EOF
383<<<<<<< merge.mine
384Line 0
385=======
386LINE 0
387>>>>>>> merge.3
388EOF
389
390for i in 1 2 3 4 5 6 7 8
391do
392 echo Line $i >>expected.C
393done
394
395test_expect_success 'cvs update (conflict merge)' \
396 '( echo LINE 0; cat merge ) >merge.tmp &&
397 mv merge.tmp merge &&
398 git add merge &&
399 git commit -q -m "Merge test (conflict)" &&
400 git push gitcvs.git >/dev/null &&
401 cd cvswork &&
402 GIT_CONFIG="$git_config" cvs -Q update &&
403 diff -q merge ../expected.C'
404
405cd "$WORKDIR"
406test_expect_success 'cvs update (-C)' \
407 'cd cvswork &&
408 GIT_CONFIG="$git_config" cvs -Q update -C &&
409 diff -q merge ../merge'
410
411cd "$WORKDIR"
412test_expect_success 'cvs update (merge no-op)' \
413 'echo Line 9 >>merge &&
414 cp merge cvswork/merge &&
415 git add merge &&
416 git commit -q -m "Merge test (no-op)" &&
417 git push gitcvs.git >/dev/null &&
418 cd cvswork &&
b3c81cff 419 sleep 1 && touch merge &&
1978659a
FL
420 GIT_CONFIG="$git_config" cvs -Q update &&
421 diff -q merge ../merge'
422
b3b53439 423test_done