3 test_description
='git-cvsserver and git refspecs
5 tests ability for git-cvsserver to switch between and compare
6 tags, branches and other git refspecs'
13 rm -f "$WORKDIR/list.expected"
14 echo "start $1" >>"${WORKDIR}/check.log"
21 GIT_DIR
=$SERVERDIR git show
"${ver}:${file}" \
22 >"$WORKDIR/check.got" 2>"$WORKDIR/check.stderr"
23 test_cmp
"$WORKDIR/check.got" "$sandbox/$file"
25 echo "check_file $sandbox $file $ver : $stat" >>"$WORKDIR/check.log"
26 echo "$file" >>"$WORKDIR/list.expected"
32 find "$sandbox" -name CVS
-prune -o -type f
-print >"$WORKDIR/list.actual" &&
33 sort <"$WORKDIR/list.expected" >expected
&&
34 sort <"$WORKDIR/list.actual" |
sed -e "s%cvswork/%%" >actual
&&
35 test_cmp expected actual
&&
39 check_end_full_tree
() {
41 sort <"$WORKDIR/list.expected" >expected
&&
42 find "$sandbox" -name CVS
-prune -o -type f
-print |
43 sed -e "s%$sandbox/%%" |
sort >act1
&&
44 test_cmp expected act1
&&
45 git ls-tree
--name-only -r "$2" |
sort >act2
&&
46 test_cmp expected act2
&&
57 git clone
-q -n . diffSandbox
&&
60 git checkout
"$vOld" &&
61 git apply
-p0 --index <"../$diffFile" &&
62 git
diff --exit-code "$vNew"
63 ) >check_diff_apply.out
2>&1
71 skip_all
='skipping git-cvsserver tests, cvs not found'
74 if ! test_have_prereq PERL
76 skip_all
='skipping git-cvsserver tests, perl not available'
79 perl
-e 'use DBI; use DBD::SQLite' >/dev
/null
2>&1 ||
{
80 skip_all
='skipping git-cvsserver tests, Perl SQLite interface unavailable'
84 unset GIT_DIR GIT_CONFIG
86 SERVERDIR
=$
(pwd)/gitcvs.git
87 git_config
="$SERVERDIR/config"
88 CVSROOT
=":fork:$SERVERDIR"
89 CVSWORK
="$(pwd)/cvswork"
90 CVS_SERVER
=git-cvsserver
91 export CVSROOT CVS_SERVER
93 rm -rf "$CVSWORK" "$SERVERDIR"
94 test_expect_success
'setup v1, b1' '
95 echo "Simple text file" >textfile.c &&
98 echo "adir/afile line1" >adir/afile &&
99 echo "adir/afile line2" >>adir/afile &&
100 echo "adir/afile line3" >>adir/afile &&
101 echo "adir/afile line4" >>adir/afile &&
102 echo "adir/a2file" >>adir/a2file &&
104 echo "adir/bdir/bfile line 1" >adir/bdir/bfile &&
105 echo "adir/bdir/bfile line 2" >>adir/bdir/bfile &&
106 echo "adir/bdir/b2file" >adir/bdir/b2file &&
107 git add textfile.c t2 adir &&
108 git commit -q -m "First Commit (v1)" &&
111 git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
112 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
113 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log"
117 test_expect_success
'cvs co v1' '
118 cvs -f -Q co -r v1 -d cvswork master >cvs.log 2>&1 &&
119 check_start_tree cvswork &&
120 check_file cvswork textfile.c v1 &&
121 check_file cvswork t2 v1 &&
122 check_file cvswork adir/afile v1 &&
123 check_file cvswork adir/a2file v1 &&
124 check_file cvswork adir/bdir/bfile v1 &&
125 check_file cvswork adir/bdir/b2file v1 &&
126 check_end_tree cvswork
130 test_expect_success
'cvs co b1' '
131 cvs -f co -r b1 -d cvswork master >cvs.log 2>&1 &&
132 check_start_tree cvswork &&
133 check_file cvswork textfile.c v1 &&
134 check_file cvswork t2 v1 &&
135 check_file cvswork adir/afile v1 &&
136 check_file cvswork adir/a2file v1 &&
137 check_file cvswork adir/bdir/bfile v1 &&
138 check_file cvswork adir/bdir/b2file v1 &&
139 check_end_tree cvswork
142 test_expect_success
'cvs co b1 [cvswork3]' '
143 cvs -f co -r b1 -d cvswork3 master >cvs.log 2>&1 &&
144 check_start_tree cvswork3 &&
145 check_file cvswork3 textfile.c v1 &&
146 check_file cvswork3 t2 v1 &&
147 check_file cvswork3 adir/afile v1 &&
148 check_file cvswork3 adir/a2file v1 &&
149 check_file cvswork3 adir/bdir/bfile v1 &&
150 check_file cvswork3 adir/bdir/b2file v1 &&
151 check_end_full_tree cvswork3 v1
154 test_expect_success
'edit cvswork3 and save diff' '
157 sed -e "s/line1/line1 - data/" adir/afile >adir/afileNEW &&
158 mv -f adir/afileNEW adir/afile &&
159 echo "afile5" >adir/afile5 &&
161 cvs -f add adir/afile5 &&
163 ! cvs -f diff -N -u >"$WORKDIR/cvswork3edit.diff"
167 test_expect_success
'setup v1.2 on b1' '
169 echo "new v1.2" >t3 &&
171 sed -e "s/line3/line3 - more data/" adir/afile >adir/afileNEW &&
172 mv -f adir/afileNEW adir/afile &&
174 echo "a3file" >>adir/a3file &&
175 echo "bfile line 3" >>adir/bdir/bfile &&
176 rm adir/bdir/b2file &&
177 echo "b3file" >adir/bdir/b3file &&
179 echo "cdir/cfile" >cdir/cfile &&
180 git add -A cdir adir t3 t2 &&
181 git commit -q -m 'v1.2
' &&
183 git push --tags gitcvs.git b1:b1
186 test_expect_success
'cvs -f up (on b1 adir)' '
187 ( cd cvswork/adir && cvs -f up -d ) >cvs.log 2>&1 &&
188 check_start_tree cvswork &&
189 check_file cvswork textfile.c v1 &&
190 check_file cvswork t2 v1 &&
191 check_file cvswork adir/afile v1.2 &&
192 check_file cvswork adir/a3file v1.2 &&
193 check_file cvswork adir/bdir/bfile v1.2 &&
194 check_file cvswork adir/bdir/b3file v1.2 &&
195 check_end_tree cvswork
198 test_expect_success
'cvs up (on b1 /)' '
199 ( cd cvswork && cvs -f up -d ) >cvs.log 2>&1 &&
200 check_start_tree cvswork &&
201 check_file cvswork textfile.c v1.2 &&
202 check_file cvswork t3 v1.2 &&
203 check_file cvswork adir/afile v1.2 &&
204 check_file cvswork adir/a3file v1.2 &&
205 check_file cvswork adir/bdir/bfile v1.2 &&
206 check_file cvswork adir/bdir/b3file v1.2 &&
207 check_file cvswork cdir/cfile v1.2 &&
208 check_end_tree cvswork
211 # Make sure "CVS/Tag" files didn't get messed up:
212 test_expect_success
'cvs up (on b1 /) (again; check CVS/Tag files)' '
213 ( cd cvswork && cvs -f up -d ) >cvs.log 2>&1 &&
214 check_start_tree cvswork &&
215 check_file cvswork textfile.c v1.2 &&
216 check_file cvswork t3 v1.2 &&
217 check_file cvswork adir/afile v1.2 &&
218 check_file cvswork adir/a3file v1.2 &&
219 check_file cvswork adir/bdir/bfile v1.2 &&
220 check_file cvswork adir/bdir/b3file v1.2 &&
221 check_file cvswork cdir/cfile v1.2 &&
222 check_end_tree cvswork
225 # update to another version:
226 test_expect_success
'cvs up -r v1' '
227 ( cd cvswork && cvs -f up -r v1 ) >cvs.log 2>&1 &&
228 check_start_tree cvswork &&
229 check_file cvswork textfile.c v1 &&
230 check_file cvswork t2 v1 &&
231 check_file cvswork adir/afile v1 &&
232 check_file cvswork adir/a2file v1 &&
233 check_file cvswork adir/bdir/bfile v1 &&
234 check_file cvswork adir/bdir/b2file v1 &&
235 check_end_tree cvswork
238 test_expect_success
'cvs up' '
239 ( cd cvswork && cvs -f up ) >cvs.log 2>&1 &&
240 check_start_tree cvswork &&
241 check_file cvswork textfile.c v1 &&
242 check_file cvswork t2 v1 &&
243 check_file cvswork adir/afile v1 &&
244 check_file cvswork adir/a2file v1 &&
245 check_file cvswork adir/bdir/bfile v1 &&
246 check_file cvswork adir/bdir/b2file v1 &&
247 check_end_tree cvswork
250 test_expect_success
'cvs up (again; check CVS/Tag files)' '
251 ( cd cvswork && cvs -f up -d ) >cvs.log 2>&1 &&
252 check_start_tree cvswork &&
253 check_file cvswork textfile.c v1 &&
254 check_file cvswork t2 v1 &&
255 check_file cvswork adir/afile v1 &&
256 check_file cvswork adir/a2file v1 &&
257 check_file cvswork adir/bdir/bfile v1 &&
258 check_file cvswork adir/bdir/b2file v1 &&
259 check_end_tree cvswork
262 test_expect_success
'setup simple b2' '
264 git push --tags gitcvs.git b2:b2
267 test_expect_success
'cvs co b2 [into cvswork2]' '
268 cvs -f co -r b2 -d cvswork2 master >cvs.log 2>&1 &&
269 check_start_tree cvswork &&
270 check_file cvswork textfile.c v1 &&
271 check_file cvswork t2 v1 &&
272 check_file cvswork adir/afile v1 &&
273 check_file cvswork adir/a2file v1 &&
274 check_file cvswork adir/bdir/bfile v1 &&
275 check_file cvswork adir/bdir/b2file v1 &&
276 check_end_tree cvswork
279 test_expect_success
'root dir edit [cvswork2]' '
281 cd cvswork2 && echo "Line 2" >>textfile.c &&
282 ! cvs -f diff -u >"$WORKDIR/cvsEdit1.diff" &&
283 cvs -f commit -m "edit textfile.c" textfile.c
287 test_expect_success
'root dir rm file [cvswork2]' '
291 cvs -f diff -u >../cvsEdit2-empty.diff &&
292 ! cvs -f diff -N -u >"$WORKDIR/cvsEdit2-N.diff" &&
293 cvs -f commit -m "rm t2"
297 test_expect_success
'subdir edit/add/rm files [cvswork2]' '
300 sed -e "s/line 1/line 1 (v2)/" adir/bdir/bfile >adir/bdir/bfileNEW &&
301 mv -f adir/bdir/bfileNEW adir/bdir/bfile &&
302 rm adir/bdir/b2file &&
304 cvs -f rm bdir/b2file &&
305 echo "4th file" >bdir/b4file &&
306 cvs -f add bdir/b4file &&
307 ! cvs -f diff -N -u >"$WORKDIR/cvsEdit3.diff" &&
308 git fetch gitcvs.git b2:b2 &&
311 ! cvs -f diff -u -N -r v1.2 >"$WORKDIR/cvsEdit3-v1.2.diff" &&
312 ! cvs -f diff -u -N -r v1.2 -r v1 >"$WORKDIR/cvsEdit3-v1.2-v1.diff"
314 cvs -f commit -m "various add/rm/edit"
318 test_expect_success
'validate result of edits [cvswork2]' '
319 git fetch gitcvs.git b2:b2 &&
321 git push --tags gitcvs.git b2:b2 &&
322 check_start_tree cvswork2 &&
323 check_file cvswork2 textfile.c v2 &&
324 check_file cvswork2 adir/afile v2 &&
325 check_file cvswork2 adir/a2file v2 &&
326 check_file cvswork2 adir/bdir/bfile v2 &&
327 check_file cvswork2 adir/bdir/b4file v2 &&
328 check_end_full_tree cvswork2 v2
331 test_expect_success
'validate basic diffs saved during above cvswork2 edits' '
332 test $(grep Index: cvsEdit1.diff | wc -l) = 1 &&
333 test_must_be_empty cvsEdit2-empty.diff &&
334 test $(grep Index: cvsEdit2-N.diff | wc -l) = 1 &&
335 test $(grep Index: cvsEdit3.diff | wc -l) = 3 &&
336 rm -rf diffSandbox &&
337 git clone -q -n . diffSandbox &&
341 git apply -p0 --index <"$WORKDIR/cvsEdit1.diff" &&
342 git apply -p0 --index <"$WORKDIR/cvsEdit2-N.diff" &&
343 git apply -p0 --directory=adir --index <"$WORKDIR/cvsEdit3.diff" &&
344 git diff --exit-code v2
345 ) >"check_diff_apply.out" 2>&1
348 test_expect_success
'validate v1.2 diff saved during last cvswork2 edit' '
349 test $(grep Index: cvsEdit3-v1.2.diff | wc -l) = 9 &&
350 check_diff cvsEdit3-v1.2.diff v1.2 v2
353 test_expect_success
'validate v1.2 v1 diff saved during last cvswork2 edit' '
354 test $(grep Index: cvsEdit3-v1.2-v1.diff | wc -l) = 9 &&
355 check_diff cvsEdit3-v1.2-v1.diff v1.2 v1
358 test_expect_success
'cvs up [cvswork2]' '
359 ( cd cvswork2 && cvs -f up ) >cvs.log 2>&1 &&
360 check_start_tree cvswork2 &&
361 check_file cvswork2 textfile.c v2 &&
362 check_file cvswork2 adir/afile v2 &&
363 check_file cvswork2 adir/a2file v2 &&
364 check_file cvswork2 adir/bdir/bfile v2 &&
365 check_file cvswork2 adir/bdir/b4file v2 &&
366 check_end_full_tree cvswork2 v2
369 test_expect_success
'cvs up -r b2 [back to cvswork]' '
370 ( cd cvswork && cvs -f up -r b2 ) >cvs.log 2>&1 &&
371 check_start_tree cvswork &&
372 check_file cvswork textfile.c v2 &&
373 check_file cvswork adir/afile v2 &&
374 check_file cvswork adir/a2file v2 &&
375 check_file cvswork adir/bdir/bfile v2 &&
376 check_file cvswork adir/bdir/b4file v2 &&
377 check_end_full_tree cvswork v2
380 test_expect_success
'cvs up -r b1' '
381 ( cd cvswork && cvs -f up -r b1 ) >cvs.log 2>&1 &&
382 check_start_tree cvswork &&
383 check_file cvswork textfile.c v1.2 &&
384 check_file cvswork t3 v1.2 &&
385 check_file cvswork adir/afile v1.2 &&
386 check_file cvswork adir/a3file v1.2 &&
387 check_file cvswork adir/bdir/bfile v1.2 &&
388 check_file cvswork adir/bdir/b3file v1.2 &&
389 check_file cvswork cdir/cfile v1.2 &&
390 check_end_full_tree cvswork v1.2
393 test_expect_success
'cvs up -A' '
394 ( cd cvswork && cvs -f up -A ) >cvs.log 2>&1 &&
395 check_start_tree cvswork &&
396 check_file cvswork textfile.c v1 &&
397 check_file cvswork t2 v1 &&
398 check_file cvswork adir/afile v1 &&
399 check_file cvswork adir/a2file v1 &&
400 check_file cvswork adir/bdir/bfile v1 &&
401 check_file cvswork adir/bdir/b2file v1 &&
402 check_end_full_tree cvswork v1
405 test_expect_success
'cvs up (check CVS/Tag files)' '
406 ( cd cvswork && cvs -f up ) >cvs.log 2>&1 &&
407 check_start_tree cvswork &&
408 check_file cvswork textfile.c v1 &&
409 check_file cvswork t2 v1 &&
410 check_file cvswork adir/afile v1 &&
411 check_file cvswork adir/a2file v1 &&
412 check_file cvswork adir/bdir/bfile v1 &&
413 check_file cvswork adir/bdir/b2file v1 &&
414 check_end_full_tree cvswork v1
417 # This is not really legal CVS, but it seems to work anyway:
418 test_expect_success
'cvs up -r heads/b1' '
419 ( cd cvswork && cvs -f up -r heads/b1 ) >cvs.log 2>&1 &&
420 check_start_tree cvswork &&
421 check_file cvswork textfile.c v1.2 &&
422 check_file cvswork t3 v1.2 &&
423 check_file cvswork adir/afile v1.2 &&
424 check_file cvswork adir/a3file v1.2 &&
425 check_file cvswork adir/bdir/bfile v1.2 &&
426 check_file cvswork adir/bdir/b3file v1.2 &&
427 check_file cvswork cdir/cfile v1.2 &&
428 check_end_full_tree cvswork v1.2
431 # But this should work even if CVS client checks -r more carefully:
432 test_expect_success
'cvs up -r heads_-s-b2 (cvsserver escape mechanism)' '
433 ( cd cvswork && cvs -f up -r heads_-s-b2 ) >cvs.log 2>&1 &&
434 check_start_tree cvswork &&
435 check_file cvswork textfile.c v2 &&
436 check_file cvswork adir/afile v2 &&
437 check_file cvswork adir/a2file v2 &&
438 check_file cvswork adir/bdir/bfile v2 &&
439 check_file cvswork adir/bdir/b4file v2 &&
440 check_end_full_tree cvswork v2
443 v1hash
=$
(git rev-parse v1
)
444 test_expect_success
'cvs up -r $(git rev-parse v1)' '
446 ( cd cvswork && cvs -f up -r "$v1hash" ) >cvs.log 2>&1 &&
447 check_start_tree cvswork &&
448 check_file cvswork textfile.c v1 &&
449 check_file cvswork t2 v1 &&
450 check_file cvswork adir/afile v1 &&
451 check_file cvswork adir/a2file v1 &&
452 check_file cvswork adir/bdir/bfile v1 &&
453 check_file cvswork adir/bdir/b2file v1 &&
454 check_end_full_tree cvswork v1
457 test_expect_success
'cvs diff -r v1 -u' '
458 ( cd cvswork && cvs -f diff -r v1 -u ) >cvsDiff.out 2>cvs.log &&
459 test_must_be_empty cvsDiff.out &&
460 test_must_be_empty cvs.log
463 test_expect_success
'cvs diff -N -r v2 -u' '
464 ( cd cvswork && ! cvs -f diff -N -r v2 -u ) >cvsDiff.out 2>cvs.log &&
465 test_must_be_empty cvs.log &&
466 test -s cvsDiff.out &&
467 check_diff cvsDiff.out v2 v1 >check_diff.out 2>&1
470 test_expect_success
'cvs diff -N -r v2 -r v1.2' '
471 ( cd cvswork && ! cvs -f diff -N -r v2 -r v1.2 -u ) >cvsDiff.out 2>cvs.log &&
472 test_must_be_empty cvs.log &&
473 test -s cvsDiff.out &&
474 check_diff cvsDiff.out v2 v1.2 >check_diff.out 2>&1
477 test_expect_success
'apply early [cvswork3] diff to b3' '
478 git clone -q . gitwork3 &&
481 git checkout -b b3 v1 &&
482 git apply -p0 --index <"$WORKDIR/cvswork3edit.diff" &&
483 git commit -m "cvswork3 edits applied"
485 git fetch gitwork3 b3:b3 &&
489 test_expect_success
'check [cvswork3] diff' '
490 ( cd cvswork3 && ! cvs -f diff -N -u ) >"$WORKDIR/cvsDiff.out" 2>cvs.log &&
491 test_must_be_empty cvs.log &&
492 test -s cvsDiff.out &&
493 test $(grep Index: cvsDiff.out | wc -l) = 3 &&
494 test_cmp cvsDiff.out cvswork3edit.diff &&
495 check_diff cvsDiff.out v1 v3 >check_diff.out 2>&1
498 test_expect_success
'merge early [cvswork3] b3 with b1' '
499 ( cd gitwork3 && git merge -m "message" b1 ) &&
500 git fetch gitwork3 b3:b3 &&
501 git tag v3merged b3 &&
502 git push --tags gitcvs.git b3:b3
505 # This test would fail if cvsserver properly created a ".#afile"* file
507 # TODO: Validate that the .# file was saved properly, and then
508 # delete/ignore it when checking the tree.
509 test_expect_success
'cvs up dirty [cvswork3]' '
513 ! cvs -f diff -N -u >"$WORKDIR/cvsDiff.out"
515 test -s cvsDiff.out &&
516 test $(grep Index: cvsDiff.out | wc -l) = 2 &&
517 check_start_tree cvswork3 &&
518 check_file cvswork3 textfile.c v3merged &&
519 check_file cvswork3 t3 v3merged &&
520 check_file cvswork3 adir/afile v3merged &&
521 check_file cvswork3 adir/a3file v3merged &&
522 check_file cvswork3 adir/afile5 v3merged &&
523 check_file cvswork3 adir/bdir/bfile v3merged &&
524 check_file cvswork3 adir/bdir/b3file v3merged &&
525 check_file cvswork3 cdir/cfile v3merged &&
526 check_end_full_tree cvswork3 v3merged
529 # TODO: test cvs status
531 test_expect_success
'cvs commit [cvswork3]' '
534 cvs -f commit -m "dirty sandbox after auto-merge"
536 check_start_tree cvswork3 &&
537 check_file cvswork3 textfile.c v3merged &&
538 check_file cvswork3 t3 v3merged &&
539 check_file cvswork3 adir/afile v3merged &&
540 check_file cvswork3 adir/a3file v3merged &&
541 check_file cvswork3 adir/afile5 v3merged &&
542 check_file cvswork3 adir/bdir/bfile v3merged &&
543 check_file cvswork3 adir/bdir/b3file v3merged &&
544 check_file cvswork3 cdir/cfile v3merged &&
545 check_end_full_tree cvswork3 v3merged &&
546 git fetch gitcvs.git b3:b4 &&
548 git diff --exit-code v4.1 v3merged >check_diff_apply.out 2>&1