remote-hg: do not fail on invalid bookmarks

Mercurial can have bookmarks pointing to "nullid" (the empty root revision), while Git can not have references to it. When cloning or fetching from a Mercurial repository that has such a bookmark, the import failed because git-remote-hg was not be able to create the corresponding reference. Warn the user about the invalid reference, and do not advertise these bookmarks as head refs, but otherwise continue the import. In particular, we still keep track of the fact that the remote repository has a bookmark of the given name, in case the user wants to modify that bookmark. Also add some test cases for this issue. Reported-by: Antoine Pelisse <apelisse@gmail.com> Signed-off-by: Max Horn <max@quendi.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Max Horn committed Mar 21, 2014 at 12:36 UTC 51be46ec4d0b64c1deb60a4814bcd24b6b478eeb
2 files changed +77 -1
contrib/remote-helpers/git-remote-hg
+4 -1
@@ -641,7 +641,10 @@ def do_list(parser):
641 print "? refs/heads/branches/%s" % gitref(branch)
642
643 for bmark in bmarks:
644 - print "? refs/heads/%s" % gitref(bmark)
644 + if bmarks[bmark].hex() == '0000000000000000000000000000000000000000':
645 + warn("Ignoring invalid bookmark '%s'", bmark)
646 + else:
647 + print "? refs/heads/%s" % gitref(bmark)
648
649 for tag, node in repo.tagslist():
650 if tag == 'tip':
contrib/remote-helpers/test-hg.sh
+73
@@ -691,4 +691,77 @@ test_expect_success 'remote double failed push' '
691 )
692 '
693
694 +test_expect_success 'clone remote with master null bookmark, then push to the bookmark' '
695 + test_when_finished "rm -rf gitrepo* hgrepo*" &&
696 +
697 + hg init hgrepo &&
698 + (
699 + cd hgrepo &&
700 + echo a >a &&
701 + hg add a &&
702 + hg commit -m a &&
703 + hg bookmark -r null master
704 + ) &&
705 +
706 + git clone "hg::hgrepo" gitrepo &&
707 + check gitrepo HEAD a &&
708 + (
709 + cd gitrepo &&
710 + git checkout --quiet -b master &&
711 + echo b >b &&
712 + git add b &&
713 + git commit -m b &&
714 + git push origin master
715 + )
716 +'
717 +
718 +test_expect_success 'clone remote with default null bookmark, then push to the bookmark' '
719 + test_when_finished "rm -rf gitrepo* hgrepo*" &&
720 +
721 + hg init hgrepo &&
722 + (
723 + cd hgrepo &&
724 + echo a >a &&
725 + hg add a &&
726 + hg commit -m a &&
727 + hg bookmark -r null -f default
728 + ) &&
729 +
730 + git clone "hg::hgrepo" gitrepo &&
731 + check gitrepo HEAD a &&
732 + (
733 + cd gitrepo &&
734 + git checkout --quiet -b default &&
735 + echo b >b &&
736 + git add b &&
737 + git commit -m b &&
738 + git push origin default
739 + )
740 +'
741 +
742 +test_expect_success 'clone remote with generic null bookmark, then push to the bookmark' '
743 + test_when_finished "rm -rf gitrepo* hgrepo*" &&
744 +
745 + hg init hgrepo &&
746 + (
747 + cd hgrepo &&
748 + echo a >a &&
749 + hg add a &&
750 + hg commit -m a &&
751 + hg bookmark -r null bmark
752 + ) &&
753 +
754 + git clone "hg::hgrepo" gitrepo &&
755 + check gitrepo HEAD a &&
756 + (
757 + cd gitrepo &&
758 + git checkout --quiet -b bmark &&
759 + git remote -v &&
760 + echo b >b &&
761 + git add b &&
762 + git commit -m b &&
763 + git push origin bmark
764 + )
765 +'
766 +
767 test_done