Search code examples
mercurialmercurial-hook

How can I create a mercurial hook that prevents new heads?


I have several repositories that have been converted from SVN and moving forward we want make sure when people push to the repository they can't create additional heads. there are several hooks in the TipsAndTricks wiki page that prevent pushing if there are multiple heads, but how I can build a hook that prevents pushing new heads?

It seems like the right way to do this would be to compare the number of heads from revision 0:parent and then compare 0:tip, but I can't seem to find a way to do that. hg heads -r $HG_NODE only shows me the number of heads after the user's first commit being pushed.


Solution

  • Use hg ci -m 'Closed branch feature-x' --close-branch to close all but one head and then apply a normal single-head hook.