Search code examples
gitmercurialhookpre-commit-hookpre-commit

Can I skip mercurial pre-commit hooks like in git?


I want to do something like git commit --no-verify but with mercurial. Are any ways to do it?


Solution

  • As noted in the hg help config documentation:

    ... Multiple hooks can be run for the same action by appending a suffix to the action. Overriding a site-wide hook can be done by changing its value or setting it to an empty string. Hooks can be prioritized by adding a prefix of "priority." to the hook name on a new line and setting the priority. The default priority is 0.

    (emphasis mine). While this refers to "system-wide hooks", it works for in-repository hooks as well:

    $ sed -n '/hooks/,+1p' .hg/hgrc
    [hooks]
    pre-commit = ./foo.sh
    $ cat foo.sh
    #! /bin/sh
    echo foo
    exit 1
    $ hg commit
    foo
    abort: pre-commit hook exited with status 1
    

    Obviously my pre-commit hook is working. Now to defeat it:

    $ hg --config hooks.pre-commit= commit
    nothing changed
    

    (there was nothing to commit; overriding the pre-commit hook worked).

    You will, of course, need to know which specific hook(s) you want to override, since there may be more than one pre-commit hook.