Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easy, painless way to test new mercurial hooks (that are works in progress)

I'm in the process of writing a mercurial changegroup hook. I don't have everything figured out yet, but the process of trial and error is made more painful by the fact that I have to keep committing and pushing just to test my work in progress.

Is there any way to 'fake' a trigger to execute my changegroup hook with the current status of the repository to be used for it's parameters?

Any help to streamline this process would be very much appreciated. Thanks Nick

like image 340
Nick Jennings Avatar asked Mar 06 '12 18:03

Nick Jennings


1 Answers

I'm afraid there's no built-in debugging capabilities for this. What I do when writing a hook is to setup two local repositories:

$ hg init repo
$ hg clone repo clone

and then configure the changegroup hook in repo. Now go into clone and do

$ echo a > a
$ hg add a
$ hg commit -m 'a file'

to setup clone. Every time I want to check the hook, I run

$ hg push; hg  -R ../repo rollback

inside clone. I keep that in my command line history so that I can just press + Return to execute it again and again. The hg rollback is the key: is effectively cancels the hg push so that I can repeat it again and again.

You will of course need to adjust this as needed for your hook. If the hook checks the committer name, then use hg commit -u someone to set this as needed. If the hook needs more than one changeset in the changegroup, then make two or more commits before pushing — rollback will take care of removing all the pushed changesets. If the hook is run by hgweb, then run

$ hg serve --config 'web.push_ssl=no' --config 'web.allow_push=*'

in one terminal to serve repo while you push to it in another terminal.

like image 113
Martin Geisler Avatar answered Sep 20 '22 16:09

Martin Geisler