diff hggit/git_handler.py @ 555:06a29fdd52a7

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.
author David M. Carr <david@carrclan.us>
date Thu, 25 Oct 2012 00:40:35 -0400
parents f3f344aac42b
children 4f4ab2d89375
line wrap: on
line diff
--- a/hggit/git_handler.py	Wed Oct 17 10:59:42 2012 -0500
+++ b/hggit/git_handler.py	Thu Oct 25 00:40:35 2012 -0400
@@ -885,15 +885,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]