On my computer I have some Mercurial commit hooks that run on every commit that make sure I branch correctly and do a few other things. But I only need these for work projects.
Here are the hooks implemented in my ~/.hgrc file:
[hooks]
# This hook will warn you if you make a commit directly to trunk.
pretxncommit.default_check=/virtualhosts/mercurial-hooks/default_check.sh
# This hook will warn you if you branch from something other than default.
pretxncommit.branch_check=/virtualhosts/mercurial-hooks/branch_check.sh
For my personal projects I don't want to use the same, annoying hooks (which are set to global). I would like all of the repos I checkout from bitbucket to not use those hooks. How can I set it up to do this?
Create a file called from_bitbucket.sh
that contains the following:
#!/bin/sh
test -f $HG_PENDING/.hg/hgrc || exit 1
egrep -q 'default.*bitbucket\.org' $HG_PENDING/.hg/hgrc || exit 1
exit 0
Give the script execute permission (e.g., chmod 755 from_bitbucket.sh
) and move it to whatever directory you want to keep it in permanently.
Change your hooks to something like:
pretxncommit.default_check=/path/to/from_bitbucket.sh || /virtualhosts/mercurial-hooks/default_check.sh
This will first execute from_bitbucket.sh
and abort early with success if the script succeeds. The script checks only if there's a line matching default.*bitbucket\.org
in your repository's .hg/hgrc
file (which should generally exist in the [paths]
section if you push to/pull from bitbucket). It will fail if there's no .hg/hgrc
or if the file doesn't contain a matching line.