Skip to content
Snippets Groups Projects
Commit a507384308b2 authored by Sverre Rabbelier's avatar Sverre Rabbelier
Browse files

Allow bookmarking a specific branch

This way 'hg gimport' can be used to import a git head as bookmark
into hg without having to push that head to a git remote first.
parent 6db38267e2e8
No related branches found
No related tags found
No related merge requests found
......@@ -59,6 +59,7 @@
self.importbranch = ui.config('git', 'importbranch')
self.exportbranch = ui.config('git', 'exportbranch', 'refs/heads/master')
self.bookbranch = ui.config('git', 'bookbranch', '')
self.init_if_missing()
self.load_git()
......@@ -532,9 +533,8 @@
else:
self.pseudo_import_git_commit(commit)
if remote_name:
self.update_hg_bookmarks(remote_name)
self.update_hg_bookmarks(remote_name)
def update_hg_bookmarks(self, remote_name):
try:
bms = bookmarks.parse(self.repo)
......@@ -537,7 +537,18 @@
def update_hg_bookmarks(self, remote_name):
try:
bms = bookmarks.parse(self.repo)
for head, sha in self.git.remote_refs(remote_name).iteritems():
if remote_name:
heads = self.git.remote_refs(remote_name)
else:
branches = self.bookbranch.split(',')
heads = dict((i, self.git.ref(i.strip())) for i in branches)
base_name = (remote_name + '/') if remote_name else ''
for head, sha in heads.iteritems():
if not sha:
self.ui.warn(_("Could not resolve head %s.\n") % head)
continue
hgsha = hex_to_sha(self.map_hg_get(sha))
if not head == 'HEAD':
......@@ -542,7 +553,8 @@
hgsha = hex_to_sha(self.map_hg_get(sha))
if not head == 'HEAD':
bms[remote_name + '/' + head] = hgsha
bookmarks.write(self.repo, bms)
bms[base_name + head] = hgsha
if heads:
bookmarks.write(self.repo, bms)
except AttributeError:
self.ui.warn(_('creating bookmarks failed, do you have'
' bookmarks enabled?\n'))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment