I like the Single Head Per Branch hook mentioned above; however, branchtags()
should be replaced with branchmap()
since branchtags() is no longer available. (I couldn't comment on that one so I stuck it down here).
I also like the hook from https://bobhood.wordpress.com/2012/12/14/branch-freezing-with-mercurial/ for Frozen Branches. You add a section in your hgrc like this:
[frozen_branches]
freeze_list = BranchFoo, BranchBar
and add the hook:
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
If anyone attempts to update the frozen branches (e.g., BranchFoo, BranchBar) the transaction will be aborted.