3

I've worked with Git to accomplish this before, but require Mercurial for another project. My Git recipe included a post-receive hook that looked like the following:

#!/bin/sh
GIT_WORK_TREE=/home/ec2-user/www
export GIT_WORK_TREE
git checkout -f

Which would refresh my working app directory every time I pushed to the remote repo on my server. I'd then run my app with node-supervisor: supervisor server.js, which would watch for file changes and restart Node following a git push / file change.

My question is what's the best way to accomplish this with Mercurial. I've looked into the changegroup hook as a similar alternative, but I can't find any example hooks. Thanks!


Update: My Implementation

Per answer & comment below, I went with the changegroup hook. Specifically, in myrepo/.hg/hgrc I used:

[hooks]
changegroup = hg update && /path/to/restart/script.sh

I went with a basic shell script to restart Node vs. installing node-supervisor per above, for this project. It looks like this:

#!/bin/sh
echo "Restarting Server" >> /logpath/server.log
sudo pkill -x node
sudo node server.js >> /logpath/server.log &
echo "Changegroup Hook Executed, Server Restarted"
exit 0

I have only one Node process running, so pkill (all) works for me. I'm also running the server.js straight out of my repo directory.

Wes Johnson
  • 3,063
  • 23
  • 32

1 Answers1

2

Try the Hooks part of the Red Bean book. Especially scrolling down to the Hooks Reference portion may be of use, e.g.:

changegroup—after remote changesets added

Amber
  • 507,862
  • 82
  • 626
  • 550
  • 2
    rather than `incoming` use `changegroup`. If someone does a `hg push` that sends 10 changesets the `incoming` hook will be run 10 times, but `changegroup` would be run only once. – Ry4an Brase Mar 12 '12 at 01:40
  • Thanks guys! I've updated my question to reflect my working implementation. – Wes Johnson Mar 12 '12 at 18:30