Tales of an IT Nobody

devbox:~$ iptables -A OUTPUT -j DROP

Mercurial (hg) checkstyle hook, at last! May 7, 2012

As far as I can tell, there’s not much in the lane of check style hooks for Mercurial.

There’s a lot of hits for git and SVN, but not much for Mercurial.

Check it out in my ‘hg-checkstyle-hook‘ bitbucket repo.

I thought I’d share my (imperfect) rendition of a Mercurial checkstyle hook. It’s meant to be setup for a pretxnchangegroup event.

Basically it does this:

  • Find what files have changed from the beginning of the changegroup to the tip
  • Copy those files to a staging directory in /tmp
  • Run PHPCS ( PHP_CodeSniffer, a PHP checkstyle command) on those files specifically
  • Provide a report on any violations resulting in a non 0 exit code.
  • The script should be configurable for any checkstyle command, as long as it takes a space delimited list of files at the end of it’s arguments.
No Comments on Mercurial (hg) checkstyle hook, at last!

The inherent risks of ‘daemonize’ features in developer tools – Git, Mercurial (hg) September 24, 2011

A handful of tools such as mercurial, git, (soon PHP – which chances are will be it’s own binary) have their own ‘daemonize’ functionality.

Whatever your reasons – if you want to disable these; there’s little to no help in figuring out how… til now…

If you want to disable Mercurial’s hg serve:
Open the file (Your python install path may differ, but this should give you an idea of what to search for)


Find the function ‘create-server’ and add ‘sys.exit()’ in the first line:

How to verify this works:

1. Before patching – run ‘hg serve’ from a mercurial repository. It will report the port number and remain active in console.
2. After patching – ‘hg serve’ from a mercurial repository will simply exit and say nothing.
3. netstat, ps -A ux |grep ‘hg serve’

If you want to disable git’s git daemon:
This one is probably the easiest of the two: find and ‘chmod a-x’ (remove execute permissions) from the ‘git-daemon’ binary on your system – mine is in /usr/libexec/git-core. You can also relocate it somewhere in-accessible.

How to verify this works:

1. Before relocating/removing/chmodding – run ‘git daemon’ – your console will remain active as if it’s listening. (You can try a base dir for a proper daemon setup if you want …)
2. After relocating/removing – run ‘git daemon’, you’ll get an error saying there are insufficient privileges, or in the case of relocating/removing you’ll see “not a git command”.
3. netstat, ps -A ux |grep ‘git daemon’

No Comments on The inherent risks of ‘daemonize’ features in developer tools – Git, Mercurial (hg)
Categories: git hg linux security servers

Visualizing changeset activity August 13, 2009

Came across a nifty extension for mercurial that uses google charts to generate graphs revolving around your Hg repository activity. The extension is called ChartExtension – it’s not as configurable as I had hoped but the results are pretty easy to obtain:

(click for larger)

No Comments on Visualizing changeset activity
Categories: hg purdy

Remote hooks with mercurial August 6, 2009

If you use mercurial in a centralized model – it can be a little fiesty to create and troubleshoot your hooks.

You’ll want to make sure you scan over the /hgrc hooks section and the redbook section on hooks

First, a few rule of thumbs:

  1. It’s possible to write them in bash/sh, and python
  2. If bash-style, your script is executed with your user’s shell. No need to put #!/bin/bash on top really (helps in vim though)
  3. Your script must be +x for the user that’s executing it. (Remote push over http/s, your www/apache user must have +x to it)

How to troubleshoot is easy, I start like this, from /home/rovangju:

This will set the stage. Then we’ll create our hook:

Your hook is now good to go!
Now, in order to fire this off we need to emulate a centralized model, so when we push to the main, we’ll fire off our hook.


If your file looks like that with the correct path try:

If all goes well you’ll see something like:

And that’s your starting point for your hook.
I just wanted to throw this out there for myself and others someday if they’re trying to find a better way to troubleshoot why their hook isn’t firing or working.
Also, logger is your friend!

No Comments on Remote hooks with mercurial
Categories: hg linux