t9402: Simplify git ls-tree
[git/gitweb.git] / t / t9402-git-cvsserver-refs.sh
blob7953ffccc6834866a04d0a347841d592d013db59
1 #!/bin/sh
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'
8 . ./test-lib.sh
10 #########
12 check_start_tree() {
13 rm -f "$WORKDIR/check.list"
14 echo "start $1" >>"${WORKDIR}/check.log"
17 check_file() {
18 sandbox="$1"
19 file="$2"
20 ver="$3"
21 GIT_DIR=$SERVERDIR git show "${ver}:${file}" \
22 >"$WORKDIR/check.got" 2>"$WORKDIR/check.stderr"
23 test_cmp "$WORKDIR/check.got" "$sandbox/$file"
24 stat=$?
25 echo "check_file $sandbox $file $ver : $stat" >>"$WORKDIR/check.log"
26 echo "$file" >>"$WORKDIR/check.list"
27 return $stat
30 check_end_tree() {
31 sandbox="$1" &&
32 find "$sandbox" -name CVS -prune -o -type f -print >"$WORKDIR/check.cvsCount" &&
33 sort <"$WORKDIR/check.list" >expected &&
34 sort <"$WORKDIR/check.cvsCount" | sed -e "s%cvswork/%%" >actual &&
35 test_cmp expected actual &&
36 rm expected actual
39 check_end_full_tree() {
40 sandbox="$1" &&
41 sort <"$WORKDIR/check.list" >expected &&
42 find "$sandbox" -name CVS -prune -o -type f -print | sed -e "s%$sandbox/%%" | sort >act1 &&
43 test_cmp expected act1 &&
44 git ls-tree --name-only -r "$2" | sort >act2 &&
45 test_cmp expected act2 &&
46 rm expected act1 act2
49 #########
51 check_diff() {
52 diffFile="$1"
53 vOld="$2"
54 vNew="$3"
55 rm -rf diffSandbox
56 git clone -q -n . diffSandbox &&
58 cd diffSandbox &&
59 git checkout "$vOld" &&
60 git apply -p0 --index <"../$diffFile" &&
61 git diff --exit-code "$vNew"
62 ) >check_diff_apply.out 2>&1
65 #########
67 cvs >/dev/null 2>&1
68 if test $? -ne 1
69 then
70 skip_all='skipping git-cvsserver tests, cvs not found'
71 test_done
73 if ! test_have_prereq PERL
74 then
75 skip_all='skipping git-cvsserver tests, perl not available'
76 test_done
78 "$PERL_PATH" -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
79 skip_all='skipping git-cvsserver tests, Perl SQLite interface unavailable'
80 test_done
83 unset GIT_DIR GIT_CONFIG
84 WORKDIR=$(pwd)
85 SERVERDIR=$(pwd)/gitcvs.git
86 git_config="$SERVERDIR/config"
87 CVSROOT=":fork:$SERVERDIR"
88 CVSWORK="$(pwd)/cvswork"
89 CVS_SERVER=git-cvsserver
90 export CVSROOT CVS_SERVER
92 rm -rf "$CVSWORK" "$SERVERDIR"
93 test_expect_success 'setup v1, b1' '
94 echo "Simple text file" >textfile.c &&
95 echo "t2" >t2 &&
96 mkdir adir &&
97 echo "adir/afile line1" >adir/afile &&
98 echo "adir/afile line2" >>adir/afile &&
99 echo "adir/afile line3" >>adir/afile &&
100 echo "adir/afile line4" >>adir/afile &&
101 echo "adir/a2file" >>adir/a2file &&
102 mkdir adir/bdir &&
103 echo "adir/bdir/bfile line 1" >adir/bdir/bfile &&
104 echo "adir/bdir/bfile line 2" >>adir/bdir/bfile &&
105 echo "adir/bdir/b2file" >adir/bdir/b2file &&
106 git add textfile.c t2 adir &&
107 git commit -q -m "First Commit (v1)" &&
108 git tag v1 &&
109 git branch b1 &&
110 git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
111 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
112 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log"
115 rm -rf cvswork
116 test_expect_success 'cvs co v1' '
117 cvs -f -Q co -r v1 -d cvswork master >cvs.log 2>&1 &&
118 check_start_tree cvswork &&
119 check_file cvswork textfile.c v1 &&
120 check_file cvswork t2 v1 &&
121 check_file cvswork adir/afile v1 &&
122 check_file cvswork adir/a2file v1 &&
123 check_file cvswork adir/bdir/bfile v1 &&
124 check_file cvswork adir/bdir/b2file v1 &&
125 check_end_tree cvswork
128 rm -rf cvswork
129 test_expect_success 'cvs co b1' '
130 cvs -f co -r b1 -d cvswork master >cvs.log 2>&1 &&
131 check_start_tree cvswork &&
132 check_file cvswork textfile.c v1 &&
133 check_file cvswork t2 v1 &&
134 check_file cvswork adir/afile v1 &&
135 check_file cvswork adir/a2file v1 &&
136 check_file cvswork adir/bdir/bfile v1 &&
137 check_file cvswork adir/bdir/b2file v1 &&
138 check_end_tree cvswork
141 test_expect_success 'cvs co b1 [cvswork3]' '
142 cvs -f co -r b1 -d cvswork3 master >cvs.log 2>&1 &&
143 check_start_tree cvswork3 &&
144 check_file cvswork3 textfile.c v1 &&
145 check_file cvswork3 t2 v1 &&
146 check_file cvswork3 adir/afile v1 &&
147 check_file cvswork3 adir/a2file v1 &&
148 check_file cvswork3 adir/bdir/bfile v1 &&
149 check_file cvswork3 adir/bdir/b2file v1 &&
150 check_end_full_tree cvswork3 v1
153 test_expect_success 'edit cvswork3 and save diff' '
155 cd cvswork3 &&
156 sed -e "s/line1/line1 - data/" adir/afile >adir/afileNEW &&
157 mv -f adir/afileNEW adir/afile &&
158 echo "afile5" >adir/afile5 &&
159 rm t2 &&
160 cvs -f add adir/afile5 &&
161 cvs -f rm t2 &&
162 ! cvs -f diff -N -u >"$WORKDIR/cvswork3edit.diff"
166 test_expect_success 'setup v1.2 on b1' '
167 git checkout b1 &&
168 echo "new v1.2" >t3 &&
169 rm t2 &&
170 sed -e "s/line3/line3 - more data/" adir/afile >adir/afileNEW &&
171 mv -f adir/afileNEW adir/afile &&
172 rm adir/a2file &&
173 echo "a3file" >>adir/a3file &&
174 echo "bfile line 3" >>adir/bdir/bfile &&
175 rm adir/bdir/b2file &&
176 echo "b3file" >adir/bdir/b3file &&
177 mkdir cdir &&
178 echo "cdir/cfile" >cdir/cfile &&
179 git add -A cdir adir t3 t2 &&
180 git commit -q -m 'v1.2' &&
181 git tag v1.2 &&
182 git push --tags gitcvs.git b1:b1
185 test_expect_success 'cvs -f up (on b1 adir)' '
186 ( cd cvswork/adir && cvs -f up -d ) >cvs.log 2>&1 &&
187 check_start_tree cvswork &&
188 check_file cvswork textfile.c v1 &&
189 check_file cvswork t2 v1 &&
190 check_file cvswork adir/afile v1.2 &&
191 check_file cvswork adir/a3file v1.2 &&
192 check_file cvswork adir/bdir/bfile v1.2 &&
193 check_file cvswork adir/bdir/b3file v1.2 &&
194 check_end_tree cvswork
197 test_expect_success 'cvs up (on b1 /)' '
198 ( cd cvswork && cvs -f up -d ) >cvs.log 2>&1 &&
199 check_start_tree cvswork &&
200 check_file cvswork textfile.c v1.2 &&
201 check_file cvswork t3 v1.2 &&
202 check_file cvswork adir/afile v1.2 &&
203 check_file cvswork adir/a3file v1.2 &&
204 check_file cvswork adir/bdir/bfile v1.2 &&
205 check_file cvswork adir/bdir/b3file v1.2 &&
206 check_file cvswork cdir/cfile v1.2 &&
207 check_end_tree cvswork
210 # Make sure "CVS/Tag" files didn't get messed up:
211 test_expect_success 'cvs up (on b1 /) (again; check CVS/Tag files)' '
212 ( cd cvswork && cvs -f up -d ) >cvs.log 2>&1 &&
213 check_start_tree cvswork &&
214 check_file cvswork textfile.c v1.2 &&
215 check_file cvswork t3 v1.2 &&
216 check_file cvswork adir/afile v1.2 &&
217 check_file cvswork adir/a3file v1.2 &&
218 check_file cvswork adir/bdir/bfile v1.2 &&
219 check_file cvswork adir/bdir/b3file v1.2 &&
220 check_file cvswork cdir/cfile v1.2 &&
221 check_end_tree cvswork
224 # update to another version:
225 test_expect_success 'cvs up -r v1' '
226 ( cd cvswork && cvs -f up -r v1 ) >cvs.log 2>&1 &&
227 check_start_tree cvswork &&
228 check_file cvswork textfile.c v1 &&
229 check_file cvswork t2 v1 &&
230 check_file cvswork adir/afile v1 &&
231 check_file cvswork adir/a2file v1 &&
232 check_file cvswork adir/bdir/bfile v1 &&
233 check_file cvswork adir/bdir/b2file v1 &&
234 check_end_tree cvswork
237 test_expect_success 'cvs up' '
238 ( cd cvswork && cvs -f up ) >cvs.log 2>&1 &&
239 check_start_tree cvswork &&
240 check_file cvswork textfile.c v1 &&
241 check_file cvswork t2 v1 &&
242 check_file cvswork adir/afile v1 &&
243 check_file cvswork adir/a2file v1 &&
244 check_file cvswork adir/bdir/bfile v1 &&
245 check_file cvswork adir/bdir/b2file v1 &&
246 check_end_tree cvswork
249 test_expect_success 'cvs up (again; check CVS/Tag files)' '
250 ( cd cvswork && cvs -f up -d ) >cvs.log 2>&1 &&
251 check_start_tree cvswork &&
252 check_file cvswork textfile.c v1 &&
253 check_file cvswork t2 v1 &&
254 check_file cvswork adir/afile v1 &&
255 check_file cvswork adir/a2file v1 &&
256 check_file cvswork adir/bdir/bfile v1 &&
257 check_file cvswork adir/bdir/b2file v1 &&
258 check_end_tree cvswork
261 test_expect_success 'setup simple b2' '
262 git branch b2 v1 &&
263 git push --tags gitcvs.git b2:b2
266 test_expect_success 'cvs co b2 [into cvswork2]' '
267 cvs -f co -r b2 -d cvswork2 master >cvs.log 2>&1 &&
268 check_start_tree cvswork &&
269 check_file cvswork textfile.c v1 &&
270 check_file cvswork t2 v1 &&
271 check_file cvswork adir/afile v1 &&
272 check_file cvswork adir/a2file v1 &&
273 check_file cvswork adir/bdir/bfile v1 &&
274 check_file cvswork adir/bdir/b2file v1 &&
275 check_end_tree cvswork
278 test_expect_success 'root dir edit [cvswork2]' '
280 cd cvswork2 && echo "Line 2" >>textfile.c &&
281 ! cvs -f diff -u >"$WORKDIR/cvsEdit1.diff" &&
282 cvs -f commit -m "edit textfile.c" textfile.c
283 ) >cvsEdit1.log 2>&1
286 test_expect_success 'root dir rm file [cvswork2]' '
288 cd cvswork2 &&
289 cvs -f rm -f t2 &&
290 cvs -f diff -u >../cvsEdit2-empty.diff &&
291 ! cvs -f diff -N -u >"$WORKDIR/cvsEdit2-N.diff" &&
292 cvs -f commit -m "rm t2"
293 ) >cvsEdit2.log 2>&1
296 test_expect_success 'subdir edit/add/rm files [cvswork2]' '
298 cd cvswork2 &&
299 sed -e "s/line 1/line 1 (v2)/" adir/bdir/bfile >adir/bdir/bfileNEW &&
300 mv -f adir/bdir/bfileNEW adir/bdir/bfile &&
301 rm adir/bdir/b2file &&
302 cd adir &&
303 cvs -f rm bdir/b2file &&
304 echo "4th file" >bdir/b4file &&
305 cvs -f add bdir/b4file &&
306 ! cvs -f diff -N -u >"$WORKDIR/cvsEdit3.diff" &&
307 git fetch gitcvs.git b2:b2 &&
309 cd .. &&
310 ! cvs -f diff -u -N -r v1.2 >"$WORKDIR/cvsEdit3-v1.2.diff" &&
311 ! cvs -f diff -u -N -r v1.2 -r v1 >"$WORKDIR/cvsEdit3-v1.2-v1.diff"
312 ) &&
313 cvs -f commit -m "various add/rm/edit"
314 ) >cvs.log 2>&1
317 test_expect_success 'validate result of edits [cvswork2]' '
318 git fetch gitcvs.git b2:b2 &&
319 git tag v2 b2 &&
320 git push --tags gitcvs.git b2:b2 &&
321 check_start_tree cvswork2 &&
322 check_file cvswork2 textfile.c v2 &&
323 check_file cvswork2 adir/afile v2 &&
324 check_file cvswork2 adir/a2file v2 &&
325 check_file cvswork2 adir/bdir/bfile v2 &&
326 check_file cvswork2 adir/bdir/b4file v2 &&
327 check_end_full_tree cvswork2 v2
330 test_expect_success 'validate basic diffs saved during above cvswork2 edits' '
331 test $(grep Index: cvsEdit1.diff | wc -l) = 1 &&
332 test ! -s cvsEdit2-empty.diff &&
333 test $(grep Index: cvsEdit2-N.diff | wc -l) = 1 &&
334 test $(grep Index: cvsEdit3.diff | wc -l) = 3 &&
335 rm -rf diffSandbox &&
336 git clone -q -n . diffSandbox &&
338 cd diffSandbox &&
339 git checkout v1 &&
340 git apply -p0 --index <"$WORKDIR/cvsEdit1.diff" &&
341 git apply -p0 --index <"$WORKDIR/cvsEdit2-N.diff" &&
342 git apply -p0 --directory=adir --index <"$WORKDIR/cvsEdit3.diff" &&
343 git diff --exit-code v2
344 ) >"check_diff_apply.out" 2>&1
347 test_expect_success 'validate v1.2 diff saved during last cvswork2 edit' '
348 test $(grep Index: cvsEdit3-v1.2.diff | wc -l) = 9 &&
349 check_diff cvsEdit3-v1.2.diff v1.2 v2
352 test_expect_success 'validate v1.2 v1 diff saved during last cvswork2 edit' '
353 test $(grep Index: cvsEdit3-v1.2-v1.diff | wc -l) = 9 &&
354 check_diff cvsEdit3-v1.2-v1.diff v1.2 v1
357 test_expect_success 'cvs up [cvswork2]' '
358 ( cd cvswork2 && cvs -f up ) >cvs.log 2>&1 &&
359 check_start_tree cvswork2 &&
360 check_file cvswork2 textfile.c v2 &&
361 check_file cvswork2 adir/afile v2 &&
362 check_file cvswork2 adir/a2file v2 &&
363 check_file cvswork2 adir/bdir/bfile v2 &&
364 check_file cvswork2 adir/bdir/b4file v2 &&
365 check_end_full_tree cvswork2 v2
368 test_expect_success 'cvs up -r b2 [back to cvswork]' '
369 ( cd cvswork && cvs -f up -r b2 ) >cvs.log 2>&1 &&
370 check_start_tree cvswork &&
371 check_file cvswork textfile.c v2 &&
372 check_file cvswork adir/afile v2 &&
373 check_file cvswork adir/a2file v2 &&
374 check_file cvswork adir/bdir/bfile v2 &&
375 check_file cvswork adir/bdir/b4file v2 &&
376 check_end_full_tree cvswork v2
379 test_expect_success 'cvs up -r b1' '
380 ( cd cvswork && cvs -f up -r b1 ) >cvs.log 2>&1 &&
381 check_start_tree cvswork &&
382 check_file cvswork textfile.c v1.2 &&
383 check_file cvswork t3 v1.2 &&
384 check_file cvswork adir/afile v1.2 &&
385 check_file cvswork adir/a3file v1.2 &&
386 check_file cvswork adir/bdir/bfile v1.2 &&
387 check_file cvswork adir/bdir/b3file v1.2 &&
388 check_file cvswork cdir/cfile v1.2 &&
389 check_end_full_tree cvswork v1.2
392 test_expect_success 'cvs up -A' '
393 ( cd cvswork && cvs -f up -A ) >cvs.log 2>&1 &&
394 check_start_tree cvswork &&
395 check_file cvswork textfile.c v1 &&
396 check_file cvswork t2 v1 &&
397 check_file cvswork adir/afile v1 &&
398 check_file cvswork adir/a2file v1 &&
399 check_file cvswork adir/bdir/bfile v1 &&
400 check_file cvswork adir/bdir/b2file v1 &&
401 check_end_full_tree cvswork v1
404 test_expect_success 'cvs up (check CVS/Tag files)' '
405 ( cd cvswork && cvs -f up ) >cvs.log 2>&1 &&
406 check_start_tree cvswork &&
407 check_file cvswork textfile.c v1 &&
408 check_file cvswork t2 v1 &&
409 check_file cvswork adir/afile v1 &&
410 check_file cvswork adir/a2file v1 &&
411 check_file cvswork adir/bdir/bfile v1 &&
412 check_file cvswork adir/bdir/b2file v1 &&
413 check_end_full_tree cvswork v1
416 # This is not really legal CVS, but it seems to work anyway:
417 test_expect_success 'cvs up -r heads/b1' '
418 ( cd cvswork && cvs -f up -r heads/b1 ) >cvs.log 2>&1 &&
419 check_start_tree cvswork &&
420 check_file cvswork textfile.c v1.2 &&
421 check_file cvswork t3 v1.2 &&
422 check_file cvswork adir/afile v1.2 &&
423 check_file cvswork adir/a3file v1.2 &&
424 check_file cvswork adir/bdir/bfile v1.2 &&
425 check_file cvswork adir/bdir/b3file v1.2 &&
426 check_file cvswork cdir/cfile v1.2 &&
427 check_end_full_tree cvswork v1.2
430 # But this should work even if CVS client checks -r more carefully:
431 test_expect_success 'cvs up -r heads_-s-b2 (cvsserver escape mechanism)' '
432 ( cd cvswork && cvs -f up -r heads_-s-b2 ) >cvs.log 2>&1 &&
433 check_start_tree cvswork &&
434 check_file cvswork textfile.c v2 &&
435 check_file cvswork adir/afile v2 &&
436 check_file cvswork adir/a2file v2 &&
437 check_file cvswork adir/bdir/bfile v2 &&
438 check_file cvswork adir/bdir/b4file v2 &&
439 check_end_full_tree cvswork v2
442 v1hash=$(git rev-parse v1)
443 test_expect_success 'cvs up -r $(git rev-parse v1)' '
444 test -n "$v1hash" &&
445 ( cd cvswork && cvs -f up -r "$v1hash" ) >cvs.log 2>&1 &&
446 check_start_tree cvswork &&
447 check_file cvswork textfile.c v1 &&
448 check_file cvswork t2 v1 &&
449 check_file cvswork adir/afile v1 &&
450 check_file cvswork adir/a2file v1 &&
451 check_file cvswork adir/bdir/bfile v1 &&
452 check_file cvswork adir/bdir/b2file v1 &&
453 check_end_full_tree cvswork v1
456 test_expect_success 'cvs diff -r v1 -u' '
457 ( cd cvswork && cvs -f diff -r v1 -u ) >cvsDiff.out 2>cvs.log &&
458 test ! -s cvsDiff.out &&
459 test ! -s cvs.log
462 test_expect_success 'cvs diff -N -r v2 -u' '
463 ( cd cvswork && ! cvs -f diff -N -r v2 -u ) >cvsDiff.out 2>cvs.log &&
464 test ! -s cvs.log &&
465 test -s cvsDiff.out &&
466 check_diff cvsDiff.out v2 v1 >check_diff.out 2>&1
469 test_expect_success 'cvs diff -N -r v2 -r v1.2' '
470 ( cd cvswork && ! cvs -f diff -N -r v2 -r v1.2 -u ) >cvsDiff.out 2>cvs.log &&
471 test ! -s cvs.log &&
472 test -s cvsDiff.out &&
473 check_diff cvsDiff.out v2 v1.2 >check_diff.out 2>&1
476 test_expect_success 'apply early [cvswork3] diff to b3' '
477 git clone -q . gitwork3 &&
479 cd gitwork3 &&
480 git checkout -b b3 v1 &&
481 git apply -p0 --index <"$WORKDIR/cvswork3edit.diff" &&
482 git commit -m "cvswork3 edits applied"
483 ) &&
484 git fetch gitwork3 b3:b3 &&
485 git tag v3 b3
488 test_expect_success 'check [cvswork3] diff' '
489 ( cd cvswork3 && ! cvs -f diff -N -u ) >"$WORKDIR/cvsDiff.out" 2>cvs.log &&
490 test ! -s cvs.log &&
491 test -s cvsDiff.out &&
492 test $(grep Index: cvsDiff.out | wc -l) = 3 &&
493 test_cmp cvsDiff.out cvswork3edit.diff &&
494 check_diff cvsDiff.out v1 v3 >check_diff.out 2>&1
497 test_expect_success 'merge early [cvswork3] b3 with b1' '
498 ( cd gitwork3 && git merge "message" HEAD b1 ) &&
499 git fetch gitwork3 b3:b3 &&
500 git tag v3merged b3 &&
501 git push --tags gitcvs.git b3:b3
504 # This test would fail if cvsserver properly created a ".#afile"* file
505 # for the merge.
506 # TODO: Validate that the .# file was saved properly, and then
507 # delete/ignore it when checking the tree.
508 test_expect_success 'cvs up dirty [cvswork3]' '
510 cd cvswork3 &&
511 cvs -f up &&
512 ! cvs -f diff -N -u >"$WORKDIR/cvsDiff.out"
513 ) >cvs.log 2>&1 &&
514 test -s cvsDiff.out &&
515 test $(grep Index: cvsDiff.out | wc -l) = 2 &&
516 check_start_tree cvswork3 &&
517 check_file cvswork3 textfile.c v3merged &&
518 check_file cvswork3 t3 v3merged &&
519 check_file cvswork3 adir/afile v3merged &&
520 check_file cvswork3 adir/a3file v3merged &&
521 check_file cvswork3 adir/afile5 v3merged &&
522 check_file cvswork3 adir/bdir/bfile v3merged &&
523 check_file cvswork3 adir/bdir/b3file v3merged &&
524 check_file cvswork3 cdir/cfile v3merged &&
525 check_end_full_tree cvswork3 v3merged
528 # TODO: test cvs status
530 test_expect_success 'cvs commit [cvswork3]' '
532 cd cvswork3 &&
533 cvs -f commit -m "dirty sandbox after auto-merge"
534 ) >cvs.log 2>&1 &&
535 check_start_tree cvswork3 &&
536 check_file cvswork3 textfile.c v3merged &&
537 check_file cvswork3 t3 v3merged &&
538 check_file cvswork3 adir/afile v3merged &&
539 check_file cvswork3 adir/a3file v3merged &&
540 check_file cvswork3 adir/afile5 v3merged &&
541 check_file cvswork3 adir/bdir/bfile v3merged &&
542 check_file cvswork3 adir/bdir/b3file v3merged &&
543 check_file cvswork3 cdir/cfile v3merged &&
544 check_end_full_tree cvswork3 v3merged &&
545 git fetch gitcvs.git b3:b4 &&
546 git tag v4.1 b4 &&
547 git diff --exit-code v4.1 v3merged >check_diff_apply.out 2>&1
550 test_done