Daniel Schaffer
Daniel Schaffer

Reputation: 57852

How do I add a command option to an existing command in a Mercurial extension?

I'm working on an extension which includes a pre-commit hook. I'd like to be able to receive a new option within my hook. However, if I add it using the cmdtable example from the documentation, substituting a reference to the existing commit command, it just overwrites the built-in options. What is the right way to do this?

Upvotes: 1

Views: 84

Answers (1)

Daniel Schaffer
Daniel Schaffer

Reputation: 57852

This is possible by using extensions.wrapcommand:

def commit(originalcommit, ui, repo, **opts):
    return originalcommit(ui, repo, **opts)

def uisetup(ui):    
    entry = extensions.wrapcommand(commands.table, "commit", commit)
    entry[1].append(('', 'newcommitoption', None, ('Description for the new commit option')))

Upvotes: 1

Related Questions