Question

I need the equivalent of git post-receive hook in Mercurial so I can notify another service that a push has been done to the repository.

What I need in my hook is simple: changeset revision of the last changeset.

Of course I understand that the difference with git is that the ref won't be named, and there can be multiple heads pushed to the repository. I might be OK with that.

What I don't want for the moment, is the behavior of my current implementation using hg incoming hook: I have the revision of every pushed changeset.

Then, to sum up, what is hg best way to be notified of the last pushed commit to a repository ?

EDIT: The goal is to notify another service to pull from the repository because new code has arrived. But I don't want the service to pull for every changeset in the push

Was it helpful?

Solution

Basically, it sounds like you want to use the changegroup hook. It is like the incoming hook, but only fires once for bundles of changes. It provides you with the ID of the first new changeset in $HG_NODE though, I’m not sure if that suits you.

See: http://www.selenic.com/mercurial/hgrc.5.html#hooks

It is a bit unclear to me which changeset you mean exactly by the ‘last’ changeset. As changesets may be added to multiple heads at once, the last changeset could be on any branch, so it’s not very useful information for say, updating.

If you want to identify which changesets were new since the last push, having the first changeset should suit you just as well if not better (as it allows you to identify new changesets without knowledge of the previous push).

However if you really want to know the ID of the last changeset, you can invoke the following command from the hook: hg tip --template "{node}". See hg help tip for more information.

If you provide some background on what you want to use this information for precisely, then I can give a more clear suggestion on how to best handle that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top