Adding custom data to commit msg

Greg Ward greg-hg at gerg.ca
Tue Nov 2 02:40:50 UTC 2010


[inapproprate question for mercurial-devel, so I'm redirecting to
mercurial list]

On Mon, Nov 1, 2010 at 10:09 PM, quarterlife <chaim.ackerman at gmail.com> wrote:
> Our developers work in private repos that contain the requirement_id in its
> name.
> I can ask them to always add the requirement_id in their commit messages,
> but it's error prone.
> I'd like to have it automatically prepended into their commit messages, so
> that the requirement can be tracked as it's changesets are pushed to various
> repos.  Is there a way to add a hook to the commit (e.g. pretxncommit) to
> automatically prepend it?  Or is there another approach that will accomplish
> the same thing.

Alas, no: by the time a pretxncommit hook runs, the changeset ID has
been computed, and that's the SHA-1 hash of various data including the
commit message.  All you can do in pretxncommit is accept or reject
the commit.

If you try to do it earlier, in precommit, that runs too early: hg
doesn't necessarily even have the commit message yet.  (If it's going
to run the user's editor, it has not done so.)

AFAIK the only solution here is to write an extension.  The good news
is that extensions give you awesome power over a huge range of
Mercurial's internals; the bad news is that those internals can change
from release to release, forcing you to keep your extension
up-to-date.

Greg



More information about the Mercurial mailing list