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