Commits

Augie Fackler committed fd7c3cf Merge

Merge with abderrahim.

  • Participants
  • Parent commits 134d59c, 9933f46

Comments (0)

Files changed (5)

 505d7cdca19838bfb270193e0709154a2dad5c19 0.1.0
+77d6c9eb02fb96abb6a933170a912e94e3141f22 0.2.0

File hggit/git_handler.py

-import os, sys, math, urllib, re
+import os, math, urllib, re
 import toposort
 
 from dulwich.errors import HangupException
 from mercurial.node import hex, bin, nullid
 from mercurial import context, util as hgutil
 
-try:
-    from mercurial.error import RepoError
-except ImportError:
-    from mercurial.repo import RepoError
-
 
 class GitHandler(object):
 
             del new_refs['capabilities^{}']
             if not self.local_heads():
                 tip = hex(self.repo.lookup('tip'))
-                bookmarks.bookmark(self.ui, self.repo, 'master', tip)
+                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)
 
             return want
         f, commit = self.git.object_store.add_pack()
         try:
-            return client.fetch_pack(path, determine_wants, graphwalker, f.write, self.ui.status)
-        except HangupException:
-            raise hgutil.Abort("the remote end hung up unexpectedly")
+            try:
+                return client.fetch_pack(path, determine_wants, graphwalker, f.write, self.ui.status)
+            except HangupException:
+                raise hgutil.Abort("the remote end hung up unexpectedly")
         finally:
             commit()
 
 
     def local_heads(self):
         try:
-            bms = bookmarks.parse(self.repo)
+            if getattr(bookmarks, 'parse', None):
+                bms = bookmarks.parse(self.repo)
+            else:
+                bms = self.repo._bookmarks
             return dict([(bm, hex(bms[bm])) for bm in bms])
         except AttributeError: #pragma: no cover
             return {}
 
     def update_hg_bookmarks(self, refs):
         try:
-            bms = bookmarks.parse(self.repo)
+            oldbm = getattr(bookmarks, 'parse', None)
+            if oldbm:
+                bms = bookmarks.parse(self.repo)
+            else:
+                bms = self.repo._bookmarks
             heads = dict([(ref[11:],refs[ref]) for ref in refs
                           if ref.startswith('refs/heads/')])
 
                         # fast forward
                         bms[head] = hgsha
             if heads:
-                bookmarks.write(self.repo, bms)
+                if oldbm:
+                    bookmarks.write(self.repo, bms)
+                else:
+                    self.repo._bookmarks = bms
+                    bookmarks.write(self.repo)
 
         except AttributeError:
             self.ui.warn(_('creating bookmarks failed, do you have'
 
 setup(
     name='hg-git',
-    version='0.1.0',
+    version='0.2.0',
     author='Scott Chacon',
     maintainer='Augie Fackler',
     maintainer_email='durin42@gmail.com',

File tests/test-merge

 
 cd ..
 cd gitrepo2
+echo % git log in repo pushed from hg
 git log master | sed 's/\.\.\.//g'
 git log beta | sed 's/\.\.\.//g'
 

File tests/test-merge.out

 importing Hg objects into Git
 at: 0/4
 creating and sending data
+% git log in repo pushed from hg
 commit 5806851511aaf3bfe813ae3a86c5027165fa9b96
 Merge: e5023f9 9497a4e
 Author: test <test@example.org>