]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9400-git-cvsserver-server.sh
status: fix bug with missing --ignore files
[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
1b19ccd2
JK
13if ! test_have_prereq PERL; then
14 say 'skipping git cvsserver tests, perl not available'
15 test_done
16fi
b3b53439
FL
17cvs >/dev/null 2>&1
18if test $? -ne 1
19then
fae74a04 20 say 'skipping git-cvsserver tests, cvs not found'
b3b53439 21 test_done
b3b53439 22fi
be38ca3d 23"$PERL_PATH" -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
fae74a04 24 say 'skipping git-cvsserver tests, Perl SQLite interface unavailable'
469be5b2 25 test_done
469be5b2 26}
b3b53439
FL
27
28unset GIT_DIR GIT_CONFIG
29WORKDIR=$(pwd)
30SERVERDIR=$(pwd)/gitcvs.git
a25907da 31git_config="$SERVERDIR/config"
b3b53439 32CVSROOT=":fork:$SERVERDIR"
a25907da 33CVSWORK="$(pwd)/cvswork"
b3b53439
FL
34CVS_SERVER=git-cvsserver
35export CVSROOT CVS_SERVER
36
37rm -rf "$CVSWORK" "$SERVERDIR"
75493765
SP
38test_expect_success 'setup' '
39 echo >empty &&
b3b53439
FL
40 git add empty &&
41 git commit -q -m "First Commit" &&
e509db99
SP
42 mkdir secondroot &&
43 ( cd secondroot &&
44 git init &&
45 touch secondrootfile &&
46 git add secondrootfile &&
47 git commit -m "second root") &&
48 git pull secondroot master &&
7fd3ef1f 49 git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
b3b53439 50 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
75493765
SP
51 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log"
52'
b3b53439
FL
53
54# note that cvs doesn't accept absolute pathnames
55# as argument to co -d
56test_expect_success 'basic checkout' \
a25907da 57 'GIT_CONFIG="$git_config" cvs -Q co -d cvswork master &&
e509db99 58 test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | head -n 1))" = "empty/1.1/"
b4ce54fc 59 test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | sed -ne \$p))" = "secondrootfile/1.1/"'
b3b53439 60
240ba7f2
FL
61#------------------------
62# PSERVER AUTHENTICATION
63#------------------------
64
65cat >request-anonymous <<EOF
66BEGIN AUTH REQUEST
67$SERVERDIR
68anonymous
69
70END AUTH REQUEST
71EOF
72
73cat >request-git <<EOF
74BEGIN AUTH REQUEST
75$SERVERDIR
76git
77
78END AUTH REQUEST
79EOF
80
24a97d84
FL
81cat >login-anonymous <<EOF
82BEGIN VERIFICATION REQUEST
83$SERVERDIR
84anonymous
85
86END VERIFICATION REQUEST
87EOF
88
89cat >login-git <<EOF
90BEGIN VERIFICATION REQUEST
91$SERVERDIR
92git
93
94END VERIFICATION REQUEST
95EOF
96
240ba7f2
FL
97test_expect_success 'pserver authentication' \
98 'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
9524cf29 99 sed -ne \$p log | grep "^I LOVE YOU\$"'
240ba7f2
FL
100
101test_expect_success 'pserver authentication failure (non-anonymous user)' \
102 'if cat request-git | git-cvsserver pserver >log 2>&1
103 then
104 false
105 else
106 true
107 fi &&
9524cf29 108 sed -ne \$p log | grep "^I HATE YOU\$"'
240ba7f2 109
24a97d84
FL
110test_expect_success 'pserver authentication (login)' \
111 'cat login-anonymous | git-cvsserver pserver >log 2>&1 &&
9524cf29 112 sed -ne \$p log | grep "^I LOVE YOU\$"'
24a97d84
FL
113
114test_expect_success 'pserver authentication failure (login/non-anonymous user)' \
115 'if cat login-git | git-cvsserver pserver >log 2>&1
116 then
117 false
118 else
119 true
120 fi &&
9524cf29 121 sed -ne \$p log | grep "^I HATE YOU\$"'
24a97d84 122
240ba7f2 123
4890888d
FL
124# misuse pserver authentication for testing of req_Root
125
126cat >request-relative <<EOF
127BEGIN AUTH REQUEST
128gitcvs.git
129anonymous
130
131END AUTH REQUEST
132EOF
133
134cat >request-conflict <<EOF
135BEGIN AUTH REQUEST
136$SERVERDIR
137anonymous
138
139END AUTH REQUEST
140Root $WORKDIR
141EOF
142
143test_expect_success 'req_Root failure (relative pathname)' \
144 'if cat request-relative | git-cvsserver pserver >log 2>&1
145 then
146 echo unexpected success
147 false
148 else
149 true
150 fi &&
aadbe44f 151 tail log | grep "^error 1 Root must be an absolute pathname$"'
4890888d
FL
152
153test_expect_success 'req_Root failure (conflicting roots)' \
154 'cat request-conflict | git-cvsserver pserver >log 2>&1 &&
aadbe44f 155 tail log | grep "^error 1 Conflicting roots specified$"'
4890888d 156
693b6327 157test_expect_success 'req_Root (strict paths)' \
f69e836f 158 'cat request-anonymous | git-cvsserver --strict-paths pserver "$SERVERDIR" >log 2>&1 &&
9524cf29 159 sed -ne \$p log | grep "^I LOVE YOU\$"'
693b6327 160
41ac414e
JH
161test_expect_success 'req_Root failure (strict-paths)' '
162 ! cat request-anonymous |
f69e836f 163 git-cvsserver --strict-paths pserver "$WORKDIR" >log 2>&1
41ac414e 164'
693b6327
FL
165
166test_expect_success 'req_Root (w/o strict-paths)' \
f69e836f 167 'cat request-anonymous | git-cvsserver pserver "$WORKDIR/" >log 2>&1 &&
9524cf29 168 sed -ne \$p log | grep "^I LOVE YOU\$"'
693b6327 169
41ac414e
JH
170test_expect_success 'req_Root failure (w/o strict-paths)' '
171 ! cat request-anonymous |
f69e836f 172 git-cvsserver pserver "$WORKDIR/gitcvs" >log 2>&1
41ac414e 173'
693b6327
FL
174
175cat >request-base <<EOF
176BEGIN AUTH REQUEST
177/gitcvs.git
178anonymous
179
180END AUTH REQUEST
fd1cd91e 181Root /gitcvs.git
693b6327
FL
182EOF
183
184test_expect_success 'req_Root (base-path)' \
f69e836f 185 'cat request-base | git-cvsserver --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
9524cf29 186 sed -ne \$p log | grep "^I LOVE YOU\$"'
693b6327 187
41ac414e
JH
188test_expect_success 'req_Root failure (base-path)' '
189 ! cat request-anonymous |
f69e836f 190 git-cvsserver --strict-paths --base-path "$WORKDIR" pserver "$SERVERDIR" >log 2>&1
41ac414e 191'
4890888d 192
226bccb9
FL
193GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false || exit 1
194
195test_expect_success 'req_Root (export-all)' \
f69e836f 196 'cat request-anonymous | git-cvsserver --export-all pserver "$WORKDIR" >log 2>&1 &&
9524cf29 197 sed -ne \$p log | grep "^I LOVE YOU\$"'
226bccb9 198
41ac414e
JH
199test_expect_success 'req_Root failure (export-all w/o whitelist)' \
200 '! (cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 || false)'
226bccb9
FL
201
202test_expect_success 'req_Root (everything together)' \
f69e836f 203 'cat request-base | git-cvsserver --export-all --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
9524cf29 204 sed -ne \$p log | grep "^I LOVE YOU\$"'
226bccb9
FL
205
206GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true || exit 1
207
1d431b22
FL
208#--------------
209# CONFIG TESTS
210#--------------
211
212test_expect_success 'gitcvs.enabled = false' \
213 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
214 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
215 then
216 echo unexpected cvs success
217 false
218 else
219 true
220 fi &&
aadbe44f 221 grep "GITCVS emulation disabled" cvs.log &&
1d431b22
FL
222 test ! -d cvswork2'
223
224rm -fr cvswork2
225test_expect_success 'gitcvs.ext.enabled = true' \
226 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
227 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
228 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
4a2284b9 229 test_cmp cvswork cvswork2'
1d431b22
FL
230
231rm -fr cvswork2
232test_expect_success 'gitcvs.ext.enabled = false' \
233 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
234 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
235 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
236 then
237 echo unexpected cvs success
238 false
239 else
240 true
241 fi &&
aadbe44f 242 grep "GITCVS emulation disabled" cvs.log &&
1d431b22
FL
243 test ! -d cvswork2'
244
245rm -fr cvswork2
246test_expect_success 'gitcvs.dbname' \
247 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
248 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
249 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
4a2284b9 250 test_cmp cvswork cvswork2 &&
1d431b22
FL
251 test -f "$SERVERDIR/gitcvs.ext.master.sqlite" &&
252 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs.ext.master.sqlite"'
253
254rm -fr cvswork2
255test_expect_success 'gitcvs.ext.dbname' \
256 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
257 GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
258 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
259 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
4a2284b9 260 test_cmp cvswork cvswork2 &&
1d431b22
FL
261 test -f "$SERVERDIR/gitcvs1.ext.master.sqlite" &&
262 test ! -f "$SERVERDIR/gitcvs2.ext.master.sqlite" &&
263 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs1.ext.master.sqlite"'
264
265
266#------------
267# CVS UPDATE
268#------------
269
270rm -fr "$SERVERDIR"
271cd "$WORKDIR" &&
7fd3ef1f 272git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
1d431b22 273GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
db1696b8 274GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
1d431b22
FL
275exit 1
276
b3b53439
FL
277test_expect_success 'cvs update (create new file)' \
278 'echo testfile1 >testfile1 &&
279 git add testfile1 &&
280 git commit -q -m "Add testfile1" &&
281 git push gitcvs.git >/dev/null &&
282 cd cvswork &&
a25907da 283 GIT_CONFIG="$git_config" cvs -Q update &&
b3b53439 284 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
4a2284b9 285 test_cmp testfile1 ../testfile1'
b3b53439
FL
286
287cd "$WORKDIR"
288test_expect_success 'cvs update (update existing file)' \
289 'echo line 2 >>testfile1 &&
290 git add testfile1 &&
291 git commit -q -m "Append to testfile1" &&
292 git push gitcvs.git >/dev/null &&
293 cd cvswork &&
a25907da 294 GIT_CONFIG="$git_config" cvs -Q update &&
b3b53439 295 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
4a2284b9 296 test_cmp testfile1 ../testfile1'
b3b53439
FL
297
298cd "$WORKDIR"
299#TODO: cvsserver doesn't support update w/o -d
41ac414e
JH
300test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" '
301 mkdir test &&
b3b53439
FL
302 echo >test/empty &&
303 git add test &&
304 git commit -q -m "Single Subdirectory" &&
305 git push gitcvs.git >/dev/null &&
306 cd cvswork &&
a25907da 307 GIT_CONFIG="$git_config" cvs -Q update &&
41ac414e
JH
308 test ! -d test
309'
b3b53439
FL
310
311cd "$WORKDIR"
312test_expect_success 'cvs update (subdirectories)' \
313 '(for dir in A A/B A/B/C A/D E; do
314 mkdir $dir &&
315 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
316 git add $dir;
317 done) &&
318 git commit -q -m "deep sub directory structure" &&
319 git push gitcvs.git >/dev/null &&
320 cd cvswork &&
a25907da 321 GIT_CONFIG="$git_config" cvs -Q update -d &&
b3b53439
FL
322 (for dir in A A/B A/B/C A/D E; do
323 filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
324 if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
4a2284b9 325 test_cmp "$dir/$filename" "../$dir/$filename"; then
b3b53439
FL
326 :
327 else
328 echo >failure
329 fi
330 done) &&
331 test ! -f failure'
332
333cd "$WORKDIR"
334test_expect_success 'cvs update (delete file)' \
335 'git rm testfile1 &&
336 git commit -q -m "Remove testfile1" &&
337 git push gitcvs.git >/dev/null &&
338 cd cvswork &&
a25907da 339 GIT_CONFIG="$git_config" cvs -Q update &&
b3b53439
FL
340 test -z "$(grep testfile1 CVS/Entries)" &&
341 test ! -f testfile1'
342
343cd "$WORKDIR"
344test_expect_success 'cvs update (re-add deleted file)' \
345 'echo readded testfile >testfile1 &&
346 git add testfile1 &&
347 git commit -q -m "Re-Add testfile1" &&
348 git push gitcvs.git >/dev/null &&
349 cd cvswork &&
a25907da 350 GIT_CONFIG="$git_config" cvs -Q update &&
b3b53439 351 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
4a2284b9 352 test_cmp testfile1 ../testfile1'
b3b53439 353
1978659a
FL
354cd "$WORKDIR"
355test_expect_success 'cvs update (merge)' \
356 'echo Line 0 >expected &&
357 for i in 1 2 3 4 5 6 7
358 do
359 echo Line $i >>merge
360 echo Line $i >>expected
361 done &&
362 echo Line 8 >>expected &&
363 git add merge &&
364 git commit -q -m "Merge test (pre-merge)" &&
365 git push gitcvs.git >/dev/null &&
366 cd cvswork &&
367 GIT_CONFIG="$git_config" cvs -Q update &&
368 test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
4a2284b9 369 test_cmp merge ../merge &&
1978659a
FL
370 ( echo Line 0; cat merge ) >merge.tmp &&
371 mv merge.tmp merge &&
372 cd "$WORKDIR" &&
373 echo Line 8 >>merge &&
374 git add merge &&
375 git commit -q -m "Merge test (merge)" &&
376 git push gitcvs.git >/dev/null &&
377 cd cvswork &&
b3c81cff 378 sleep 1 && touch merge &&
1978659a 379 GIT_CONFIG="$git_config" cvs -Q update &&
4a2284b9 380 test_cmp merge ../expected'
1978659a
FL
381
382cd "$WORKDIR"
383
384cat >expected.C <<EOF
385<<<<<<< merge.mine
386Line 0
387=======
388LINE 0
389>>>>>>> merge.3
390EOF
391
392for i in 1 2 3 4 5 6 7 8
393do
394 echo Line $i >>expected.C
395done
396
397test_expect_success 'cvs update (conflict merge)' \
398 '( echo LINE 0; cat merge ) >merge.tmp &&
399 mv merge.tmp merge &&
400 git add merge &&
401 git commit -q -m "Merge test (conflict)" &&
402 git push gitcvs.git >/dev/null &&
403 cd cvswork &&
404 GIT_CONFIG="$git_config" cvs -Q update &&
4a2284b9 405 test_cmp merge ../expected.C'
1978659a
FL
406
407cd "$WORKDIR"
408test_expect_success 'cvs update (-C)' \
409 'cd cvswork &&
410 GIT_CONFIG="$git_config" cvs -Q update -C &&
4a2284b9 411 test_cmp merge ../merge'
1978659a
FL
412
413cd "$WORKDIR"
414test_expect_success 'cvs update (merge no-op)' \
415 'echo Line 9 >>merge &&
416 cp merge cvswork/merge &&
417 git add merge &&
418 git commit -q -m "Merge test (no-op)" &&
419 git push gitcvs.git >/dev/null &&
420 cd cvswork &&
b3c81cff 421 sleep 1 && touch merge &&
1978659a 422 GIT_CONFIG="$git_config" cvs -Q update &&
4a2284b9 423 test_cmp merge ../merge'
1978659a 424
6e8937a0
DD
425cd "$WORKDIR"
426test_expect_success 'cvs update (-p)' '
427 touch really-empty &&
428 echo Line 1 > no-lf &&
6ecfd91d 429 printf "Line 2" >> no-lf &&
6e8937a0
DD
430 git add really-empty no-lf &&
431 git commit -q -m "Update -p test" &&
432 git push gitcvs.git >/dev/null &&
433 cd cvswork &&
434 GIT_CONFIG="$git_config" cvs update &&
435 rm -f failures &&
436 for i in merge no-lf empty really-empty; do
437 GIT_CONFIG="$git_config" cvs update -p "$i" >$i.out
438 diff $i.out ../$i >>failures 2>&1
439 done &&
440 test -z "$(cat failures)"
441'
442
b0f2ecf5
LN
443cd "$WORKDIR"
444test_expect_success 'cvs update (module list supports packed refs)' '
445 GIT_DIR="$SERVERDIR" git pack-refs --all &&
446 GIT_CONFIG="$git_config" cvs -n up -d 2> out &&
447 grep "cvs update: New directory \`master'\''" < out
448'
449
dded801a
DD
450#------------
451# CVS STATUS
452#------------
453
454cd "$WORKDIR"
455test_expect_success 'cvs status' '
456 mkdir status.dir &&
457 echo Line > status.dir/status.file &&
458 echo Line > status.file &&
459 git add status.dir status.file &&
460 git commit -q -m "Status test" &&
461 git push gitcvs.git >/dev/null &&
462 cd cvswork &&
463 GIT_CONFIG="$git_config" cvs update &&
464 GIT_CONFIG="$git_config" cvs status | grep "^File: status.file" >../out &&
465 test $(wc -l <../out) = 2
466'
467
468cd "$WORKDIR"
469test_expect_success 'cvs status (nonrecursive)' '
470 cd cvswork &&
471 GIT_CONFIG="$git_config" cvs status -l | grep "^File: status.file" >../out &&
472 test $(wc -l <../out) = 1
473'
474
475cd "$WORKDIR"
476test_expect_success 'cvs status (no subdirs in header)' '
477 cd cvswork &&
478 GIT_CONFIG="$git_config" cvs status | grep ^File: >../out &&
479 ! grep / <../out
480'
481
42f7a2da
FE
482#------------
483# CVS CHECKOUT
484#------------
485
486cd "$WORKDIR"
487test_expect_success 'cvs co -c (shows module database)' '
488 GIT_CONFIG="$git_config" cvs co -c > out &&
489 grep "^master[ ]\+master$" < out &&
490 ! grep -v "^master[ ]\+master$" < out
491'
492
7ceacdff
JH
493#------------
494# CVS ANNOTATE
495#------------
496
497cd "$WORKDIR"
498test_expect_success 'cvs annotate' '
499 cd cvswork &&
500 GIT_CONFIG="$git_config" cvs annotate merge >../out &&
501 sed -e "s/ .*//" ../out >../actual &&
502 for i in 3 1 1 1 1 1 1 1 2 4; do echo 1.$i; done >../expect &&
503 test_cmp ../expect ../actual
504'
505
b3b53439 506test_done