开发者

How do I write my hgrc so that Mercurial detects my hooks?

've written two functions in a file commit_hooks.py that I want to run before any commit is made persistent, but I can't figure out how to write my hgrc to detect them.

The function headers are:

def precommit_bad_merge(ui, repo, parent1=None, parent2=None, **kwargs):
...

def precommit_bad_branching(ui, repo, **kwargs):
...

I've tried using this "guide", but the documentation is too "man pagey" for me. The following is an outcast which doesn't work.

[hooks]
precommit = ..\..\mno2\commit_hooks.py

Update! Rewriting the hook line to:

precommit = D:\environments\next\mno2\commit_hooks.py

make Mercurial detect the precommit hook, but 开发者_运维技巧it always exits with status 1 for some reason.


Set up your [hooks] section like this:

[hooks]
precommit.foo = python:D:\environments\next\mno2\commit_hooks.py:precommit_bad_merge
precommit.bar = python:D:\environments\next\mno2\commit_hooks.py:precommit_bad_branching

The syntax for the precommit line that you used is for external hooks, so it was treating your python file as a self-contained script (which I'm assuming it's not since you're using the function signatures for in-process hooks).

You may need to have the python executable in your path (I do).

For more information, see the definitive guide's section on in-process hooks; there's some useful information hidden in the comments.


The "man pagey" documentation has a section on python hook syntax:

The syntax for Python hooks is as follows:

hookname = python:modulename.submodule.callable
hookname = python:/path/to/python/module.py:callable

Python hooks are run within the Mercurial process. Each hook is called with at least three keyword arguments: a ui object (keyword ui), a repository object (keyword repo), and a hooktype keyword that tells what kind of hook is used. Arguments listed as environment variables above are passed as keyword arguments, with no HG_ prefix, and names in lower case.

If a Python hook returns a "true" value or raises an exception, this is treated as a failure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜