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