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

2

16

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

Musk answered 6/3, 2012 at 18:47 Comment(0)
F
18

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.

Falls answered 6/3, 2012 at 23:11 Comment(1)
Thanks, that's simplifying the way I was going about it in several ways! :)Musk
K
6

I've recently been writing a python hook for Mercurial using the API. To test it, I did the following, after launching the python interpreter inside the repository folder.

from mercurial import ui, hg
repo = hg.repository(ui.ui(), '.')
execfile('./myhook.py')
myhook(repo.ui, repo, 'hash', 'outgoing')

Where myhook is your hook function (located in myhook.py), hash is the hash of the changeset you want to test your hook with, and outgoing is the hook type.

If your hook doesn't behave as expected you can modify your script and execute the last two lines again to retry.

Kinesiology answered 2/4, 2012 at 18:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.