Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

# 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
share|improve this question

closed as off-topic by masegaloeh, kasperd, Hyppy, mdpc, dawud Apr 17 '15 at 22:22

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "Questions on Server Fault must be about managing information technology systems in a business environment. Home and end-user computing questions may be asked on Super User, and questions about development, testing and development tools may be asked on Stack Overflow." – masegaloeh, Hyppy, dawud
  • "Questions should demonstrate reasonable business information technology management practices. Questions that relate to unsupported hardware or software platforms or unmaintained environments may not be suitable for Server Fault - see the help center." – kasperd, mdpc
If this question can be reworded to fit the rules in the help center, please edit the question.

Did you arrive at a solution? – kmarsh Aug 24 '09 at 14:50
The "Also, don't 'hg push --force' because that won't work either." part of your script is not needed. If users do hg push, then Mercurial will abort before anything is pushed and your script is not executed. If they do hg push --force, then your script is executed but so the line is redundant. – Martin Geisler Dec 18 '11 at 10:52
I think most workflows would allow users to push a new head on a feature branch, but only want to prevent users pushing multiple heads to the default branch. For this, replace hg heads -q in the script above with hg heads -q default. – mo. Jun 25 '14 at 14:44
up vote 6 down vote accepted

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.

share|improve this answer
looks like pretxncommit is the place to put this hook, but is there a pre-installed hook for this sort of test (like the acl or bugzilla hooks)? Will I have to create an external hook? If you have any suggestions for testing this, I'm all ears. – user9748 Jul 5 '09 at 18:36

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

share|improve this answer

Consider putting the repository on an access-controlled server, and then implementing mercurial-server (formerly known as hg-admin-tools). Users push through SSH (from Windows or Linux) and are subject to your access controls.

There are two permissions files that will give you fine-grained control over who can read versus push. Multiple repositories can be set up under one management system, so you don't have to install it over and over again.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.