Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial Changegroup hook varies based on branches

Is there an existing hook in Mercurial which, like changegroup, allows actions to take place on a push, but allows me to do multiple actions (or vary them) based on which branches are affected by the changesets therein?

For example, I need to notify a listener at an url when a push is made but ideally it would notify different urls based on which branch is affected without just blanketing them all.

like image 355
ziklagx Avatar asked Jan 22 '11 00:01

ziklagx


1 Answers

There are no branch-specfic hooks, but you can do that logic in the hook itself. For example in your hgrc:

[hooks]
changeset = actions-by-branch.sh

and then in your actions-by-branch.sh you'd do:

#!/bin/bash
BRANCH=$(hg log --template '{branch}' -r $HG_NODE)
BRANCH=${BRANCH:-default}  # set value to 'default' if it was empty

if [ "$BRANCH" == "default" ] ; then
   do something
elif [ "$BRANCH" == "release" ] ; then
   do something else
else
   do a different thing
fi

Notice that I used a changeset rather than changegroup hook. A single changegroup can have changesets on multiple branches, which would complicate the logic. If you do decide to go that route you need to loop from $HG_NODE all the way to tip to act on each changeset in the changegroup.

like image 163
Ry4an Brase Avatar answered Oct 02 '22 02:10

Ry4an Brase