8

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
user9748
  • 267

3 Answers3

6

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.

Marijn
  • 76
1

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

0

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.

kmarsh
  • 3,133