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'
13 if ! test_have_prereq PYTHON
15 skip_all='skipping remote-hg tests; python not available'
19 if ! "$PYTHON_PATH" -c 'import mercurial' > /dev/null 2>&1
21 skip_all='skipping remote-hg tests; mercurial not available'
27 git --git-dir=$1/.git log --format='%s' -1 $2 > actual &&
28 test_cmp expected actual
35 hg -R $1 log -r $2 --template '{desc}\n' > actual &&
36 test_cmp expected actual
38 hg -R $1 branches > out &&
47 hg -R $1 log -r "bookmark('$2')" --template '{desc}\n' > actual &&
48 test_cmp expected actual
50 hg -R $1 bookmarks > out &&
56 git --git-dir=$1/.git ls-files > actual &&
59 printf "%s\n" "$2" > expected
63 test_cmp expected actual
67 expected_ret=$1 ret=0 ref_ret=0
70 git push origin "$@" 2> error
74 while IFS=':' read branch kind
78 grep "^ \* \[new branch\] *${branch} -> ${branch}$" error || ref_ret=1
81 grep "^ ! \[rejected\] *${branch} -> ${branch} (non-fast-forward)$" error || ref_ret=1
84 grep "^ ! \[rejected\] *${branch} -> ${branch} (fetch first)$" error || ref_ret=1
87 grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *${branch} -> ${branch} (forced update)$" error || ref_ret=1
90 grep "^ [a-f0-9]*\.\.[a-f0-9]* *${branch} -> ${branch}$" error || ref_ret=1
93 test $ref_ret -ne 0 && echo "match for '$branch' failed" && break
96 if test $expected_ret -ne $ret || test $ref_ret -ne 0
105 cat > "$HOME"/.hgrc <<-EOF &&
107 username = H G Wells <wells@example.com>
112 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230" &&
113 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" &&
114 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
119 test_expect_success 'setup' '
123 echo zero > content &&
129 test_expect_success 'cloning' '
130 test_when_finished "rm -rf gitrepo*" &&
131 git clone "hg::hgrepo" gitrepo &&
132 check gitrepo HEAD zero
135 test_expect_success 'cloning with branches' '
136 test_when_finished "rm -rf gitrepo*" &&
141 echo next > content &&
145 git clone "hg::hgrepo" gitrepo &&
146 check gitrepo origin/branches/next next
149 test_expect_success 'cloning with bookmarks' '
150 test_when_finished "rm -rf gitrepo*" &&
154 hg checkout default &&
155 hg bookmark feature-a &&
156 echo feature-a > content &&
157 hg commit -m feature-a
160 git clone "hg::hgrepo" gitrepo &&
161 check gitrepo origin/feature-a feature-a
164 test_expect_success 'update bookmark' '
165 test_when_finished "rm -rf gitrepo*" &&
173 git clone "hg::hgrepo" gitrepo &&
175 git checkout --quiet devel &&
176 echo devel > content &&
177 git commit -a -m devel &&
181 check_bookmark hgrepo devel devel
184 test_expect_success 'new bookmark' '
185 test_when_finished "rm -rf gitrepo*" &&
188 git clone "hg::hgrepo" gitrepo &&
190 git checkout --quiet -b feature-b &&
191 echo feature-b > content &&
192 git commit -a -m feature-b &&
193 git push --quiet origin feature-b
196 check_bookmark hgrepo feature-b feature-b
199 # cleanup previous stuff
203 echo $1 >> content &&
204 hg commit -u "$2" -m "add $1" &&
205 echo "$3" >> ../expected
208 test_expect_success 'authors' '
209 test_when_finished "rm -rf hgrepo gitrepo" &&
219 author_test alpha "" "H G Wells <wells@example.com>" &&
220 author_test beta "beta" "beta <unknown>" &&
221 author_test gamma "gamma <test@example.com> (comment)" "gamma <test@example.com>" &&
222 author_test delta "<delta@example.com>" "Unknown <delta@example.com>" &&
223 author_test epsilon "epsilon<test@example.com>" "epsilon <test@example.com>" &&
224 author_test zeta "zeta <test@example.com" "zeta <test@example.com>" &&
225 author_test eta " eta " "eta <unknown>" &&
226 author_test theta "theta < test@example.com >" "theta <test@example.com>" &&
227 author_test iota "iota >test@example.com>" "iota <test@example.com>" &&
228 author_test kappa "kappa < test <at> example <dot> com>" "kappa <unknown>" &&
229 author_test lambda "lambda@example.com" "Unknown <lambda@example.com>" &&
230 author_test mu "mu.mu@example.com" "Unknown <mu.mu@example.com>"
233 git clone "hg::hgrepo" gitrepo &&
234 git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" > actual &&
236 test_cmp expected actual
239 test_expect_success 'strip' '
240 test_when_finished "rm -rf hgrepo gitrepo" &&
246 echo one >> content &&
250 echo two >> content &&
254 git clone "hg::hgrepo" gitrepo &&
260 echo three >> content &&
261 hg commit -m three &&
263 echo four >> content &&
270 git log --format="%s" origin/master > ../actual
273 hg -R hgrepo log --template "{desc}\n" > expected &&
274 test_cmp actual expected
277 test_expect_success 'remote push with master bookmark' '
278 test_when_finished "rm -rf hgrepo gitrepo*" &&
283 echo zero > content &&
286 hg bookmark master &&
287 echo one > content &&
292 git clone "hg::hgrepo" gitrepo &&
294 echo two > content &&
295 git commit -a -m two &&
299 check_branch hgrepo default two
302 cat > expected <<\EOF
303 changeset: 0:6e2126489d3d
305 user: A U Thor <author@example.com>
306 date: Mon Jan 01 00:00:00 2007 +0230
311 test_expect_success 'remote push from master branch' '
312 test_when_finished "rm -rf hgrepo gitrepo*" &&
319 git remote add origin "hg::../hgrepo" &&
320 echo one > content &&
322 git commit -a -m one &&
323 git push origin master
326 hg -R hgrepo log > actual &&
328 test_cmp expected actual &&
330 check_branch hgrepo default one
333 GIT_REMOTE_HG_TEST_REMOTE=1
334 export GIT_REMOTE_HG_TEST_REMOTE
336 test_expect_success 'remote cloning' '
337 test_when_finished "rm -rf gitrepo*" &&
342 echo zero > content &&
347 git clone "hg::hgrepo" gitrepo &&
348 check gitrepo HEAD zero
351 test_expect_success 'moving remote clone' '
352 test_when_finished "rm -rf gitrepo*" &&
355 git clone "hg::hgrepo" gitrepo &&
356 mv gitrepo gitrepo2 &&
362 test_expect_success 'remote update bookmark' '
363 test_when_finished "rm -rf gitrepo*" &&
371 git clone "hg::hgrepo" gitrepo &&
373 git checkout --quiet devel &&
374 echo devel > content &&
375 git commit -a -m devel &&
379 check_bookmark hgrepo devel devel
382 test_expect_success 'remote new bookmark' '
383 test_when_finished "rm -rf gitrepo*" &&
386 git clone "hg::hgrepo" gitrepo &&
388 git checkout --quiet -b feature-b &&
389 echo feature-b > content &&
390 git commit -a -m feature-b &&
391 git push --quiet origin feature-b
394 check_bookmark hgrepo feature-b feature-b
397 test_expect_success 'remote push diverged' '
398 test_when_finished "rm -rf gitrepo*" &&
400 git clone "hg::hgrepo" gitrepo &&
404 hg checkout default &&
405 echo bump > content &&
411 echo diverge > content &&
412 git commit -a -m diverged &&
414 master:non-fast-forward
418 check_branch hgrepo default bump
421 test_expect_success 'remote update bookmark diverge' '
422 test_when_finished "rm -rf gitrepo*" &&
430 git clone "hg::hgrepo" gitrepo &&
434 echo "bump bookmark" > content &&
435 hg commit -m "bump bookmark"
440 git checkout --quiet diverge &&
441 echo diverge > content &&
442 git commit -a -m diverge &&
448 check_bookmark hgrepo diverge "bump bookmark"
451 test_expect_success 'remote new bookmark multiple branch head' '
452 test_when_finished "rm -rf gitrepo*" &&
455 git clone "hg::hgrepo" gitrepo &&
457 git checkout --quiet -b feature-c HEAD^ &&
458 echo feature-c > content &&
459 git commit -a -m feature-c &&
460 git push --quiet origin feature-c
463 check_bookmark hgrepo feature-c feature-c
466 # cleanup previous stuff
469 test_expect_success 'fetch special filenames' '
470 test_when_finished "rm -rf hgrepo gitrepo && LC_ALL=C" &&
479 echo test >> "æ rø" &&
481 echo test >> "ø~?" &&
483 hg commit -m add-utf-8 &&
484 echo test >> "æ rø" &&
485 hg commit -m test-utf-8 &&
487 hg mv "æ rø" "ø~?" &&
488 hg commit -m hg-mv-utf-8
492 git clone "hg::hgrepo" gitrepo &&
494 git -c core.quotepath=false ls-files > ../actual
496 echo "ø~?" > expected &&
497 test_cmp expected actual
500 test_expect_success 'push special filenames' '
501 test_when_finished "rm -rf hgrepo gitrepo && LC_ALL=C" &&
503 mkdir -p tmp && cd tmp &&
512 echo one >> content &&
518 git clone "hg::hgrepo" gitrepo &&
521 echo test >> "æ rø" &&
523 git commit -m utf-8 &&
530 hg manifest > ../actual
533 printf "content\næ rø\n" > expected &&
534 test_cmp expected actual
541 echo zero > content &&
544 hg bookmark bad_bmark1 &&
545 echo one > content &&
547 hg bookmark bad_bmark2 &&
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"
558 git clone "hg::hgrepo" gitrepo &&
562 echo two > content &&
563 git commit -q -a -m two &&
565 git checkout -q good_bmark &&
566 echo three > content &&
567 git commit -q -a -m three &&
569 git checkout -q bad_bmark1 &&
570 git reset --hard HEAD^ &&
571 echo four > content &&
572 git commit -q -a -m four &&
574 git checkout -q bad_bmark2 &&
575 git reset --hard HEAD^ &&
576 echo five > content &&
577 git commit -q -a -m five &&
579 git checkout -q -b new_bmark master &&
580 echo six > content &&
581 git commit -q -a -m six &&
583 git checkout -q branches/good_branch &&
584 echo seven > content &&
585 git commit -q -a -m seven &&
586 echo eight > content &&
587 git commit -q -a -m eight &&
589 git checkout -q branches/bad_branch &&
590 git reset --hard HEAD^ &&
591 echo nine > content &&
592 git commit -q -a -m nine &&
594 git checkout -q -b branches/new_branch master &&
595 echo ten > content &&
596 git commit -q -a -m ten
600 test_expect_success 'remote big push' '
601 test_when_finished "rm -rf hgrepo gitrepo*" &&
608 check_push 1 --all <<-\EOF
613 branches/new_branch:new
614 bad_bmark1:non-fast-forward
615 bad_bmark2:non-fast-forward
616 branches/bad_branch:non-fast-forward
620 check_branch hgrepo default one &&
621 check_branch hgrepo good_branch "good branch" &&
622 check_branch hgrepo bad_branch "bad branch" &&
623 check_branch hgrepo new_branch '' &&
624 check_bookmark hgrepo good_bmark one &&
625 check_bookmark hgrepo bad_bmark1 one &&
626 check_bookmark hgrepo bad_bmark2 one &&
627 check_bookmark hgrepo new_bmark ''
630 test_expect_success 'remote big push fetch first' '
631 test_when_finished "rm -rf hgrepo gitrepo*" &&
636 echo zero > content &&
639 hg bookmark bad_bmark &&
640 hg bookmark good_bmark &&
641 hg bookmark -i good_bmark &&
642 hg -q branch good_branch &&
643 echo "good branch" > content &&
644 hg commit -m "good branch" &&
645 hg -q branch bad_branch &&
646 echo "bad branch" > content &&
647 hg commit -m "bad branch"
650 git clone "hg::hgrepo" gitrepo &&
654 hg bookmark -f bad_bmark &&
655 echo update_bmark > content &&
656 hg commit -m "update bmark"
661 echo two > content &&
662 git commit -q -a -m two &&
664 git checkout -q good_bmark &&
665 echo three > content &&
666 git commit -q -a -m three &&
668 git checkout -q bad_bmark &&
669 echo four > content &&
670 git commit -q -a -m four &&
672 git checkout -q branches/bad_branch &&
673 echo five > content &&
674 git commit -q -a -m five &&
676 check_push 1 --all <<-\EOF &&
679 bad_bmark:fetch-first
680 branches/bad_branch:festch-first
685 check_push 1 --all <<-\EOF
688 bad_bmark:non-fast-forward
689 branches/bad_branch:non-fast-forward
694 test_expect_success 'remote big push force' '
695 test_when_finished "rm -rf hgrepo gitrepo*" &&
702 check_push 0 --force --all <<-\EOF
707 branches/new_branch:new
708 bad_bmark1:forced-update
709 bad_bmark2:forced-update
710 branches/bad_branch:forced-update
714 check_branch hgrepo default six &&
715 check_branch hgrepo good_branch eight &&
716 check_branch hgrepo bad_branch nine &&
717 check_branch hgrepo new_branch ten &&
718 check_bookmark hgrepo good_bmark three &&
719 check_bookmark hgrepo bad_bmark1 four &&
720 check_bookmark hgrepo bad_bmark2 five &&
721 check_bookmark hgrepo new_bmark six
724 test_expect_success 'remote big push dry-run' '
725 test_when_finished "rm -rf hgrepo gitrepo*" &&
732 check_push 1 --dry-run --all <<-\EOF &&
737 branches/new_branch:new
738 bad_bmark1:non-fast-forward
739 bad_bmark2:non-fast-forward
740 branches/bad_branch:non-fast-forward
743 check_push 0 --dry-run master good_bmark new_bmark branches/good_branch branches/new_branch <<-\EOF
748 branches/new_branch:new
752 check_branch hgrepo default one &&
753 check_branch hgrepo good_branch "good branch" &&
754 check_branch hgrepo bad_branch "bad branch" &&
755 check_branch hgrepo new_branch '' &&
756 check_bookmark hgrepo good_bmark one &&
757 check_bookmark hgrepo bad_bmark1 one &&
758 check_bookmark hgrepo bad_bmark2 one &&
759 check_bookmark hgrepo new_bmark ''
762 test_expect_success 'remote double failed push' '
763 test_when_finished "rm -rf hgrepo gitrepo*" &&
768 echo zero > content &&
771 echo one > content &&
776 git clone "hg::hgrepo" gitrepo &&
778 git reset --hard HEAD^ &&
779 echo two > content &&
780 git commit -a -m two &&
781 test_expect_code 1 git push &&
782 test_expect_code 1 git push
786 test_expect_success 'clone remote with null bookmark, then push' '
787 test_when_finished "rm -rf gitrepo* hgrepo*" &&
795 hg bookmark -r null bookmark
799 git clone "hg::hgrepo" gitrepo &&
800 check gitrepo HEAD a &&
802 git checkout --quiet -b bookmark &&
807 git push origin bookmark
811 test_expect_success 'notes' '
812 test_when_finished "rm -rf hgrepo gitrepo" &&
817 echo one > content &&
820 echo two > content &&
824 git clone "hg::hgrepo" gitrepo &&
825 hg -R hgrepo log --template "{node}\n\n" > expected &&
826 git --git-dir=gitrepo/.git log --pretty="tformat:%N" --notes=hg > actual &&
827 test_cmp expected actual
830 test_expect_failure 'push updates notes' '
831 test_when_finished "rm -rf hgrepo gitrepo" &&
836 echo one > content &&
841 git clone "hg::hgrepo" gitrepo &&
845 echo two > content &&
850 hg -R hgrepo log --template "{node}\n\n" > expected &&
851 git --git-dir=gitrepo/.git log --pretty="tformat:%N" --notes=hg > actual &&
852 test_cmp expected actual
855 test_expect_success 'pull tags' '
856 test_when_finished "rm -rf hgrepo gitrepo" &&
861 echo one > content &&
866 git clone "hg::hgrepo" gitrepo &&
868 (cd hgrepo && hg tag v1.0) &&
869 (cd gitrepo && git pull) &&
871 echo "v1.0" > expected &&
872 git --git-dir=gitrepo/.git tag > actual &&
873 test_cmp expected actual
876 test_expect_success 'push merged named branch' '
877 test_when_finished "rm -rf hgrepo gitrepo" &&
882 echo one > content &&
886 echo two > content &&
889 echo three > content &&
894 git clone "hg::hgrepo" gitrepo &&
896 git merge -m Merge -Xtheirs origin/branches/feature &&
900 cat > expected <<-EOF
906 hg -R hgrepo log --template "{desc}\n" > actual &&
907 test_cmp expected actual
910 test_expect_success 'light tag sets author' '
911 test_when_finished "rm -rf hgrepo gitrepo" &&
916 echo one > content &&
922 git clone "hg::hgrepo" gitrepo &&
928 echo "C O Mitter <committer@example.com>" > expected &&
929 hg -R hgrepo log --template "{author}\n" -r tip > actual &&
930 test_cmp expected actual
933 test_expect_success 'push tag different branch' '
934 test_when_finished "rm -rf hgrepo gitrepo" &&
939 echo one > content &&
943 echo two > content &&
948 git clone "hg::hgrepo" gitrepo &&
951 git checkout branches/feature &&
956 echo feature > expected &&
957 hg -R hgrepo log --template="{branch}\n" -r tip > actual &&
958 test_cmp expected actual
961 test_expect_success 'cloning a removed file works' '
962 test_when_finished "rm -rf hgrepo gitrepo" &&
968 echo test > test_file &&
976 git clone "hg::hgrepo" gitrepo &&
980 test_expect_success 'cloning a file replaced with a directory' '
981 test_when_finished "rm -rf hgrepo gitrepo" &&
987 echo test > dir_or_file &&
988 hg add dir_or_file &&
993 echo test > dir_or_file/test_file &&
994 hg add dir_or_file/test_file &&
998 git clone "hg::hgrepo" gitrepo &&
999 check_files gitrepo "dir_or_file/test_file"
1002 test_expect_success 'clone replace directory with a file' '
1003 test_when_finished "rm -rf hgrepo gitrepo" &&
1009 mkdir dir_or_file &&
1010 echo test > dir_or_file/test_file &&
1011 hg add dir_or_file/test_file &&
1014 hg rm dir_or_file/test_file &&
1015 echo test > dir_or_file &&
1016 hg add dir_or_file &&
1022 git clone "hg::hgrepo" gitrepo &&
1023 check_files gitrepo "dir_or_file"