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:
- It’s possible to write them in bash/sh, and python
- 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)
- 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:
|
mkdir repojunk && cd repojunk<br />mkdir main && cd main<br />hg init<br />echo 'yay' > test<br />hg add && hg commit -m "A test"<br /> |
This will set the stage. Then we’ll create our hook:
|
mkdir ../hooks<br />echo 'echo "Triggering from node: $HG_NODE" ' > ../hooks/myhook<br />chmod ug+x ../hooks/myhooks<br />echo '[hooks]' > .hg/hgrc<br />echo 'changegroup = /full/pathto/user/repojunk/hooks/myhook' >> .hg/hgrc<br /> |
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.
|
cd ../<br />hg clone main main-copy<br />cd main-copy<br />echo "New data" >> test<br />hg commit -m "Added more data"<br />hg push<br /> |
/home/rovangju/repojunk/main/.hg/hgrc:
|
[hooks]<br />changegroup = /home/rovangju/repojunk/hooks/myhook |
If your file looks like that with the correct path try:
|
echo "Even more data!" >> test<br />hg commit -m "Added even more data"<br />hg push |
If all goes well you’ll see something like:
|
pushing to /home/rovangju/repojunk/main<br />searching for changes<br />adding changesets<br />adding manifests<br />adding file changes<br />added 1 changesets with 1 changes to 1 files<br /><span style="font-weight: bold; color: rgb(0, 153, 0);">Triggering from node: b1af240419d49095741f2f5e8a1e95170ec02587</span> |
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!