Stopping pushers from breaking my central Mercurial repository [closed]

I'm running the central mercurial repository, and I understand that the normal "push" command will stop if the remote user is trying to force multiple "head"s to my central repository. The intention is that the remote user should first pull and merge before trying to push again.

However, using hg push --force will override this. I would like to block this behavior.

I am currently using the hgwebdir.cgi plus some apache-auth stuff to limit users ability to pull and push.

EDIT: a pretxnchangegroup hook solved the problem. Hook worked:

#!/bin/bash
# force-one-head
# add the following to <repository>/.hg/hgrc :
# [hooks]
# pretxnchangegroup.forceonehead = /path/to/force-one-head

if [[ `hg heads -q | wc -l` -gt 1 ]]; then
    echo "There are multiple heads."
    echo "Please 'hg pull' and get your repository up to date first."
    echo "Also, don't 'hg push --force' because that won't work either."
    exit 1
fi

This is not an Apache change, but you have to set it in the Mercurial repository itself.

You can setup hooks that run a script before accepting a push into your repository. In the scripts triggered by the pretxncommit or pretxnchangegroup hooks you can check if those changes create a new head and refuse them if they do.

See the chapter on hooks in the Hg Book for more details.


There is no hook supplied that will create this behavior. You will need to write it yourself.