Edit Made this basic hook to prevent branch name & commit message bugID mismatches. https://gist.github.com/2583189
So basically the idea is that th
i think the problem here is that the pretxncommit
hook is executed at a point where you can't really change anything anymore. And you can't really get the commit message at that point either, because it's not set on any context object accessible.
repo['tip'].description()
doesn't refer to the changelog being committed but to old tip already committed, that would be repo[None]
, but as some digging in the source revealed it's not the same context object that's being persisted, so it's no point in changing it.
the only way i could find would be to use an earlier hook - like precommit
- and monkeypatch the commitctx
method of the repository like this:
def precommit_hook(repo, **kwargs):
# keep a copy of repo.commitctx
commitctx = repo.commitctx
def updatectx(ctx, error):
# check if `ctx.branch()` matches ...
# update commit text
ctx._text += " ... additional text"
# call original
return commitctx(ctx, error)
# monkeypatch the commit method
repo.commitctx = updatectx
this way cou can access the context object just before it's committed.