如何编写 hgrc 以便 Mercurial 检测到我的钩子?

发布于 2024-09-25 13:46:09 字数 612 浏览 2 评论 0原文

我已经在文件 commit_hooks.py 中编写了两个函数,我想在任何提交持久化之前运行它们,但我不知道如何编写 hgrc 来检测它们。

函数标题是:

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

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

我尝试使用此“指南”,但是文档对我来说太“手册页”了。以下是一个不起作用的弃儿。

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

更新! 将钩子行重写为:

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

使 Mercurial 检测预提交钩子,但由于某种原因它总是以状态 1 退出。

'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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷路的信 2024-10-02 13:46:09

像这样设置您的 [hooks] 部分:

[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

您使用的 precommit 行的语法用于外部挂钩,因此它将您的 python 文件视为独立的文件脚本(我假设它不是因为您使用进程内挂钩的函数签名)。

您可能需要在您的路径中包含 python 可执行文件(我确实如此)。

有关详细信息,请参阅中的权威指南部分- 进程挂钩;评论里隐藏了一些有用的信息。

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.

别把无礼当个性 2024-10-02 13:46:09

“man pagey”文档有一个关于 python hook 语法的部分:

Python 钩子的语法如下
如下:

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

Python 挂钩在
水星过程。每个钩子都被称为
至少有三个关键字参数:
一个 ui 对象(关键字 ui),一个存储库
对象(关键字存储库)和钩子类型
关键字告诉什么样的钩子
被使用。参数列出为
上面的环境变量已经传递了
作为关键字参数,没有 HG_
前缀和小写名称。

如果 Python 挂钩返回“true”
值或引发异常,这是
被视为失败。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文