如何编写 hgrc 以便 Mercurial 检测到我的钩子?
我已经在文件 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样设置您的
[hooks]
部分:您使用的
precommit
行的语法用于外部挂钩,因此它将您的 python 文件视为独立的文件脚本(我假设它不是因为您使用进程内挂钩的函数签名)。您可能需要在您的路径中包含 python 可执行文件(我确实如此)。
有关详细信息,请参阅中的权威指南部分- 进程挂钩;评论里隐藏了一些有用的信息。
Set up your
[hooks]
section like this: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.
“man pagey”文档有一个关于 python hook 语法的部分:
The "man pagey" documentation has a section on python hook syntax: