unable to return a failure from a hook

Haszlakiewicz, Eric EHASZLA at transunion.com
Mon Jan 17 10:32:10 CST 2011


>-----Original Message-----
>From: Wagner Bruna [mailto:wagner.bruna+mercurial at gmail.com]
>On 01/14/2011 08:22 PM, Haszlakiewicz, Eric wrote:
>> I'm trying to write a hook that causes a commit to fail
>> based on some custom checks.  I can get most of the stuff
>> I was to do to work, but the basic step of causing a
>> failure to happen doesn't work.
>> Based on what I see on the HookExamples on the wiki, I
>> expect that I should be able to do this:
>>
>>> cat example.py   (actually in Library.zip)
>>
>> def hook(ui, repo, hooktype, **kwargs):
>>         print "returning false";
>>         return False
>>
>>> grep -B 2 example mercurial.ini
>> [hooks]
>> pretxncommit.example = python:example.hook
>>
>> But instead, hg ignores the return value, and commits the change:
>
>The hook function must actually return True (or throw an exception)
>for failure - for consistency with return codes of program hooks, I guess.

Ah, of course.  Thanks.

Next question: I see many hook examples that just have ui, repo, **kwargs, but when I tried just that I got an error from python saying that I didn't have enough parameters.  
Is this a recent API change, or are there some hooks that don't take the extra hooktype parameter?

eric


More information about the Mercurial mailing list