Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ignore certain mercurial commands in mercurial hook

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
like image 204
birthofearth Avatar asked Oct 31 '22 02:10

birthofearth


1 Answers

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()
like image 109
Rudi Avatar answered Nov 09 '22 10:11

Rudi