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=$(dirname $0)/
12 . "$TEST_DIRECTORY"/test-lib.sh
14 if ! test_have_prereq PYTHON
16 skip_all='skipping remote-hg tests; python not available'
20 if ! "$PYTHON_PATH" -c 'import mercurial' > /dev/null 2>&1
22 skip_all='skipping remote-hg tests; mercurial not available'
28 git --git-dir=$1/.git log --format='%s' -1 $2 > actual &&
29 test_cmp expected actual
36 hg -R $1 log -r $2 --template '{desc}\n' > actual &&
37 test_cmp expected actual
39 hg -R $1 branches > out &&
48 hg -R $1 log -r "bookmark('$2')" --template '{desc}\n' > actual &&
49 test_cmp expected actual
51 hg -R $1 bookmarks > out &&
57 git --git-dir=$1/.git ls-files > actual &&
60 printf "%s\n" "$2" > expected
64 test_cmp expected actual
68 expected_ret=$1 ret=0 ref_ret=0
71 git push origin "$@" 2> error
75 while IFS=':' read branch kind
79 grep "^ \* \[new branch\] *${branch} -> ${branch}$" error || ref_ret=1
82 grep "^ ! \[rejected\] *${branch} -> ${branch} (non-fast-forward)$" error || ref_ret=1
85 grep "^ ! \[rejected\] *${branch} -> ${branch} (fetch first)$" error || ref_ret=1
88 grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *${branch} -> ${branch} (forced update)$" error || ref_ret=1
91 grep "^ [a-f0-9]*\.\.[a-f0-9]* *${branch} -> ${branch}$" error || ref_ret=1
94 test $ref_ret -ne 0 && echo "match for '$branch' failed" && break
97 if test $expected_ret -ne $ret || test $ref_ret -ne 0
106 cat > "$HOME"/.hgrc <<-EOF &&
108 username = H G Wells <wells@example.com>
113 GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230" &&
114 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" &&
115 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
120 test_expect_success 'setup' '
124 echo zero > content &&
130 test_expect_success 'cloning' '
131 test_when_finished "rm -rf gitrepo*" &&
132 git clone "hg::hgrepo" gitrepo &&
133 check gitrepo HEAD zero
136 test_expect_success 'cloning with branches' '
137 test_when_finished "rm -rf gitrepo*" &&
142 echo next > content &&
146 git clone "hg::hgrepo" gitrepo &&
147 check gitrepo origin/branches/next next
150 test_expect_success 'cloning with bookmarks' '
151 test_when_finished "rm -rf gitrepo*" &&
155 hg checkout default &&
156 hg bookmark feature-a &&
157 echo feature-a > content &&
158 hg commit -m feature-a
161 git clone "hg::hgrepo" gitrepo &&
162 check gitrepo origin/feature-a feature-a
165 test_expect_success 'update bookmark' '
166 test_when_finished "rm -rf gitrepo*" &&
174 git clone "hg::hgrepo" gitrepo &&
176 git checkout --quiet devel &&
177 echo devel > content &&
178 git commit -a -m devel &&
182 check_bookmark hgrepo devel devel
185 test_expect_success 'new bookmark' '
186 test_when_finished "rm -rf gitrepo*" &&
189 git clone "hg::hgrepo" gitrepo &&
191 git checkout --quiet -b feature-b &&
192 echo feature-b > content &&
193 git commit -a -m feature-b &&
194 git push --quiet origin feature-b
197 check_bookmark hgrepo feature-b feature-b
200 # cleanup previous stuff
204 echo $1 >> content &&
205 hg commit -u "$2" -m "add $1" &&
206 echo "$3" >> ../expected
209 test_expect_success 'authors' '
210 test_when_finished "rm -rf hgrepo gitrepo" &&
220 author_test alpha "" "H G Wells <wells@example.com>" &&
221 author_test beta "beta" "beta <unknown>" &&
222 author_test gamma "gamma <test@example.com> (comment)" "gamma <test@example.com>" &&
223 author_test delta "<delta@example.com>" "Unknown <delta@example.com>" &&
224 author_test epsilon "epsilon<test@example.com>" "epsilon <test@example.com>" &&
225 author_test zeta "zeta <test@example.com" "zeta <test@example.com>" &&
226 author_test eta " eta " "eta <unknown>" &&
227 author_test theta "theta < test@example.com >" "theta <test@example.com>" &&
228 author_test iota "iota >test@example.com>" "iota <test@example.com>" &&
229 author_test kappa "kappa < test <at> example <dot> com>" "kappa <unknown>" &&
230 author_test lambda "lambda@example.com" "Unknown <lambda@example.com>" &&
231 author_test mu "mu.mu@example.com" "Unknown <mu.mu@example.com>"
234 git clone "hg::hgrepo" gitrepo &&
235 git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" > actual &&
237 test_cmp expected actual
240 test_expect_success 'strip' '
241 test_when_finished "rm -rf hgrepo gitrepo" &&
247 echo one >> content &&
251 echo two >> content &&
255 git clone "hg::hgrepo" gitrepo &&
261 echo three >> content &&
262 hg commit -m three &&
264 echo four >> content &&
271 git log --format="%s" origin/master > ../actual
274 hg -R hgrepo log --template "{desc}\n" > expected &&
275 test_cmp actual expected
278 test_expect_success 'remote push with master bookmark' '
279 test_when_finished "rm -rf hgrepo gitrepo*" &&
284 echo zero > content &&
287 hg bookmark master &&
288 echo one > content &&
293 git clone "hg::hgrepo" gitrepo &&
295 echo two > content &&
296 git commit -a -m two &&
300 check_branch hgrepo default two
303 cat > expected <<\EOF
304 changeset: 0:6e2126489d3d
306 user: A U Thor <author@example.com>
307 date: Mon Jan 01 00:00:00 2007 +0230
312 test_expect_success 'remote push from master branch' '
313 test_when_finished "rm -rf hgrepo gitrepo*" &&
320 git remote add origin "hg::../hgrepo" &&
321 echo one > content &&
323 git commit -a -m one &&
324 git push origin master
327 hg -R hgrepo log > actual &&
329 test_cmp expected actual &&
331 check_branch hgrepo default one
334 GIT_REMOTE_HG_TEST_REMOTE=1
335 export GIT_REMOTE_HG_TEST_REMOTE
337 test_expect_success 'remote cloning' '
338 test_when_finished "rm -rf gitrepo*" &&
343 echo zero > content &&
348 git clone "hg::hgrepo" gitrepo &&
349 check gitrepo HEAD zero
352 test_expect_success 'moving remote clone' '
353 test_when_finished "rm -rf gitrepo*" &&
356 git clone "hg::hgrepo" gitrepo &&
357 mv gitrepo gitrepo2 &&
363 test_expect_success 'remote update bookmark' '
364 test_when_finished "rm -rf gitrepo*" &&
372 git clone "hg::hgrepo" gitrepo &&
374 git checkout --quiet devel &&
375 echo devel > content &&
376 git commit -a -m devel &&
380 check_bookmark hgrepo devel devel
383 test_expect_success 'remote new bookmark' '
384 test_when_finished "rm -rf gitrepo*" &&
387 git clone "hg::hgrepo" gitrepo &&
389 git checkout --quiet -b feature-b &&
390 echo feature-b > content &&
391 git commit -a -m feature-b &&
392 git push --quiet origin feature-b
395 check_bookmark hgrepo feature-b feature-b
398 test_expect_success 'remote push diverged' '
399 test_when_finished "rm -rf gitrepo*" &&
401 git clone "hg::hgrepo" gitrepo &&
405 hg checkout default &&
406 echo bump > content &&
412 echo diverge > content &&
413 git commit -a -m diverged &&
415 master:non-fast-forward
419 check_branch hgrepo default bump
422 test_expect_success 'remote update bookmark diverge' '
423 test_when_finished "rm -rf gitrepo*" &&
431 git clone "hg::hgrepo" gitrepo &&
435 echo "bump bookmark" > content &&
436 hg commit -m "bump bookmark"
441 git checkout --quiet diverge &&
442 echo diverge > content &&
443 git commit -a -m diverge &&
449 check_bookmark hgrepo diverge "bump bookmark"
452 test_expect_success 'remote new bookmark multiple branch head' '
453 test_when_finished "rm -rf gitrepo*" &&
456 git clone "hg::hgrepo" gitrepo &&
458 git checkout --quiet -b feature-c HEAD^ &&
459 echo feature-c > content &&
460 git commit -a -m feature-c &&
461 git push --quiet origin feature-c
464 check_bookmark hgrepo feature-c feature-c
467 # cleanup previous stuff
470 test_expect_success 'fetch special filenames' '
471 test_when_finished "rm -rf hgrepo gitrepo && LC_ALL=C" &&
480 echo test >> "æ rø" &&
482 echo test >> "ø~?" &&
484 hg commit -m add-utf-8 &&
485 echo test >> "æ rø" &&
486 hg commit -m test-utf-8 &&
488 hg mv "æ rø" "ø~?" &&
489 hg commit -m hg-mv-utf-8
493 git clone "hg::hgrepo" gitrepo &&
495 git -c core.quotepath=false ls-files > ../actual
497 echo "ø~?" > expected &&
498 test_cmp expected actual
501 test_expect_success 'push special filenames' '
502 test_when_finished "rm -rf hgrepo gitrepo && LC_ALL=C" &&
504 mkdir -p tmp && cd tmp &&
513 echo one >> content &&
519 git clone "hg::hgrepo" gitrepo &&
522 echo test >> "æ rø" &&
524 git commit -m utf-8 &&
531 hg manifest > ../actual
534 printf "content\næ rø\n" > expected &&
535 test_cmp expected actual
542 echo zero > content &&
545 hg bookmark bad_bmark1 &&
546 echo one > content &&
548 hg bookmark bad_bmark2 &&
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"
559 git clone "hg::hgrepo" gitrepo &&
563 echo two > content &&
564 git commit -q -a -m two &&
566 git checkout -q good_bmark &&
567 echo three > content &&
568 git commit -q -a -m three &&
570 git checkout -q bad_bmark1 &&
571 git reset --hard HEAD^ &&
572 echo four > content &&
573 git commit -q -a -m four &&
575 git checkout -q bad_bmark2 &&
576 git reset --hard HEAD^ &&
577 echo five > content &&
578 git commit -q -a -m five &&
580 git checkout -q -b new_bmark master &&
581 echo six > content &&
582 git commit -q -a -m six &&
584 git checkout -q branches/good_branch &&
585 echo seven > content &&
586 git commit -q -a -m seven &&
587 echo eight > content &&
588 git commit -q -a -m eight &&
590 git checkout -q branches/bad_branch &&
591 git reset --hard HEAD^ &&
592 echo nine > content &&
593 git commit -q -a -m nine &&
595 git checkout -q -b branches/new_branch master &&
596 echo ten > content &&
597 git commit -q -a -m ten
601 test_expect_success 'remote big push' '
602 test_when_finished "rm -rf hgrepo gitrepo*" &&
609 check_push 1 --all <<-\EOF
614 branches/new_branch:new
615 bad_bmark1:non-fast-forward
616 bad_bmark2:non-fast-forward
617 branches/bad_branch:non-fast-forward
621 check_branch hgrepo default one &&
622 check_branch hgrepo good_branch "good branch" &&
623 check_branch hgrepo bad_branch "bad branch" &&
624 check_branch hgrepo new_branch '' &&
625 check_bookmark hgrepo good_bmark one &&
626 check_bookmark hgrepo bad_bmark1 one &&
627 check_bookmark hgrepo bad_bmark2 one &&
628 check_bookmark hgrepo new_bmark ''
631 test_expect_success 'remote big push fetch first' '
632 test_when_finished "rm -rf hgrepo gitrepo*" &&
637 echo zero > content &&
640 hg bookmark bad_bmark &&
641 hg bookmark good_bmark &&
642 hg bookmark -i good_bmark &&
643 hg -q branch good_branch &&
644 echo "good branch" > content &&
645 hg commit -m "good branch" &&
646 hg -q branch bad_branch &&
647 echo "bad branch" > content &&
648 hg commit -m "bad branch"
651 git clone "hg::hgrepo" gitrepo &&
655 hg bookmark -f bad_bmark &&
656 echo update_bmark > content &&
657 hg commit -m "update bmark"
662 echo two > content &&
663 git commit -q -a -m two &&
665 git checkout -q good_bmark &&
666 echo three > content &&
667 git commit -q -a -m three &&
669 git checkout -q bad_bmark &&
670 echo four > content &&
671 git commit -q -a -m four &&
673 git checkout -q branches/bad_branch &&
674 echo five > content &&
675 git commit -q -a -m five &&
677 check_push 1 --all <<-\EOF &&
680 bad_bmark:fetch-first
681 branches/bad_branch:festch-first
686 check_push 1 --all <<-\EOF
689 bad_bmark:non-fast-forward
690 branches/bad_branch:non-fast-forward
695 test_expect_success 'remote big push force' '
696 test_when_finished "rm -rf hgrepo gitrepo*" &&
703 check_push 0 --force --all <<-\EOF
708 branches/new_branch:new
709 bad_bmark1:forced-update
710 bad_bmark2:forced-update
711 branches/bad_branch:forced-update
715 check_branch hgrepo default six &&
716 check_branch hgrepo good_branch eight &&
717 check_branch hgrepo bad_branch nine &&
718 check_branch hgrepo new_branch ten &&
719 check_bookmark hgrepo good_bmark three &&
720 check_bookmark hgrepo bad_bmark1 four &&
721 check_bookmark hgrepo bad_bmark2 five &&
722 check_bookmark hgrepo new_bmark six
725 test_expect_success 'remote big push dry-run' '
726 test_when_finished "rm -rf hgrepo gitrepo*" &&
733 check_push 1 --dry-run --all <<-\EOF &&
738 branches/new_branch:new
739 bad_bmark1:non-fast-forward
740 bad_bmark2:non-fast-forward
741 branches/bad_branch:non-fast-forward
744 check_push 0 --dry-run master good_bmark new_bmark branches/good_branch branches/new_branch <<-\EOF
749 branches/new_branch:new
753 check_branch hgrepo default one &&
754 check_branch hgrepo good_branch "good branch" &&
755 check_branch hgrepo bad_branch "bad branch" &&
756 check_branch hgrepo new_branch '' &&
757 check_bookmark hgrepo good_bmark one &&
758 check_bookmark hgrepo bad_bmark1 one &&
759 check_bookmark hgrepo bad_bmark2 one &&
760 check_bookmark hgrepo new_bmark ''
763 test_expect_success 'remote double failed push' '
764 test_when_finished "rm -rf hgrepo gitrepo*" &&
769 echo zero > content &&
772 echo one > content &&
777 git clone "hg::hgrepo" gitrepo &&
779 git reset --hard HEAD^ &&
780 echo two > content &&
781 git commit -a -m two &&
782 test_expect_code 1 git push &&
783 test_expect_code 1 git push
787 test_expect_success 'clone remote with null bookmark, then push' '
788 test_when_finished "rm -rf gitrepo* hgrepo*" &&
796 hg bookmark -r null bookmark
800 git clone "hg::hgrepo" gitrepo &&
801 check gitrepo HEAD a &&
803 git checkout --quiet -b bookmark &&
808 git push origin bookmark
812 test_expect_success 'notes' '
813 test_when_finished "rm -rf hgrepo gitrepo" &&
818 echo one > content &&
821 echo two > content &&
825 git clone "hg::hgrepo" gitrepo &&
826 hg -R hgrepo log --template "{node}\n\n" > expected &&
827 git --git-dir=gitrepo/.git log --pretty="tformat:%N" --notes=hg > actual &&
828 test_cmp expected actual
831 test_expect_failure 'push updates notes' '
832 test_when_finished "rm -rf hgrepo gitrepo" &&
837 echo one > content &&
842 git clone "hg::hgrepo" gitrepo &&
846 echo two > content &&
851 hg -R hgrepo log --template "{node}\n\n" > expected &&
852 git --git-dir=gitrepo/.git log --pretty="tformat:%N" --notes=hg > actual &&
853 test_cmp expected actual
856 test_expect_success 'pull tags' '
857 test_when_finished "rm -rf hgrepo gitrepo" &&
862 echo one > content &&
867 git clone "hg::hgrepo" gitrepo &&
869 (cd hgrepo && hg tag v1.0) &&
870 (cd gitrepo && git pull) &&
872 echo "v1.0" > expected &&
873 git --git-dir=gitrepo/.git tag > actual &&
874 test_cmp expected actual
877 test_expect_success 'push merged named branch' '
878 test_when_finished "rm -rf hgrepo gitrepo" &&
883 echo one > content &&
887 echo two > content &&
890 echo three > content &&
895 git clone "hg::hgrepo" gitrepo &&
897 git merge -m Merge -Xtheirs origin/branches/feature &&
901 cat > expected <<-EOF
907 hg -R hgrepo log --template "{desc}\n" > actual &&
908 test_cmp expected actual
911 test_expect_success 'light tag sets author' '
912 test_when_finished "rm -rf hgrepo gitrepo" &&
917 echo one > content &&
923 git clone "hg::hgrepo" gitrepo &&
929 echo "C O Mitter <committer@example.com>" > expected &&
930 hg -R hgrepo log --template "{author}\n" -r tip > actual &&
931 test_cmp expected actual
934 test_expect_success 'push tag different branch' '
935 test_when_finished "rm -rf hgrepo gitrepo" &&
940 echo one > content &&
944 echo two > content &&
949 git clone "hg::hgrepo" gitrepo &&
952 git checkout branches/feature &&
957 echo feature > expected &&
958 hg -R hgrepo log --template="{branch}\n" -r tip > actual &&
959 test_cmp expected actual
962 test_expect_success 'cloning a removed file works' '
963 test_when_finished "rm -rf hgrepo gitrepo" &&
969 echo test > test_file &&
977 git clone "hg::hgrepo" gitrepo &&
981 test_expect_success 'cloning a file replaced with a directory' '
982 test_when_finished "rm -rf hgrepo gitrepo" &&
988 echo test > dir_or_file &&
989 hg add dir_or_file &&
994 echo test > dir_or_file/test_file &&
995 hg add dir_or_file/test_file &&
999 git clone "hg::hgrepo" gitrepo &&
1000 check_files gitrepo "dir_or_file/test_file"
1003 test_expect_success 'clone replace directory with a file' '
1004 test_when_finished "rm -rf hgrepo gitrepo" &&
1010 mkdir dir_or_file &&
1011 echo test > dir_or_file/test_file &&
1012 hg add dir_or_file/test_file &&
1015 hg rm dir_or_file/test_file &&
1016 echo test > dir_or_file &&
1017 hg add dir_or_file &&
1023 git clone "hg::hgrepo" gitrepo &&
1024 check_files gitrepo "dir_or_file"