ignore certain mercurial commands in mercurial hook

谁都会走 提交于 2019-12-07 07:11:18

问题


I have a mercurial hook like so:

[hooks]
pretxncommit.myhook = python:path/to/file:myhook

with the code looking like this:

def myhook(ui, repo, **kwargs):
    #do some stuff

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?

perhaps something like this:

def myhook(ui, repo, command, **kwargs):
      if command is "hg shelve"
           return 0
      #do some stuff

回答1:


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.

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()


来源:https://stackoverflow.com/questions/30648564/ignore-certain-mercurial-commands-in-mercurial-hook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!