Search code examples
mercurialmercurial-hook

Mercurial: Redirect an incoming push to a separate repo


I am looking for some solution where a push made to a branch in production server is redirected to some other mercurial server. I can then trigger a hook, run some basic tests and send the changes back to the production server only if my tests pass.

How do I redirect incoming changes to another mercurial server? How do I merge them back to the production server?

So far I have looked into pretxnchangegroup.HOOK_NAME, pre-HOOK_NAME, incoming-HOOK_NAME, but I haven't got far using them.


Solution

  • Redirecting might be difficult and probably needs doing at the proxy level or similar - iirc you cannot do that with a hook... yet there might be a similar solutions to what you try to achieve:

    Have people PULL from one repository (let's call it 'vetted') Have people PUSH to another repository (let's call it 'testing')

    Thus on the 'testing'-repository accept changes from your contributors as long as they are draft phase. Make it a non-publishing repository and work with hooks:

    • Use a pretxnchangegroup hook to quickly test the incoming changes for sanity (e.g. that they confirm to coding style and commit message style, and maybe that incoming changes are draft phase)

    • Use a changegroup hook (thus when the changesets are already accept Have your CI run all the tests on incoming changesets via the changegroup hook (not the pretxnchangegroup as you want the push to succeed and not hang till all build tests are done). Notify the commiter of the result. If the tests are successful, then you might use this hook to push the successfully tested changesets to your 'vetted' repository and otherwise prune the changesets which failed your build tests from the 'testing' repo.