setup: trivial style fixes
[git/mjg.git] / contrib / remote-helpers / test-hg.sh
blob72f745d63f2f225b4976b27875d726b4652198ed
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-lib.sh
13 if ! test_have_prereq PYTHON
14 then
15 skip_all='skipping remote-hg tests; python not available'
16 test_done
19 if ! python -c 'import mercurial'
20 then
21 skip_all='skipping remote-hg tests; mercurial not available'
22 test_done
25 check () {
26 echo $3 >expected &&
27 git --git-dir=$1/.git log --format='%s' -1 $2 >actual
28 test_cmp expected actual
31 check_branch () {
32 if test -n "$3"
33 then
34 echo $3 >expected &&
35 hg -R $1 log -r $2 --template '{desc}\n' >actual &&
36 test_cmp expected actual
37 else
38 hg -R $1 branches >out &&
39 ! grep $2 out
43 check_bookmark () {
44 if test -n "$3"
45 then
46 echo $3 >expected &&
47 hg -R $1 log -r "bookmark('$2')" --template '{desc}\n' >actual &&
48 test_cmp expected actual
49 else
50 hg -R $1 bookmarks >out &&
51 ! grep $2 out
55 check_push () {
56 local expected_ret=$1 ret=0 ref_ret=0 IFS=':'
58 shift
59 git push origin "$@" 2>error
60 ret=$?
61 cat error
63 while read branch kind
65 case "$kind" in
66 'new')
67 grep "^ \* \[new branch\] *${branch} -> ${branch}$" error || ref_ret=1
69 'non-fast-forward')
70 grep "^ ! \[rejected\] *${branch} -> ${branch} (non-fast-forward)$" error || ref_ret=1
72 'fetch-first')
73 grep "^ ! \[rejected\] *${branch} -> ${branch} (fetch first)$" error || ref_ret=1
75 'forced-update')
76 grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *${branch} -> ${branch} (forced update)$" error || ref_ret=1
78 '')
79 grep "^ [a-f0-9]*\.\.[a-f0-9]* *${branch} -> ${branch}$" error || ref_ret=1
81 esac
82 test $ref_ret -ne 0 && echo "match for '$branch' failed" && break
83 done
85 if test $expected_ret -ne $ret -o $ref_ret -ne 0
86 then
87 return 1
90 return 0
93 setup () {
95 echo "[ui]"
96 echo "username = H G Wells <wells@example.com>"
97 echo "[extensions]"
98 echo "mq ="
99 ) >>"$HOME"/.hgrc &&
101 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230" &&
102 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" &&
103 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
106 setup
108 test_expect_success 'cloning' '
109 test_when_finished "rm -rf gitrepo*" &&
112 hg init hgrepo &&
113 cd hgrepo &&
114 echo zero >content &&
115 hg add content &&
116 hg commit -m zero
117 ) &&
119 git clone "hg::hgrepo" gitrepo &&
120 check gitrepo HEAD zero
123 test_expect_success 'cloning with branches' '
124 test_when_finished "rm -rf gitrepo*" &&
127 cd hgrepo &&
128 hg branch next &&
129 echo next >content &&
130 hg commit -m next
131 ) &&
133 git clone "hg::hgrepo" gitrepo &&
134 check gitrepo origin/branches/next next
137 test_expect_success 'cloning with bookmarks' '
138 test_when_finished "rm -rf gitrepo*" &&
141 cd hgrepo &&
142 hg checkout default &&
143 hg bookmark feature-a &&
144 echo feature-a >content &&
145 hg commit -m feature-a
146 ) &&
148 git clone "hg::hgrepo" gitrepo &&
149 check gitrepo origin/feature-a feature-a
152 test_expect_success 'update bookmark' '
153 test_when_finished "rm -rf gitrepo*" &&
156 cd hgrepo &&
157 hg bookmark devel
158 ) &&
161 git clone "hg::hgrepo" gitrepo &&
162 cd gitrepo &&
163 git checkout --quiet devel &&
164 echo devel >content &&
165 git commit -a -m devel &&
166 git push --quiet
167 ) &&
169 check_bookmark hgrepo devel devel
172 test_expect_success 'new bookmark' '
173 test_when_finished "rm -rf gitrepo*" &&
176 git clone "hg::hgrepo" gitrepo &&
177 cd gitrepo &&
178 git checkout --quiet -b feature-b &&
179 echo feature-b >content &&
180 git commit -a -m feature-b &&
181 git push --quiet origin feature-b
182 ) &&
184 check_bookmark hgrepo feature-b feature-b
187 # cleanup previous stuff
188 rm -rf hgrepo
190 author_test () {
191 echo $1 >>content &&
192 hg commit -u "$2" -m "add $1" &&
193 echo "$3" >>../expected
196 test_expect_success 'authors' '
197 test_when_finished "rm -rf hgrepo gitrepo" &&
200 hg init hgrepo &&
201 cd hgrepo &&
203 touch content &&
204 hg add content &&
206 >../expected &&
207 author_test alpha "" "H G Wells <wells@example.com>" &&
208 author_test beta "test" "test <unknown>" &&
209 author_test beta "test <test@example.com> (comment)" "test <test@example.com>" &&
210 author_test gamma "<test@example.com>" "Unknown <test@example.com>" &&
211 author_test delta "name<test@example.com>" "name <test@example.com>" &&
212 author_test epsilon "name <test@example.com" "name <test@example.com>" &&
213 author_test zeta " test " "test <unknown>" &&
214 author_test eta "test < test@example.com >" "test <test@example.com>" &&
215 author_test theta "test >test@example.com>" "test <test@example.com>" &&
216 author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
217 author_test kappa "test@example.com" "Unknown <test@example.com>"
218 ) &&
220 git clone "hg::hgrepo" gitrepo &&
221 git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" >actual &&
223 test_cmp expected actual
226 test_expect_success 'strip' '
227 test_when_finished "rm -rf hgrepo gitrepo" &&
230 hg init hgrepo &&
231 cd hgrepo &&
233 echo one >>content &&
234 hg add content &&
235 hg commit -m one &&
237 echo two >>content &&
238 hg commit -m two
239 ) &&
241 git clone "hg::hgrepo" gitrepo &&
244 cd hgrepo &&
245 hg strip 1 &&
247 echo three >>content &&
248 hg commit -m three &&
250 echo four >>content &&
251 hg commit -m four
252 ) &&
255 cd gitrepo &&
256 git fetch &&
257 git log --format="%s" origin/master >../actual
258 ) &&
260 hg -R hgrepo log --template "{desc}\n" >expected &&
261 test_cmp actual expected
264 test_expect_success 'remote push with master bookmark' '
265 test_when_finished "rm -rf hgrepo gitrepo*" &&
268 hg init hgrepo &&
269 cd hgrepo &&
270 echo zero >content &&
271 hg add content &&
272 hg commit -m zero &&
273 hg bookmark master &&
274 echo one >content &&
275 hg commit -m one
276 ) &&
279 git clone "hg::hgrepo" gitrepo &&
280 cd gitrepo &&
281 echo two >content &&
282 git commit -a -m two &&
283 git push
284 ) &&
286 check_branch hgrepo default two
289 cat >expected <<\EOF
290 changeset: 0:6e2126489d3d
291 tag: tip
292 user: A U Thor <author@example.com>
293 date: Mon Jan 01 00:00:00 2007 +0230
294 summary: one
298 test_expect_success 'remote push from master branch' '
299 test_when_finished "rm -rf hgrepo gitrepo*" &&
301 hg init hgrepo &&
304 git init gitrepo &&
305 cd gitrepo &&
306 git remote add origin "hg::../hgrepo" &&
307 echo one >content &&
308 git add content &&
309 git commit -a -m one &&
310 git push origin master
311 ) &&
313 hg -R hgrepo log >actual &&
314 cat actual &&
315 test_cmp expected actual &&
317 check_branch hgrepo default one
320 GIT_REMOTE_HG_TEST_REMOTE=1
321 export GIT_REMOTE_HG_TEST_REMOTE
323 test_expect_success 'remote cloning' '
324 test_when_finished "rm -rf gitrepo*" &&
327 hg init hgrepo &&
328 cd hgrepo &&
329 echo zero >content &&
330 hg add content &&
331 hg commit -m zero
332 ) &&
334 git clone "hg::hgrepo" gitrepo &&
335 check gitrepo HEAD zero
338 test_expect_success 'remote update bookmark' '
339 test_when_finished "rm -rf gitrepo*" &&
342 cd hgrepo &&
343 hg bookmark devel
344 ) &&
347 git clone "hg::hgrepo" gitrepo &&
348 cd gitrepo &&
349 git checkout --quiet devel &&
350 echo devel >content &&
351 git commit -a -m devel &&
352 git push --quiet
353 ) &&
355 check_bookmark hgrepo devel devel
358 test_expect_success 'remote new bookmark' '
359 test_when_finished "rm -rf gitrepo*" &&
362 git clone "hg::hgrepo" gitrepo &&
363 cd gitrepo &&
364 git checkout --quiet -b feature-b &&
365 echo feature-b >content &&
366 git commit -a -m feature-b &&
367 git push --quiet origin feature-b
368 ) &&
370 check_bookmark hgrepo feature-b feature-b
373 test_expect_success 'remote push diverged' '
374 test_when_finished "rm -rf gitrepo*" &&
376 git clone "hg::hgrepo" gitrepo &&
379 cd hgrepo &&
380 hg checkout default &&
381 echo bump >content &&
382 hg commit -m bump
383 ) &&
386 cd gitrepo &&
387 echo diverge >content &&
388 git commit -a -m diverged &&
389 check_push 1 <<-\EOF
390 master:non-fast-forward
392 ) &&
394 check_branch hgrepo default bump
397 test_expect_success 'remote update bookmark diverge' '
398 test_when_finished "rm -rf gitrepo*" &&
401 cd hgrepo &&
402 hg checkout tip^ &&
403 hg bookmark diverge
404 ) &&
406 git clone "hg::hgrepo" gitrepo &&
409 cd hgrepo &&
410 echo "bump bookmark" >content &&
411 hg commit -m "bump bookmark"
412 ) &&
415 cd gitrepo &&
416 git checkout --quiet diverge &&
417 echo diverge >content &&
418 git commit -a -m diverge &&
419 check_push 1 <<-\EOF
420 diverge:fetch-first
422 ) &&
424 check_bookmark hgrepo diverge "bump bookmark"
427 test_expect_success 'remote new bookmark multiple branch head' '
428 test_when_finished "rm -rf gitrepo*" &&
431 git clone "hg::hgrepo" gitrepo &&
432 cd gitrepo &&
433 git checkout --quiet -b feature-c HEAD^ &&
434 echo feature-c >content &&
435 git commit -a -m feature-c &&
436 git push --quiet origin feature-c
437 ) &&
439 check_bookmark hgrepo feature-c feature-c
442 # cleanup previous stuff
443 rm -rf hgrepo
445 setup_big_push () {
447 hg init hgrepo &&
448 cd hgrepo &&
449 echo zero >content &&
450 hg add content &&
451 hg commit -m zero &&
452 hg bookmark bad_bmark1 &&
453 echo one >content &&
454 hg commit -m one &&
455 hg bookmark bad_bmark2 &&
456 hg bookmark good_bmark &&
457 hg bookmark -i good_bmark &&
458 hg -q branch good_branch &&
459 echo "good branch" >content &&
460 hg commit -m "good branch" &&
461 hg -q branch bad_branch &&
462 echo "bad branch" >content &&
463 hg commit -m "bad branch"
464 ) &&
466 git clone "hg::hgrepo" gitrepo &&
469 cd gitrepo &&
470 echo two >content &&
471 git commit -q -a -m two &&
473 git checkout -q good_bmark &&
474 echo three >content &&
475 git commit -q -a -m three &&
477 git checkout -q bad_bmark1 &&
478 git reset --hard HEAD^ &&
479 echo four >content &&
480 git commit -q -a -m four &&
482 git checkout -q bad_bmark2 &&
483 git reset --hard HEAD^ &&
484 echo five >content &&
485 git commit -q -a -m five &&
487 git checkout -q -b new_bmark master &&
488 echo six >content &&
489 git commit -q -a -m six &&
491 git checkout -q branches/good_branch &&
492 echo seven >content &&
493 git commit -q -a -m seven &&
494 echo eight >content &&
495 git commit -q -a -m eight &&
497 git checkout -q branches/bad_branch &&
498 git reset --hard HEAD^ &&
499 echo nine >content &&
500 git commit -q -a -m nine &&
502 git checkout -q -b branches/new_branch master &&
503 echo ten >content &&
504 git commit -q -a -m ten
508 test_expect_success 'remote big push' '
509 test_when_finished "rm -rf hgrepo gitrepo*" &&
511 setup_big_push
514 cd gitrepo &&
516 check_push 1 --all <<-\EOF
517 master
518 good_bmark
519 branches/good_branch
520 new_bmark:new
521 branches/new_branch:new
522 bad_bmark1:non-fast-forward
523 bad_bmark2:non-fast-forward
524 branches/bad_branch:non-fast-forward
526 ) &&
528 check_branch hgrepo default one &&
529 check_branch hgrepo good_branch "good branch" &&
530 check_branch hgrepo bad_branch "bad branch" &&
531 check_branch hgrepo new_branch '' &&
532 check_bookmark hgrepo good_bmark one &&
533 check_bookmark hgrepo bad_bmark1 one &&
534 check_bookmark hgrepo bad_bmark2 one &&
535 check_bookmark hgrepo new_bmark ''
538 test_expect_success 'remote big push fetch first' '
539 test_when_finished "rm -rf hgrepo gitrepo*" &&
542 hg init hgrepo &&
543 cd hgrepo &&
544 echo zero >content &&
545 hg add content &&
546 hg commit -m zero &&
547 hg bookmark bad_bmark &&
548 hg bookmark good_bmark &&
549 hg bookmark -i good_bmark &&
550 hg -q branch good_branch &&
551 echo "good branch" >content &&
552 hg commit -m "good branch" &&
553 hg -q branch bad_branch &&
554 echo "bad branch" >content &&
555 hg commit -m "bad branch"
556 ) &&
558 git clone "hg::hgrepo" gitrepo &&
561 cd hgrepo &&
562 hg bookmark -f bad_bmark &&
563 echo update_bmark >content &&
564 hg commit -m "update bmark"
565 ) &&
568 cd gitrepo &&
569 echo two >content &&
570 git commit -q -a -m two &&
572 git checkout -q good_bmark &&
573 echo three >content &&
574 git commit -q -a -m three &&
576 git checkout -q bad_bmark &&
577 echo four >content &&
578 git commit -q -a -m four &&
580 git checkout -q branches/bad_branch &&
581 echo five >content &&
582 git commit -q -a -m five &&
584 check_push 1 --all <<-\EOF &&
585 master
586 good_bmark
587 bad_bmark:fetch-first
588 branches/bad_branch:festch-first
591 git fetch &&
593 check_push 1 --all <<-\EOF
594 master
595 good_bmark
596 bad_bmark:non-fast-forward
597 branches/bad_branch:non-fast-forward
602 test_expect_failure 'remote big push force' '
603 test_when_finished "rm -rf hgrepo gitrepo*" &&
605 setup_big_push
608 cd gitrepo &&
610 check_push 0 --force --all <<-\EOF
611 master
612 good_bmark
613 branches/good_branch
614 new_bmark:new
615 branches/new_branch:new
616 bad_bmark1:forced-update
617 bad_bmark2:forced-update
618 branches/bad_branch:forced-update
620 ) &&
622 check_branch hgrepo default six &&
623 check_branch hgrepo good_branch eight &&
624 check_branch hgrepo bad_branch nine &&
625 check_branch hgrepo new_branch ten &&
626 check_bookmark hgrepo good_bmark three &&
627 check_bookmark hgrepo bad_bmark1 four &&
628 check_bookmark hgrepo bad_bmark2 five &&
629 check_bookmark hgrepo new_bmark six
632 test_expect_failure 'remote big push dry-run' '
633 test_when_finished "rm -rf hgrepo gitrepo*" &&
635 setup_big_push
638 cd gitrepo &&
640 check_push 1 --dry-run --all <<-\EOF &&
641 master
642 good_bmark
643 branches/good_branch
644 new_bmark:new
645 branches/new_branch:new
646 bad_bmark1:non-fast-forward
647 bad_bmark2:non-fast-forward
648 branches/bad_branch:non-fast-forward
651 check_push 0 --dry-run master good_bmark new_bmark branches/good_branch branches/new_branch <<-\EOF
652 master
653 good_bmark
654 branches/good_branch
655 new_bmark:new
656 branches/new_branch:new
658 ) &&
660 check_branch hgrepo default one &&
661 check_branch hgrepo good_branch "good branch" &&
662 check_branch hgrepo bad_branch "bad branch" &&
663 check_branch hgrepo new_branch '' &&
664 check_bookmark hgrepo good_bmark one &&
665 check_bookmark hgrepo bad_bmark1 one &&
666 check_bookmark hgrepo bad_bmark2 one &&
667 check_bookmark hgrepo new_bmark ''
670 test_expect_success 'remote double failed push' '
671 test_when_finished "rm -rf hgrepo gitrepo*" &&
674 hg init hgrepo &&
675 cd hgrepo &&
676 echo zero >content &&
677 hg add content &&
678 hg commit -m zero &&
679 echo one >content &&
680 hg commit -m one
681 ) &&
684 git clone "hg::hgrepo" gitrepo &&
685 cd gitrepo &&
686 git reset --hard HEAD^ &&
687 echo two >content &&
688 git commit -a -m two &&
689 test_expect_code 1 git push &&
690 test_expect_code 1 git push
694 test_done