tags:

views:

558

answers:

1

What are some useful Mercurial hooks that you have come across?

A few example hooks are located in the Mercurial book:

I personally don't find these very useful. I would like to see:

  • Reject Multiple Heads
  • Reject Changegroups with merges (useful if you want users to always rebase)
    • Reject Changegroups with merges, unless commit message has special string
  • Automatic links to Fogbugz or TFS (similar to bugzilla hook)
  • Blacklist, would deny pushes that had certain changeset ids. (Useful if you use MQ to pull changes in from other clones)

Please stick to hooks that have either bat and bash, or Python. That way they can be used by both *nix and Windows users.

+4  A: 

My favorite hook for formal repositories is the one that refuses multiple heads. It's great when you've got a continuous integration system that needs a post-merge tip to build automatically.

A few examples are here: http://mercurial.selenic.com/wiki/TipsAndTricks#Prevent%5Fa%5Fpush%5Fthat%5Fwould%5Fcreate%5Fmultiple%5Fheads

I use this version from netbeans:

# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
#
# To forbid pushes which creates two or more headss
#
# [hooks]
# pretxnchangegroup.forbid_2heads = python:forbid2_head.forbid_2heads

from mercurial import ui
from mercurial.i18n import gettext as _

def forbid_2heads(ui, repo, hooktype, node, **kwargs):
    if len(repo.heads()) > 1:
        ui.warn(_('Trying to push more than one head, try run "hg merge" before it.\n'))
        return True
Ry4an