remote-hg: test 'shared_path' in a moved clone
[git.git] / contrib / remote-helpers / test-hg.sh
blob5d128a5da9a1afd3bf441f58e75d4f02a64509d5
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 author_test mu "mu.mu@example.com" "Unknown <mu.mu@example.com>"
220 ) &&
222 git clone "hg::hgrepo" gitrepo &&
223 git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" >actual &&
225 test_cmp expected actual
228 test_expect_success 'strip' '
229 test_when_finished "rm -rf hgrepo gitrepo" &&
232 hg init hgrepo &&
233 cd hgrepo &&
235 echo one >>content &&
236 hg add content &&
237 hg commit -m one &&
239 echo two >>content &&
240 hg commit -m two
241 ) &&
243 git clone "hg::hgrepo" gitrepo &&
246 cd hgrepo &&
247 hg strip 1 &&
249 echo three >>content &&
250 hg commit -m three &&
252 echo four >>content &&
253 hg commit -m four
254 ) &&
257 cd gitrepo &&
258 git fetch &&
259 git log --format="%s" origin/master >../actual
260 ) &&
262 hg -R hgrepo log --template "{desc}\n" >expected &&
263 test_cmp actual expected
266 test_expect_success 'remote push with master bookmark' '
267 test_when_finished "rm -rf hgrepo gitrepo*" &&
270 hg init hgrepo &&
271 cd hgrepo &&
272 echo zero >content &&
273 hg add content &&
274 hg commit -m zero &&
275 hg bookmark master &&
276 echo one >content &&
277 hg commit -m one
278 ) &&
281 git clone "hg::hgrepo" gitrepo &&
282 cd gitrepo &&
283 echo two >content &&
284 git commit -a -m two &&
285 git push
286 ) &&
288 check_branch hgrepo default two
291 cat >expected <<\EOF
292 changeset: 0:6e2126489d3d
293 tag: tip
294 user: A U Thor <author@example.com>
295 date: Mon Jan 01 00:00:00 2007 +0230
296 summary: one
300 test_expect_success 'remote push from master branch' '
301 test_when_finished "rm -rf hgrepo gitrepo*" &&
303 hg init hgrepo &&
306 git init gitrepo &&
307 cd gitrepo &&
308 git remote add origin "hg::../hgrepo" &&
309 echo one >content &&
310 git add content &&
311 git commit -a -m one &&
312 git push origin master
313 ) &&
315 hg -R hgrepo log >actual &&
316 cat actual &&
317 test_cmp expected actual &&
319 check_branch hgrepo default one
322 GIT_REMOTE_HG_TEST_REMOTE=1
323 export GIT_REMOTE_HG_TEST_REMOTE
325 test_expect_success 'remote cloning' '
326 test_when_finished "rm -rf gitrepo*" &&
329 hg init hgrepo &&
330 cd hgrepo &&
331 echo zero >content &&
332 hg add content &&
333 hg commit -m zero
334 ) &&
336 git clone "hg::hgrepo" gitrepo &&
337 check gitrepo HEAD zero
340 test_expect_success 'moving remote clone' '
341 test_when_finished "rm -rf gitrepo*" &&
344 git clone "hg::hgrepo" gitrepo &&
345 mv gitrepo gitrepo2 &&
346 cd gitrepo2 &&
347 git fetch
351 test_expect_success 'remote update bookmark' '
352 test_when_finished "rm -rf gitrepo*" &&
355 cd hgrepo &&
356 hg bookmark devel
357 ) &&
360 git clone "hg::hgrepo" gitrepo &&
361 cd gitrepo &&
362 git checkout --quiet devel &&
363 echo devel >content &&
364 git commit -a -m devel &&
365 git push --quiet
366 ) &&
368 check_bookmark hgrepo devel devel
371 test_expect_success 'remote new bookmark' '
372 test_when_finished "rm -rf gitrepo*" &&
375 git clone "hg::hgrepo" gitrepo &&
376 cd gitrepo &&
377 git checkout --quiet -b feature-b &&
378 echo feature-b >content &&
379 git commit -a -m feature-b &&
380 git push --quiet origin feature-b
381 ) &&
383 check_bookmark hgrepo feature-b feature-b
386 test_expect_success 'remote push diverged' '
387 test_when_finished "rm -rf gitrepo*" &&
389 git clone "hg::hgrepo" gitrepo &&
392 cd hgrepo &&
393 hg checkout default &&
394 echo bump >content &&
395 hg commit -m bump
396 ) &&
399 cd gitrepo &&
400 echo diverge >content &&
401 git commit -a -m diverged &&
402 check_push 1 <<-\EOF
403 master:non-fast-forward
405 ) &&
407 check_branch hgrepo default bump
410 test_expect_success 'remote update bookmark diverge' '
411 test_when_finished "rm -rf gitrepo*" &&
414 cd hgrepo &&
415 hg checkout tip^ &&
416 hg bookmark diverge
417 ) &&
419 git clone "hg::hgrepo" gitrepo &&
422 cd hgrepo &&
423 echo "bump bookmark" >content &&
424 hg commit -m "bump bookmark"
425 ) &&
428 cd gitrepo &&
429 git checkout --quiet diverge &&
430 echo diverge >content &&
431 git commit -a -m diverge &&
432 check_push 1 <<-\EOF
433 diverge:fetch-first
435 ) &&
437 check_bookmark hgrepo diverge "bump bookmark"
440 test_expect_success 'remote new bookmark multiple branch head' '
441 test_when_finished "rm -rf gitrepo*" &&
444 git clone "hg::hgrepo" gitrepo &&
445 cd gitrepo &&
446 git checkout --quiet -b feature-c HEAD^ &&
447 echo feature-c >content &&
448 git commit -a -m feature-c &&
449 git push --quiet origin feature-c
450 ) &&
452 check_bookmark hgrepo feature-c feature-c
455 # cleanup previous stuff
456 rm -rf hgrepo
458 test_expect_success 'fetch special filenames' '
459 test_when_finished "rm -rf hgrepo gitrepo && LC_ALL=C" &&
461 LC_ALL=en_US.UTF-8
462 export LC_ALL
465 hg init hgrepo &&
466 cd hgrepo &&
468 echo test >> "æ rø" &&
469 hg add "æ rø" &&
470 echo test >> "ø~?" &&
471 hg add "ø~?" &&
472 hg commit -m add-utf-8 &&
473 echo test >> "æ rø" &&
474 hg commit -m test-utf-8 &&
475 hg rm "ø~?" &&
476 hg mv "æ rø" "ø~?" &&
477 hg commit -m hg-mv-utf-8
478 ) &&
481 git clone "hg::hgrepo" gitrepo &&
482 cd gitrepo &&
483 git -c core.quotepath=false ls-files > ../actual
484 ) &&
485 echo "ø~?" > expected &&
486 test_cmp expected actual
489 test_expect_success 'push special filenames' '
490 test_when_finished "rm -rf hgrepo gitrepo && LC_ALL=C" &&
492 mkdir -p tmp && cd tmp &&
494 LC_ALL=en_US.UTF-8
495 export LC_ALL
498 hg init hgrepo &&
499 cd hgrepo &&
501 echo one >> content &&
502 hg add content &&
503 hg commit -m one
504 ) &&
507 git clone "hg::hgrepo" gitrepo &&
508 cd gitrepo &&
510 echo test >> "æ rø" &&
511 git add "æ rø" &&
512 git commit -m utf-8 &&
514 git push
515 ) &&
517 (cd hgrepo &&
518 hg update &&
519 hg manifest > ../actual
520 ) &&
522 printf "content\næ rø\n" > expected &&
523 test_cmp expected actual
526 setup_big_push () {
528 hg init hgrepo &&
529 cd hgrepo &&
530 echo zero >content &&
531 hg add content &&
532 hg commit -m zero &&
533 hg bookmark bad_bmark1 &&
534 echo one >content &&
535 hg commit -m one &&
536 hg bookmark bad_bmark2 &&
537 hg bookmark good_bmark &&
538 hg bookmark -i good_bmark &&
539 hg -q branch good_branch &&
540 echo "good branch" >content &&
541 hg commit -m "good branch" &&
542 hg -q branch bad_branch &&
543 echo "bad branch" >content &&
544 hg commit -m "bad branch"
545 ) &&
547 git clone "hg::hgrepo" gitrepo &&
550 cd gitrepo &&
551 echo two >content &&
552 git commit -q -a -m two &&
554 git checkout -q good_bmark &&
555 echo three >content &&
556 git commit -q -a -m three &&
558 git checkout -q bad_bmark1 &&
559 git reset --hard HEAD^ &&
560 echo four >content &&
561 git commit -q -a -m four &&
563 git checkout -q bad_bmark2 &&
564 git reset --hard HEAD^ &&
565 echo five >content &&
566 git commit -q -a -m five &&
568 git checkout -q -b new_bmark master &&
569 echo six >content &&
570 git commit -q -a -m six &&
572 git checkout -q branches/good_branch &&
573 echo seven >content &&
574 git commit -q -a -m seven &&
575 echo eight >content &&
576 git commit -q -a -m eight &&
578 git checkout -q branches/bad_branch &&
579 git reset --hard HEAD^ &&
580 echo nine >content &&
581 git commit -q -a -m nine &&
583 git checkout -q -b branches/new_branch master &&
584 echo ten >content &&
585 git commit -q -a -m ten
589 test_expect_success 'remote big push' '
590 test_when_finished "rm -rf hgrepo gitrepo*" &&
592 setup_big_push
595 cd gitrepo &&
597 check_push 1 --all <<-\EOF
598 master
599 good_bmark
600 branches/good_branch
601 new_bmark:new
602 branches/new_branch:new
603 bad_bmark1:non-fast-forward
604 bad_bmark2:non-fast-forward
605 branches/bad_branch:non-fast-forward
607 ) &&
609 check_branch hgrepo default one &&
610 check_branch hgrepo good_branch "good branch" &&
611 check_branch hgrepo bad_branch "bad branch" &&
612 check_branch hgrepo new_branch '' &&
613 check_bookmark hgrepo good_bmark one &&
614 check_bookmark hgrepo bad_bmark1 one &&
615 check_bookmark hgrepo bad_bmark2 one &&
616 check_bookmark hgrepo new_bmark ''
619 test_expect_success 'remote big push fetch first' '
620 test_when_finished "rm -rf hgrepo gitrepo*" &&
623 hg init hgrepo &&
624 cd hgrepo &&
625 echo zero >content &&
626 hg add content &&
627 hg commit -m zero &&
628 hg bookmark bad_bmark &&
629 hg bookmark good_bmark &&
630 hg bookmark -i good_bmark &&
631 hg -q branch good_branch &&
632 echo "good branch" >content &&
633 hg commit -m "good branch" &&
634 hg -q branch bad_branch &&
635 echo "bad branch" >content &&
636 hg commit -m "bad branch"
637 ) &&
639 git clone "hg::hgrepo" gitrepo &&
642 cd hgrepo &&
643 hg bookmark -f bad_bmark &&
644 echo update_bmark >content &&
645 hg commit -m "update bmark"
646 ) &&
649 cd gitrepo &&
650 echo two >content &&
651 git commit -q -a -m two &&
653 git checkout -q good_bmark &&
654 echo three >content &&
655 git commit -q -a -m three &&
657 git checkout -q bad_bmark &&
658 echo four >content &&
659 git commit -q -a -m four &&
661 git checkout -q branches/bad_branch &&
662 echo five >content &&
663 git commit -q -a -m five &&
665 check_push 1 --all <<-\EOF &&
666 master
667 good_bmark
668 bad_bmark:fetch-first
669 branches/bad_branch:festch-first
672 git fetch &&
674 check_push 1 --all <<-\EOF
675 master
676 good_bmark
677 bad_bmark:non-fast-forward
678 branches/bad_branch:non-fast-forward
683 test_expect_failure 'remote big push force' '
684 test_when_finished "rm -rf hgrepo gitrepo*" &&
686 setup_big_push
689 cd gitrepo &&
691 check_push 0 --force --all <<-\EOF
692 master
693 good_bmark
694 branches/good_branch
695 new_bmark:new
696 branches/new_branch:new
697 bad_bmark1:forced-update
698 bad_bmark2:forced-update
699 branches/bad_branch:forced-update
701 ) &&
703 check_branch hgrepo default six &&
704 check_branch hgrepo good_branch eight &&
705 check_branch hgrepo bad_branch nine &&
706 check_branch hgrepo new_branch ten &&
707 check_bookmark hgrepo good_bmark three &&
708 check_bookmark hgrepo bad_bmark1 four &&
709 check_bookmark hgrepo bad_bmark2 five &&
710 check_bookmark hgrepo new_bmark six
713 test_expect_failure 'remote big push dry-run' '
714 test_when_finished "rm -rf hgrepo gitrepo*" &&
716 setup_big_push
719 cd gitrepo &&
721 check_push 1 --dry-run --all <<-\EOF &&
722 master
723 good_bmark
724 branches/good_branch
725 new_bmark:new
726 branches/new_branch:new
727 bad_bmark1:non-fast-forward
728 bad_bmark2:non-fast-forward
729 branches/bad_branch:non-fast-forward
732 check_push 0 --dry-run master good_bmark new_bmark branches/good_branch branches/new_branch <<-\EOF
733 master
734 good_bmark
735 branches/good_branch
736 new_bmark:new
737 branches/new_branch:new
739 ) &&
741 check_branch hgrepo default one &&
742 check_branch hgrepo good_branch "good branch" &&
743 check_branch hgrepo bad_branch "bad branch" &&
744 check_branch hgrepo new_branch '' &&
745 check_bookmark hgrepo good_bmark one &&
746 check_bookmark hgrepo bad_bmark1 one &&
747 check_bookmark hgrepo bad_bmark2 one &&
748 check_bookmark hgrepo new_bmark ''
751 test_expect_success 'remote double failed push' '
752 test_when_finished "rm -rf hgrepo gitrepo*" &&
755 hg init hgrepo &&
756 cd hgrepo &&
757 echo zero >content &&
758 hg add content &&
759 hg commit -m zero &&
760 echo one >content &&
761 hg commit -m one
762 ) &&
765 git clone "hg::hgrepo" gitrepo &&
766 cd gitrepo &&
767 git reset --hard HEAD^ &&
768 echo two >content &&
769 git commit -a -m two &&
770 test_expect_code 1 git push &&
771 test_expect_code 1 git push
775 test_done