Mercurial trick: hooks

It is possible to define hooks in mercurial. Useful for making basic sanity check before committing.

I often forgot some debugging 'print' statements here and there in my Python code. To detect them I simply needed to add in .hg/hgrc:

[hooks]
pretxncommit.check_no_print = ! hg tip -p | egrep '^[+-]\s*print\>'

This will stop the commit if any line starting with 'print' is found in you patch.

I guess there are lots of other useful things we can do with such mechanism! :)