test-hg.sh: help user correlate verbose output with email test
[git.git] / contrib / remote-helpers / test-hg.sh
blob642ad938cd3202eafeeb61a1dd95d9acfdab71a0
1 #!/bin/sh
3 # Copyright (c) 2012 Felipe Contreras
5 # Base commands from hg-git tests:
6 # https://bitbucket.org/durin42/hg-git/src
9 test_description='Test remote-hg'
11 test -n "$TEST_DIRECTORY" || TEST_DIRECTORY=${0%/*}/../../t
12 . "$TEST_DIRECTORY"/test-lib.sh
14 if ! test_have_prereq PYTHON
15 then
16 skip_all='skipping remote-hg tests; python not available'
17 test_done
20 if ! python -c 'import mercurial'
21 then
22 skip_all='skipping remote-hg tests; mercurial not available'
23 test_done
26 check () {
27 echo $3 >expected &&
28 git --git-dir=$1/.git log --format='%s' -1 $2 >actual
29 test_cmp expected actual
32 check_branch () {
33 if test -n "$3"
34 then
35 echo $3 >expected &&
36 hg -R $1 log -r $2 --template '{desc}\n' >actual &&
37 test_cmp expected actual
38 else
39 hg -R $1 branches >out &&
40 ! grep $2 out
44 check_bookmark () {
45 if test -n "$3"
46 then
47 echo $3 >expected &&
48 hg -R $1 log -r "bookmark('$2')" --template '{desc}\n' >actual &&
49 test_cmp expected actual
50 else
51 hg -R $1 bookmarks >out &&
52 ! grep $2 out
56 check_push () {
57 expected_ret=$1 ret=0 ref_ret=0
59 shift
60 git push origin "$@" 2>error
61 ret=$?
62 cat error
64 while IFS=':' read branch kind
66 case "$kind" in
67 'new')
68 grep "^ \* \[new branch\] *${branch} -> ${branch}$" error || ref_ret=1
70 'non-fast-forward')
71 grep "^ ! \[rejected\] *${branch} -> ${branch} (non-fast-forward)$" error || ref_ret=1
73 'fetch-first')
74 grep "^ ! \[rejected\] *${branch} -> ${branch} (fetch first)$" error || ref_ret=1
76 'forced-update')
77 grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *${branch} -> ${branch} (forced update)$" error || ref_ret=1
79 '')
80 grep "^ [a-f0-9]*\.\.[a-f0-9]* *${branch} -> ${branch}$" error || ref_ret=1
82 esac
83 test $ref_ret -ne 0 && echo "match for '$branch' failed" && break
84 done
86 if test $expected_ret -ne $ret || test $ref_ret -ne 0
87 then
88 return 1
91 return 0
94 setup () {
96 echo "[ui]"
97 echo "username = H G Wells <wells@example.com>"
98 echo "[extensions]"
99 echo "mq ="
100 ) >>"$HOME"/.hgrc &&
102 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230" &&
103 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" &&
104 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
107 setup
109 test_expect_success 'cloning' '
110 test_when_finished "rm -rf gitrepo*" &&
113 hg init hgrepo &&
114 cd hgrepo &&
115 echo zero >content &&
116 hg add content &&
117 hg commit -m zero
118 ) &&
120 git clone "hg::hgrepo" gitrepo &&
121 check gitrepo HEAD zero
124 test_expect_success 'cloning with branches' '
125 test_when_finished "rm -rf gitrepo*" &&
128 cd hgrepo &&
129 hg branch next &&
130 echo next >content &&
131 hg commit -m next
132 ) &&
134 git clone "hg::hgrepo" gitrepo &&
135 check gitrepo origin/branches/next next
138 test_expect_success 'cloning with bookmarks' '
139 test_when_finished "rm -rf gitrepo*" &&
142 cd hgrepo &&
143 hg checkout default &&
144 hg bookmark feature-a &&
145 echo feature-a >content &&
146 hg commit -m feature-a
147 ) &&
149 git clone "hg::hgrepo" gitrepo &&
150 check gitrepo origin/feature-a feature-a
153 test_expect_success 'update bookmark' '
154 test_when_finished "rm -rf gitrepo*" &&
157 cd hgrepo &&
158 hg bookmark devel
159 ) &&
162 git clone "hg::hgrepo" gitrepo &&
163 cd gitrepo &&
164 git checkout --quiet devel &&
165 echo devel >content &&
166 git commit -a -m devel &&
167 git push --quiet
168 ) &&
170 check_bookmark hgrepo devel devel
173 test_expect_success 'new bookmark' '
174 test_when_finished "rm -rf gitrepo*" &&
177 git clone "hg::hgrepo" gitrepo &&
178 cd gitrepo &&
179 git checkout --quiet -b feature-b &&
180 echo feature-b >content &&
181 git commit -a -m feature-b &&
182 git push --quiet origin feature-b
183 ) &&
185 check_bookmark hgrepo feature-b feature-b
188 # cleanup previous stuff
189 rm -rf hgrepo
191 author_test () {
192 echo $1 >>content &&
193 hg commit -u "$2" -m "add $1" &&
194 echo "$3" >>../expected
197 test_expect_success 'authors' '
198 test_when_finished "rm -rf hgrepo gitrepo" &&
201 hg init hgrepo &&
202 cd hgrepo &&
204 touch content &&
205 hg add content &&
207 >../expected &&
208 author_test alpha "" "H G Wells <wells@example.com>" &&
209 author_test beta "beta" "beta <unknown>" &&
210 author_test gamma "gamma <test@example.com> (comment)" "gamma <test@example.com>" &&
211 author_test delta "<delta@example.com>" "Unknown <delta@example.com>" &&
212 author_test epsilon "epsilon<test@example.com>" "epsilon <test@example.com>" &&
213 author_test zeta "zeta <test@example.com" "zeta <test@example.com>" &&
214 author_test eta " eta " "eta <unknown>" &&
215 author_test theta "theta < test@example.com >" "theta <test@example.com>" &&
216 author_test iota "iota >test@example.com>" "iota <test@example.com>" &&
217 author_test kappa "kappa < test <at> example <dot> com>" "kappa <unknown>" &&
218 author_test lambda "lambda@example.com" "Unknown <lambda@example.com>"
219 ) &&
221 git clone "hg::hgrepo" gitrepo &&
222 git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" >actual &&
224 test_cmp expected actual
227 test_expect_success 'strip' '
228 test_when_finished "rm -rf hgrepo gitrepo" &&
231 hg init hgrepo &&
232 cd hgrepo &&
234 echo one >>content &&
235 hg add content &&
236 hg commit -m one &&
238 echo two >>content &&
239 hg commit -m two
240 ) &&
242 git clone "hg::hgrepo" gitrepo &&
245 cd hgrepo &&
246 hg strip 1 &&
248 echo three >>content &&
249 hg commit -m three &&
251 echo four >>content &&
252 hg commit -m four
253 ) &&
256 cd gitrepo &&
257 git fetch &&
258 git log --format="%s" origin/master >../actual
259 ) &&
261 hg -R hgrepo log --template "{desc}\n" >expected &&
262 test_cmp actual expected
265 test_expect_success 'remote push with master bookmark' '
266 test_when_finished "rm -rf hgrepo gitrepo*" &&
269 hg init hgrepo &&
270 cd hgrepo &&
271 echo zero >content &&
272 hg add content &&
273 hg commit -m zero &&
274 hg bookmark master &&
275 echo one >content &&
276 hg commit -m one
277 ) &&
280 git clone "hg::hgrepo" gitrepo &&
281 cd gitrepo &&
282 echo two >content &&
283 git commit -a -m two &&
284 git push
285 ) &&
287 check_branch hgrepo default two
290 cat >expected <<\EOF
291 changeset: 0:6e2126489d3d
292 tag: tip
293 user: A U Thor <author@example.com>
294 date: Mon Jan 01 00:00:00 2007 +0230
295 summary: one
299 test_expect_success 'remote push from master branch' '
300 test_when_finished "rm -rf hgrepo gitrepo*" &&
302 hg init hgrepo &&
305 git init gitrepo &&
306 cd gitrepo &&
307 git remote add origin "hg::../hgrepo" &&
308 echo one >content &&
309 git add content &&
310 git commit -a -m one &&
311 git push origin master
312 ) &&
314 hg -R hgrepo log >actual &&
315 cat actual &&
316 test_cmp expected actual &&
318 check_branch hgrepo default one
321 GIT_REMOTE_HG_TEST_REMOTE=1
322 export GIT_REMOTE_HG_TEST_REMOTE
324 test_expect_success 'remote cloning' '
325 test_when_finished "rm -rf gitrepo*" &&
328 hg init hgrepo &&
329 cd hgrepo &&
330 echo zero >content &&
331 hg add content &&
332 hg commit -m zero
333 ) &&
335 git clone "hg::hgrepo" gitrepo &&
336 check gitrepo HEAD zero
339 test_expect_success 'remote update bookmark' '
340 test_when_finished "rm -rf gitrepo*" &&
343 cd hgrepo &&
344 hg bookmark devel
345 ) &&
348 git clone "hg::hgrepo" gitrepo &&
349 cd gitrepo &&
350 git checkout --quiet devel &&
351 echo devel >content &&
352 git commit -a -m devel &&
353 git push --quiet
354 ) &&
356 check_bookmark hgrepo devel devel
359 test_expect_success 'remote new bookmark' '
360 test_when_finished "rm -rf gitrepo*" &&
363 git clone "hg::hgrepo" gitrepo &&
364 cd gitrepo &&
365 git checkout --quiet -b feature-b &&
366 echo feature-b >content &&
367 git commit -a -m feature-b &&
368 git push --quiet origin feature-b
369 ) &&
371 check_bookmark hgrepo feature-b feature-b
374 test_expect_success 'remote push diverged' '
375 test_when_finished "rm -rf gitrepo*" &&
377 git clone "hg::hgrepo" gitrepo &&
380 cd hgrepo &&
381 hg checkout default &&
382 echo bump >content &&
383 hg commit -m bump
384 ) &&
387 cd gitrepo &&
388 echo diverge >content &&
389 git commit -a -m diverged &&
390 check_push 1 <<-\EOF
391 master:non-fast-forward
393 ) &&
395 check_branch hgrepo default bump
398 test_expect_success 'remote update bookmark diverge' '
399 test_when_finished "rm -rf gitrepo*" &&
402 cd hgrepo &&
403 hg checkout tip^ &&
404 hg bookmark diverge
405 ) &&
407 git clone "hg::hgrepo" gitrepo &&
410 cd hgrepo &&
411 echo "bump bookmark" >content &&
412 hg commit -m "bump bookmark"
413 ) &&
416 cd gitrepo &&
417 git checkout --quiet diverge &&
418 echo diverge >content &&
419 git commit -a -m diverge &&
420 check_push 1 <<-\EOF
421 diverge:fetch-first
423 ) &&
425 check_bookmark hgrepo diverge "bump bookmark"
428 test_expect_success 'remote new bookmark multiple branch head' '
429 test_when_finished "rm -rf gitrepo*" &&
432 git clone "hg::hgrepo" gitrepo &&
433 cd gitrepo &&
434 git checkout --quiet -b feature-c HEAD^ &&
435 echo feature-c >content &&
436 git commit -a -m feature-c &&
437 git push --quiet origin feature-c
438 ) &&
440 check_bookmark hgrepo feature-c feature-c
443 # cleanup previous stuff
444 rm -rf hgrepo
446 setup_big_push () {
448 hg init hgrepo &&
449 cd hgrepo &&
450 echo zero >content &&
451 hg add content &&
452 hg commit -m zero &&
453 hg bookmark bad_bmark1 &&
454 echo one >content &&
455 hg commit -m one &&
456 hg bookmark bad_bmark2 &&
457 hg bookmark good_bmark &&
458 hg bookmark -i good_bmark &&
459 hg -q branch good_branch &&
460 echo "good branch" >content &&
461 hg commit -m "good branch" &&
462 hg -q branch bad_branch &&
463 echo "bad branch" >content &&
464 hg commit -m "bad branch"
465 ) &&
467 git clone "hg::hgrepo" gitrepo &&
470 cd gitrepo &&
471 echo two >content &&
472 git commit -q -a -m two &&
474 git checkout -q good_bmark &&
475 echo three >content &&
476 git commit -q -a -m three &&
478 git checkout -q bad_bmark1 &&
479 git reset --hard HEAD^ &&
480 echo four >content &&
481 git commit -q -a -m four &&
483 git checkout -q bad_bmark2 &&
484 git reset --hard HEAD^ &&
485 echo five >content &&
486 git commit -q -a -m five &&
488 git checkout -q -b new_bmark master &&
489 echo six >content &&
490 git commit -q -a -m six &&
492 git checkout -q branches/good_branch &&
493 echo seven >content &&
494 git commit -q -a -m seven &&
495 echo eight >content &&
496 git commit -q -a -m eight &&
498 git checkout -q branches/bad_branch &&
499 git reset --hard HEAD^ &&
500 echo nine >content &&
501 git commit -q -a -m nine &&
503 git checkout -q -b branches/new_branch master &&
504 echo ten >content &&
505 git commit -q -a -m ten
509 test_expect_success 'remote big push' '
510 test_when_finished "rm -rf hgrepo gitrepo*" &&
512 setup_big_push
515 cd gitrepo &&
517 check_push 1 --all <<-\EOF
518 master
519 good_bmark
520 branches/good_branch
521 new_bmark:new
522 branches/new_branch:new
523 bad_bmark1:non-fast-forward
524 bad_bmark2:non-fast-forward
525 branches/bad_branch:non-fast-forward
527 ) &&
529 check_branch hgrepo default one &&
530 check_branch hgrepo good_branch "good branch" &&
531 check_branch hgrepo bad_branch "bad branch" &&
532 check_branch hgrepo new_branch '' &&
533 check_bookmark hgrepo good_bmark one &&
534 check_bookmark hgrepo bad_bmark1 one &&
535 check_bookmark hgrepo bad_bmark2 one &&
536 check_bookmark hgrepo new_bmark ''
539 test_expect_success 'remote big push fetch first' '
540 test_when_finished "rm -rf hgrepo gitrepo*" &&
543 hg init hgrepo &&
544 cd hgrepo &&
545 echo zero >content &&
546 hg add content &&
547 hg commit -m zero &&
548 hg bookmark bad_bmark &&
549 hg bookmark good_bmark &&
550 hg bookmark -i good_bmark &&
551 hg -q branch good_branch &&
552 echo "good branch" >content &&
553 hg commit -m "good branch" &&
554 hg -q branch bad_branch &&
555 echo "bad branch" >content &&
556 hg commit -m "bad branch"
557 ) &&
559 git clone "hg::hgrepo" gitrepo &&
562 cd hgrepo &&
563 hg bookmark -f bad_bmark &&
564 echo update_bmark >content &&
565 hg commit -m "update bmark"
566 ) &&
569 cd gitrepo &&
570 echo two >content &&
571 git commit -q -a -m two &&
573 git checkout -q good_bmark &&
574 echo three >content &&
575 git commit -q -a -m three &&
577 git checkout -q bad_bmark &&
578 echo four >content &&
579 git commit -q -a -m four &&
581 git checkout -q branches/bad_branch &&
582 echo five >content &&
583 git commit -q -a -m five &&
585 check_push 1 --all <<-\EOF &&
586 master
587 good_bmark
588 bad_bmark:fetch-first
589 branches/bad_branch:festch-first
592 git fetch &&
594 check_push 1 --all <<-\EOF
595 master
596 good_bmark
597 bad_bmark:non-fast-forward
598 branches/bad_branch:non-fast-forward
603 test_expect_failure 'remote big push force' '
604 test_when_finished "rm -rf hgrepo gitrepo*" &&
606 setup_big_push
609 cd gitrepo &&
611 check_push 0 --force --all <<-\EOF
612 master
613 good_bmark
614 branches/good_branch
615 new_bmark:new
616 branches/new_branch:new
617 bad_bmark1:forced-update
618 bad_bmark2:forced-update
619 branches/bad_branch:forced-update
621 ) &&
623 check_branch hgrepo default six &&
624 check_branch hgrepo good_branch eight &&
625 check_branch hgrepo bad_branch nine &&
626 check_branch hgrepo new_branch ten &&
627 check_bookmark hgrepo good_bmark three &&
628 check_bookmark hgrepo bad_bmark1 four &&
629 check_bookmark hgrepo bad_bmark2 five &&
630 check_bookmark hgrepo new_bmark six
633 test_expect_failure 'remote big push dry-run' '
634 test_when_finished "rm -rf hgrepo gitrepo*" &&
636 setup_big_push
639 cd gitrepo &&
641 check_push 1 --dry-run --all <<-\EOF &&
642 master
643 good_bmark
644 branches/good_branch
645 new_bmark:new
646 branches/new_branch:new
647 bad_bmark1:non-fast-forward
648 bad_bmark2:non-fast-forward
649 branches/bad_branch:non-fast-forward
652 check_push 0 --dry-run master good_bmark new_bmark branches/good_branch branches/new_branch <<-\EOF
653 master
654 good_bmark
655 branches/good_branch
656 new_bmark:new
657 branches/new_branch:new
659 ) &&
661 check_branch hgrepo default one &&
662 check_branch hgrepo good_branch "good branch" &&
663 check_branch hgrepo bad_branch "bad branch" &&
664 check_branch hgrepo new_branch '' &&
665 check_bookmark hgrepo good_bmark one &&
666 check_bookmark hgrepo bad_bmark1 one &&
667 check_bookmark hgrepo bad_bmark2 one &&
668 check_bookmark hgrepo new_bmark ''
671 test_expect_success 'remote double failed push' '
672 test_when_finished "rm -rf hgrepo gitrepo*" &&
675 hg init hgrepo &&
676 cd hgrepo &&
677 echo zero >content &&
678 hg add content &&
679 hg commit -m zero &&
680 echo one >content &&
681 hg commit -m one
682 ) &&
685 git clone "hg::hgrepo" gitrepo &&
686 cd gitrepo &&
687 git reset --hard HEAD^ &&
688 echo two >content &&
689 git commit -a -m two &&
690 test_expect_code 1 git push &&
691 test_expect_code 1 git push
695 test_done