忽略水银钩中的某些水银命令 [英] ignore certain mercurial commands in mercurial hook
问题描述
我有一个像这样的鱼钩:
I have a mercurial hook like so:
[hooks]
pretxncommit.myhook = python:path/to/file:myhook
代码如下:
def myhook(ui, repo, **kwargs):
#do some stuff
,但是此挂钩在使用提交逻辑执行其他操作的命令上运行,在我的情况下为hg shelve
.有没有一种方法可以获取用户输入的命令,从而避免在该命令上运行钩子?
but this hook runs on commands that use the commit logic to do something else, in my case hg shelve
. is there a way to get the command that the user has input to avoid running the hook on that command?
也许是这样的:
def myhook(ui, repo, command, **kwargs):
if command is "hg shelve"
return 0
#do some stuff
推荐答案
不幸的是,答案似乎是否定的.我刚刚调试了hg 3.1的钩子机制,关于发出哪个命令的信息不会传播到钩子函数中.我能想到的唯一方法是用调试器api破解某些东西,以从调用堆栈中提取信息.
Unfortunately the answer seems to be no. I just debugged into the hook mechanism of hg 3.1, and the information about which command was issued is not propagated into the hook function. The only way I can think of is to hack something ugly with the debugger api to extract informations from the call stack.
另一种方法是检查sys.argv
,但我担心这也是非常不可靠的(因为它无法检测是否通过
Another hack would be to inspect sys.argv
, but I fear that this is also very unreliable (as it can't detect if something was executed via the Command Server).
顺便说一句,我使用以下代码片段附加了调试器:
BTW I used this snippet to attach a debugger:
def myhook(ui, repo, **kwargs):
print kwargs
from pdb import set_trace
set_trace()
这篇关于忽略水银钩中的某些水银命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!