我喜欢上面提到的 Single Head Per Branch hook;但是,branchtags()
应该替换为,branchmap()
因为 branchtags() 不再可用。(我无法评论那个,所以我把它贴在这里)。
我也喜欢来自https://bobhood.wordpress.com/2012/12/14/branch-freezing-with-mercurial/的 Frozen Branches的钩子。您在 hgrc 中添加一个部分,如下所示:
[frozen_branches]
freeze_list = BranchFoo, BranchBar
并添加钩子:
def frozenbranches(ui, repo, **kwargs):
hooktype = kwargs['hooktype']
if hooktype != 'pretxnchangegroup':
ui.warn('frozenbranches: Only "pretxnchangegroup" hooks are supported by this hook\n')
return True
frozen_list = ui.configlist('frozen_branches', 'freeze_list')
if frozen_list is None:
# no frozen branches listed; allow all changes
return False
try:
ctx = repo[kwargs['node']]
start = ctx.rev()
end = len(repo)
for rev in xrange(start, end):
node = repo[rev]
branch = node.branch()
if branch in frozen_list:
ui.warn("abort: %d:%s includes modifications to frozen branch: '%s'!\n" % (rev, node.hex()[:12], branch))
# reject the entire changegroup
return True
except:
e = sys.exc_info()[0]
ui.warn("\nERROR !!!\n%s" % e)
return True
# allow the changegroup
return False
如果有人试图更新冻结的分支(例如,BranchFoo、BranchBar),事务将被中止。