]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9400-git-cvsserver-server.sh
t9400: Work around CVS' deficiencies
[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"
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' \
a25907da 47 'GIT_CONFIG="$git_config" cvs -Q co -d cvswork master &&
b3b53439
FL
48 test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5))" = "empty/1.1/"'
49
240ba7f2
FL
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
70test_expect_success 'pserver authentication' \
71 'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
72 tail -n1 log | grep -q "^I LOVE YOU$"'
73
74test_expect_success 'pserver authentication failure (non-anonymous user)' \
75 'if cat request-git | git-cvsserver pserver >log 2>&1
76 then
77 false
78 else
79 true
80 fi &&
81 tail -n1 log | grep -q "^I HATE YOU$"'
82
83
1d431b22
FL
84#--------------
85# CONFIG TESTS
86#--------------
87
88test_expect_success 'gitcvs.enabled = false' \
89 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
90 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
91 then
92 echo unexpected cvs success
93 false
94 else
95 true
96 fi &&
97 cat cvs.log | grep -q "GITCVS emulation disabled" &&
98 test ! -d cvswork2'
99
100rm -fr cvswork2
101test_expect_success 'gitcvs.ext.enabled = true' \
102 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
103 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
104 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
105 diff -q cvswork cvswork2'
106
107rm -fr cvswork2
108test_expect_success 'gitcvs.ext.enabled = false' \
109 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
110 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
111 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
112 then
113 echo unexpected cvs success
114 false
115 else
116 true
117 fi &&
118 cat cvs.log | grep -q "GITCVS emulation disabled" &&
119 test ! -d cvswork2'
120
121rm -fr cvswork2
122test_expect_success 'gitcvs.dbname' \
123 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
124 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
125 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
126 diff -q cvswork cvswork2 &&
127 test -f "$SERVERDIR/gitcvs.ext.master.sqlite" &&
128 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs.ext.master.sqlite"'
129
130rm -fr cvswork2
131test_expect_success 'gitcvs.ext.dbname' \
132 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
133 GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
134 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
135 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
136 diff -q cvswork cvswork2 &&
137 test -f "$SERVERDIR/gitcvs1.ext.master.sqlite" &&
138 test ! -f "$SERVERDIR/gitcvs2.ext.master.sqlite" &&
139 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs1.ext.master.sqlite"'
140
141
142#------------
143# CVS UPDATE
144#------------
145
146rm -fr "$SERVERDIR"
147cd "$WORKDIR" &&
148git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
149GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
150GIT_DIR="$SERVERDIR" git config --bool gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
151exit 1
152
b3b53439
FL
153test_expect_success 'cvs update (create new file)' \
154 'echo testfile1 >testfile1 &&
155 git add testfile1 &&
156 git commit -q -m "Add testfile1" &&
157 git push gitcvs.git >/dev/null &&
158 cd cvswork &&
a25907da 159 GIT_CONFIG="$git_config" cvs -Q update &&
b3b53439
FL
160 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
161 diff -q testfile1 ../testfile1'
162
163cd "$WORKDIR"
164test_expect_success 'cvs update (update existing file)' \
165 'echo line 2 >>testfile1 &&
166 git add testfile1 &&
167 git commit -q -m "Append to testfile1" &&
168 git push gitcvs.git >/dev/null &&
169 cd cvswork &&
a25907da 170 GIT_CONFIG="$git_config" cvs -Q update &&
b3b53439
FL
171 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
172 diff -q testfile1 ../testfile1'
173
174cd "$WORKDIR"
175#TODO: cvsserver doesn't support update w/o -d
176test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" \
177 'mkdir test &&
178 echo >test/empty &&
179 git add test &&
180 git commit -q -m "Single Subdirectory" &&
181 git push gitcvs.git >/dev/null &&
182 cd cvswork &&
a25907da 183 GIT_CONFIG="$git_config" cvs -Q update &&
b3b53439
FL
184 test ! -d test'
185
186cd "$WORKDIR"
187test_expect_success 'cvs update (subdirectories)' \
188 '(for dir in A A/B A/B/C A/D E; do
189 mkdir $dir &&
190 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
191 git add $dir;
192 done) &&
193 git commit -q -m "deep sub directory structure" &&
194 git push gitcvs.git >/dev/null &&
195 cd cvswork &&
a25907da 196 GIT_CONFIG="$git_config" cvs -Q update -d &&
b3b53439
FL
197 (for dir in A A/B A/B/C A/D E; do
198 filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
199 if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
200 diff -q "$dir/$filename" "../$dir/$filename"; then
201 :
202 else
203 echo >failure
204 fi
205 done) &&
206 test ! -f failure'
207
208cd "$WORKDIR"
209test_expect_success 'cvs update (delete file)' \
210 'git rm testfile1 &&
211 git commit -q -m "Remove testfile1" &&
212 git push gitcvs.git >/dev/null &&
213 cd cvswork &&
a25907da 214 GIT_CONFIG="$git_config" cvs -Q update &&
b3b53439
FL
215 test -z "$(grep testfile1 CVS/Entries)" &&
216 test ! -f testfile1'
217
218cd "$WORKDIR"
219test_expect_success 'cvs update (re-add deleted file)' \
220 'echo readded testfile >testfile1 &&
221 git add testfile1 &&
222 git commit -q -m "Re-Add testfile1" &&
223 git push gitcvs.git >/dev/null &&
224 cd cvswork &&
a25907da 225 GIT_CONFIG="$git_config" cvs -Q update &&
b3b53439
FL
226 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
227 diff -q testfile1 ../testfile1'
228
1978659a
FL
229cd "$WORKDIR"
230test_expect_success 'cvs update (merge)' \
231 'echo Line 0 >expected &&
232 for i in 1 2 3 4 5 6 7
233 do
234 echo Line $i >>merge
235 echo Line $i >>expected
236 done &&
237 echo Line 8 >>expected &&
238 git add merge &&
239 git commit -q -m "Merge test (pre-merge)" &&
240 git push gitcvs.git >/dev/null &&
241 cd cvswork &&
242 GIT_CONFIG="$git_config" cvs -Q update &&
243 test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
244 diff -q merge ../merge &&
245 ( echo Line 0; cat merge ) >merge.tmp &&
246 mv merge.tmp merge &&
247 cd "$WORKDIR" &&
248 echo Line 8 >>merge &&
249 git add merge &&
250 git commit -q -m "Merge test (merge)" &&
251 git push gitcvs.git >/dev/null &&
252 cd cvswork &&
b3c81cff 253 sleep 1 && touch merge &&
1978659a
FL
254 GIT_CONFIG="$git_config" cvs -Q update &&
255 diff -q merge ../expected'
256
257cd "$WORKDIR"
258
259cat >expected.C <<EOF
260<<<<<<< merge.mine
261Line 0
262=======
263LINE 0
264>>>>>>> merge.3
265EOF
266
267for i in 1 2 3 4 5 6 7 8
268do
269 echo Line $i >>expected.C
270done
271
272test_expect_success 'cvs update (conflict merge)' \
273 '( echo LINE 0; cat merge ) >merge.tmp &&
274 mv merge.tmp merge &&
275 git add merge &&
276 git commit -q -m "Merge test (conflict)" &&
277 git push gitcvs.git >/dev/null &&
278 cd cvswork &&
279 GIT_CONFIG="$git_config" cvs -Q update &&
280 diff -q merge ../expected.C'
281
282cd "$WORKDIR"
283test_expect_success 'cvs update (-C)' \
284 'cd cvswork &&
285 GIT_CONFIG="$git_config" cvs -Q update -C &&
286 diff -q merge ../merge'
287
288cd "$WORKDIR"
289test_expect_success 'cvs update (merge no-op)' \
290 'echo Line 9 >>merge &&
291 cp merge cvswork/merge &&
292 git add merge &&
293 git commit -q -m "Merge test (no-op)" &&
294 git push gitcvs.git >/dev/null &&
295 cd cvswork &&
b3c81cff 296 sleep 1 && touch merge &&
1978659a
FL
297 GIT_CONFIG="$git_config" cvs -Q update &&
298 diff -q merge ../merge'
299
b3b53439 300test_done