Skip to content

Commit 51be46e

Browse files
fingolfingitster
authored andcommitted
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 <[email protected]> Signed-off-by: Max Horn <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d2446df commit 51be46e

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

contrib/remote-helpers/git-remote-hg

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,10 @@ def do_list(parser):
641641
print "? refs/heads/branches/%s" % gitref(branch)
642642

643643
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)
645648

646649
for tag, node in repo.tagslist():
647650
if tag == 'tip':

contrib/remote-helpers/test-hg.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,4 +691,77 @@ test_expect_success 'remote double failed push' '
691691
)
692692
'
693693

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+
694767
test_done

0 commit comments

Comments
 (0)