--- a/hgext/convert/git.py Sat Jan 24 22:28:14 2015 +0900
+++ b/hgext/convert/git.py Wed Jul 29 13:21:03 2015 -0700
@@ -371,28 +371,31 @@
def getbookmarks(self):
bookmarks = {}
- # Interesting references in git are prefixed
- prefix = 'refs/heads/'
- prefixlen = len(prefix)
+ # Handle local and remote branches
+ remoteprefix = self.ui.config('convert', 'git.remoteprefix', 'remote')
+ reftypes = [
+ # (git prefix, hg prefix)
+ ('refs/remotes/origin/', remoteprefix + '/'),
+ ('refs/heads/', '')
+ ]
- # factor two commands
- remoteprefix = self.ui.config('convert', 'git.remoteprefix', 'remote')
- gitcmd = { remoteprefix + '/': 'git ls-remote --heads origin',
- '': 'git show-ref'}
+ exclude = set([
+ 'refs/remotes/origin/HEAD',
+ ])
- # Origin heads
- for reftype in gitcmd:
- try:
- fh = self.gitopen(gitcmd[reftype], err=subprocess.PIPE)
- for line in fh:
- line = line.strip()
- rev, name = line.split(None, 1)
- if not name.startswith(prefix):
+ try:
+ fh = self.gitopen('git show-ref', err=subprocess.PIPE)
+ for line in fh:
+ line = line.strip()
+ rev, name = line.split(None, 1)
+ # Process each type of branch
+ for gitprefix, hgprefix in reftypes:
+ if not name.startswith(gitprefix) or name in exclude:
continue
- name = '%s%s' % (reftype, name[prefixlen:])
+ name = '%s%s' % (hgprefix, name[len(gitprefix):])
bookmarks[name] = rev
- except Exception:
- pass
+ except Exception:
+ pass
return bookmarks