Mercurial hook that operates like 'changegroup', but only on push?
Asked Answered
V

2

4

We've built a changeset propagation mechanism, but it relies on bundling and unbundling the new changesets. If we were to use the changegroup hook, then it would cause cyclic behaviors, because the hook is run during a pull, push, or unbundle. What we need is for the sync to be done after a commit, which the commit hook works perfectly for, but also after a push.

Note, the post-push hook is not the answer, as it is run when you push from that repository to another. This scenario calls, basically, for a special behavior of changegroup, only running when the new changesets are a result of a push.

Is there any hook that works that way?

Voidance answered 18/1, 2012 at 23:3 Comment(0)
S
3

Check the source argument to the hook. It will be bundle when you're unbundling a changegroup, serve when the changeset comes in over HTTP(S) or SSH, and push when it comes in via a push done to a repository on the local file system.

You find this argument as the HG_SOURCE environment variable for a hook run as an external process, and as the source keyword argument for an in-process hook.

Stalnaker answered 18/1, 2012 at 23:13 Comment(2)
Thanks for your answer. I have, in fact, written a small Python script that does just that. The dilemma that I'm facing, however, is that our development team uses Windows systems, and I'm hesitant about insisting that we install Python on all servers. Could I write a .bat file or something that can run without external dependencies?Voidance
Upon further experimentation, it seems that TortoiseHG comes with Python embedded (duh), and runs hooks using its internal Python runtime - so you don't have to use a .bat file.Voidance
V
2

For the sake of completeness, here is a script that would work (as per @MartinGeisler's answer). Let's call it pushhook.py:

def pushhook(ui, repo, source=None, **kwargs):
    if source == 'push':
        # Perform push-only operations here

And the hgrc looks like:

[hooks]
changegroup.push = python:.hg/pushhook.py:pushhook
Voidance answered 19/6, 2012 at 16:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.