Prevent multiple heads in default branch for mercurial repositories

Is there proper way to preventing creating new heads in RhodeCode-managed hg repository with:

$ hg push -f

?

Currently I’m using custom hook scripts in .hg/hgrc but is there a better way?

The custom .hg/hgrc is currently the way to go. However please check out this ticket: https://issues.rhodecode.com/issues/4044

We’re going to roll this out together with Branch permissions.

Thanks for the reply, looking forward for integration of this ticket.
It would be could to manage multiple heads block on repository group/global level.

Yes, we’re going to leverage our permissions system on repo groups/repos to add additional rules on branches etc. So it should have all the flexibility that we already have with regular permissions.

we blocked it wholesale with a custom pretxnchangegroup hook:

python:forbid_2heads.py:forbid_2heads
# [hooks]
# pretxnchangegroup.forbid_2heads = python:forbid_2heads.forbid_2heads

from mercurial import ui
from mercurial.i18n import gettext as _

def forbid_2heads(ui, repo, hooktype, node, **kwargs):
    violators = [ branch for (branch, heads) in repo.branchmap().iteritems() if len([head for head in heads if not repo[head].extra().get('close')]) > 1 ]
    if violators:
        ui.warn(_('Trying to push more than one head to %s; did you forget to merge?\n') % violators)
        return True