[PATCH next] push: fix traceback when pushing empty hg repo to empty git repo (issue #58)

25 views
Skip to first unread message

David Carr

unread,
Oct 25, 2012, 12:41:15 AM10/25/12
to hg-...@googlegroups.com
# HG changeset patch
# User David M. Carr <da...@carrclan.us>
# Date 1351140035 14400
# Node ID 00a7702d946727187320689b0dbbfcbc042e6c9e
# Parent cac070a4b5219b86d4999722bbe1ca7f34e55697
push: fix traceback when pushing empty hg repo to empty git repo (issue #58)

In the logic that was attempting to handle the case where the local repo doesn't
have any bookmarks, the assumption was being made that tip resolved to a
non-null revision. In the case of a totally empty local repo, however, that
isn't a valid assumption, and resulted in attempting to set the master ref
to None, which broke dulwich.

The "fix", which avoids the traceback and allows the push to complete (though
still do nothing, since in this case there aren't any changes to push), is to
not tweak the refs at all if tip is nullid. Leaving the special capabilities
ref and not adding a master ref appears to be fine in this case.

diff --git a/hggit/git_handler.py b/hggit/git_handler.py
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -887,15 +887,17 @@

#The remote repo is empty and the local one doesn't have bookmarks/tags
if refs.keys()[0] == 'capabilities^{}':
- del new_refs['capabilities^{}']
if not self.local_heads():
- tip = hex(self.repo.lookup('tip'))
- try:
- commands.bookmark(self.ui, self.repo, 'master', tip, force=True)
- except NameError:
- bookmarks.bookmark(self.ui, self.repo, 'master', tip, force=True)
- bookmarks.setcurrent(self.repo, 'master')
- new_refs['refs/heads/master'] = self.map_git_get(tip)
+ tip = self.repo.lookup('tip')
+ if tip != nullid:
+ del new_refs['capabilities^{}']
+ tip = hex(tip)
+ try:
+ commands.bookmark(self.ui, self.repo, 'master', tip, force=True)
+ except NameError:
+ bookmarks.bookmark(self.ui, self.repo, 'master', tip, force=True)
+ bookmarks.setcurrent(self.repo, 'master')
+ new_refs['refs/heads/master'] = self.map_git_get(tip)

for rev in revs:
ctx = self.repo[rev]
diff --git a/tests/test-push.t b/tests/test-push.t
--- a/tests/test-push.t
+++ b/tests/test-push.t
@@ -153,3 +153,15 @@
[1]

$ cd ..
+
+Push empty Hg repo to empty Git repo (issue #58)
+Since there aren't any changes, exit code 1 is expected in modern Mercurial.
+However, since it varies between supported Mercurial versions, we need to
+force it to consistency for now. (see issue3228, fixed in Mercurial 2.1)
+ $ hg init hgrepo2
+ $ git init -q --bare gitrepo2
+ $ hg -R hgrepo2 push gitrepo2 && false
+ pushing to gitrepo2
+ searching for changes
+ no changes found
+ [1]

Augie Fackler

unread,
Oct 25, 2012, 9:36:12 AM10/25/12
to hg-...@googlegroups.com
queued, thanks
> --
> You received this message because you are subscribed to the Google Groups "hg-git" group.
> To post to this group, send email to hg-...@googlegroups.com.
> To unsubscribe from this group, send email to hg-git+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/hg-git?hl=en.
>

Reply all
Reply to author
Forward
0 new messages