繼馬丁·蓋斯勒的答案,this post,這裏是在Windows上運行的掛鉤:
在hgrc
:
[hooks]
precommit.bookmark = python:/path/to/hg-hooks.py:prefix_commit_message
和hg-hooks.py
:
import sys, mercurial
## to be accepted in TortoiseHg, see http://tortoisehg.bitbucket.io/manual/2.9/faq.html
sys.path.append(r'C:\Python27\Lib\site-packages')
import hglib
def _get_active_bookmark(path):
'''Return the active bookmark or None.
'''
client = hglib.open(path)
bookmarks, active = client.bookmarks()
if active == -1:
return None
else:
return bookmarks[active][0]
###
### Available hooks
###
def prefix_commit_message(ui, repo, **kwargs):
'''Prepend [active bookmark name] to commit message.
'''
commitctx = repo.commitctx
def rewrite_ctx(ctx, error):
book = _get_active_bookmark(repo.root)
if book:
old_text = ctx._text
if not old_text.lstrip().startswith("["):
ctx._text = "[" + book + "] "+ old_text
return commitctx(ctx, error)
repo.commitctx = rewrite_ctx
謝謝,但我只是檢查,如果有兩個書籤,改變活動一個不會改變'汞ID -B'的輸出。 – Shadok