views:

55

answers:

2

How can I configure a Mercurial server to restrict commits to a named branch once it has been closed? I only want the repository administrator to have the ability to reopen the branch.

http://mercurial.selenic.com/wiki/PruningDeadBranches says that closed changesets can be identified by "close=1 in the changeset's extra field". It's not clear how to read a changeset's extra field using the Mercurial API.

+2  A: 

There is an ACL extension that is distributed along with Mercurial. You should be able to specify the frozen branches by denying commit to every one except the administrator. I am not sure if named branches can leverage this facility.

Configuring acls:

[acl.deny.branches] 
frozen-branch = *

[acl.allow.branches]
branch_name = admin
pyfunc
A: 

A server can't restrict commits, but it can refuse to accept pushes that violate constraints. Here's a hook you can put on a server to reject any pushes that have any changesets that are on a closed branch:

#!/bin/sh
for thenode in $(hg log -r $HG_NODE:tip --template '{node}\n') ; do
     if hg branches --closed | grep -q "^$(hg id --branch -r $thenode).*\(closed\)"  ; then
          echo Commits to closed branches are not allowed -- bad changeset $thenode
          exit 1
     fi
done

You'd install that hook like this:

[hooks]
prechangegroup = /path/to/that.sh

There's almost certainly a way to do it using in-python hooks with the API you referenced, but shell hooks work out pretty well too.

Ry4an