Reputation: 62178
Is it possible to modify the behavior of a core Mercurial command (e.g. hg commit
or hg status
) by creating an extension?
For example, would it be possible to modify hg commit
to ask the user to enter an issue tracking ID?
I understand that hook scripts could be used, but such scripts are not distributed via hg pull
and need to be configured for every repository used.
Upvotes: 4
Views: 477
Reputation: 78330
Just to note: both extensions and hooks have exactly the same mass-deployment limitations. In both cases you have to induce your internal users to download a piece of software, be it a hook or an extension, and then to enable it in either the hgrc in their homedir or within the repo.
For both hooks and extensions you can distribute the software using any mechanism and can enable them globally in /etc/mercurial/hgrc
Extensions have some advantages over hooks as to how deep they can dig in the mercurial internals, but deployment is identical.
Upvotes: 2
Reputation: 62178
Answering my own question
The Mercurial API provides the extensions.wrapcommand(table, command, wrapper)
method which seems to provide the desired feature.
From the source code:
Wrap the command named `command' in table.
Replace command in the command table with wrapper. The wrapped command will be inserted into the command table specified by the table argument. The wrapper will be called like wrapper(orig, *args, **kwargs) where orig is the original (wrapped) function, and *args, **kwargs are the arguments passed to it.
A couple examples:
Upvotes: 4