1

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.

1 Answers1

0

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.

planetmaker
  • 5,884
  • 3
  • 28
  • 37
  • I thought about that, the only question I have here is how will I push changes from "testing" repo to "vetted" repo after my tests pass. Is there any hg related command to get two repos in sync? –  Aug 01 '17 at 18:19
  • What's wrong with using a push executed in the hook which runs the testing? – planetmaker Aug 02 '17 at 09:25
  • I am relatively new on mercurial and it's hooks and don't know how to do that. Can you tell me how to execute a push from python hook. –  Aug 02 '17 at 14:57
  • I guess python-hglib or hgapi packages of python will help me out. –  Aug 03 '17 at 16:32