In our hg workflow we use
default as testing branch and
stable as the one that contains stable code. All changes are made in feature-branches that are started from latest
stable. This hook checks if there is a "direct" commit to
stable (they are denied, only merges may change contents of
stable) or that new feature branch has been started from
default (which is denied by conventions too).
Any proposal to make it more "pythonic" (or just better)?
from mercurial import context def check(ui, repo, hooktype, node=None, source=None, **kwargs): for rev in xrange(repo[node].rev(), len(repo)): ctx = context.changectx(repo, rev) parents = ctx.parents() if len(parents) == 1: if ctx.branch() in ['default', 'stable']: ui.warn('!!! You cannot commit directly to %s at %s !!!' % (ctx.branch(), ctx.hex())) return True if parents.branch() == 'default': ui.warn('!!! You cannot start your private branch from default at %s !!!' % (ctx.hex())) return True return False