Since I’ve been playing around with Mercurial I thought it would only be fair to write another version of my Hazel gating snippet.

The basic mechanism is the same (parsing the status output) and the code is barely changed:

 1 #!/bin/bash
 2 
 3 cd $(dirname $1)
 4 FILENAME=$(basename $1)
 5 HGSTATUS=$(hg status -c "$FILENAME")
 6 if [ "$HGSTATUS" == "" ]; then
 7   exit 1 # Dirty
 8 else
 9   exit 0 # Clean
10 fi

An important difference to note is that this script checks that the file is clean (through the -c flag on line 5), not that the file is not dirty as the Git version does. This requires the conditional to be reversed as an empty string means that the file has been modified in some way.

As I mentioned previously in my post about branch comparison, I’ve spent some time recently to learn more about Git and Mercurial. This was both to improve my pretty basic Git skills and see why Daniel Jalkut keeps banging on about Mercurial (go to the 28-minute mark).

When I learnt about hooks (Mercurial, Git) I was a little worried they would invalidate the time I’d spent writing the status gating snippet. But while hooks are very handy and powerful, there’s plenty off actions that Hazel is more suited to or more convenient for — this just acts as a nice safety check so it doesn’t step on your toes while you’re working.