How to create pre-push hook in Mercurial

1.1k views Asked by At

Is there a way in mercurial to run a hook before doing a push. For example I'd like to run JSHint over the codebase when I type hg push and abort the push when any errors are found.

I first tried using a pre-commit hook. That worked, but it's a nuisance to wait a few seconds before each commit. Besides, I'd like to sometimes do intermediate commits with possibly broken code.

Reading the docs for hgrc I discovered preoutgoing and pre-outgoing which seemed like the thing I'd like. But these didn't work. The only thing they seem to do is run the hook when I type:

hg outgoing

Not useful for me at all.

1

There are 1 answers

0
Rene Saarsoo On

Found a solution. Posting it here in case somebody else is wondering about the same thing.

Turns out the documentation was just confusing for me. It told:

"pre-<command>"

Run before executing the associated command. The contents of the command line are passed as "$HG_ARGS". Parsed command line arguments are passed as "$HG_PATS" and "$HG_OPTS". These contain string representations of the data internally passed to . "$HG_OPTS" is a dictionary of options (with unspecified options set to their defaults). "$HG_PATS" is a list of arguments. If the hook returns failure, the command doesn't execute and Mercurial returns the failure code.

I thought that the <command> it referred to is one of the hook types like outgoing or commit and I couldn't find a push hook listed there. But turns out the command is just any mercurial command, so I can just use pre-push.

Issue solved :)