I'm trying to modify this Mercurial extension to prompt the user to add a FogBugz case number to their commit message. Ideally, I'd like the user to just type in a number after being prompted and have it automatically appended to the commit message.
Here's what I've got so far:
def pretxncommit(ui, repo, **kwargs):
tip = repo.changectx(repo.changelog.tip())
if not RE_CASE.search(tip.description()) and len(tip.parents()) < 2:
casenumResponse = ui.prompt('*** Please specify a case number, x to abort, or hit enter to ignore:', '')
casenum = RE_CASENUM.search(casenumResponse)
if casenum:
# this doesn't work!
# tip.description(tip.description() + ' (Case ' + casenum.group(0) + ')')
return True
elif (casenumResponse == 'x'):
ui.warn('*** User aborted\n')
return True
return True
return False
What I haven't been able to find is a way to edit the commit message. tip.description
appears to be readonly, and I haven't seen anything in the documentation or examples that would let me modify it. The only references I've seen to editing commit messages have to do with patches and the Mq extension, and it doesn't seem like that can help here.
Any ideas as to how I could set the commit message?
I didn't end up finding a way using a hook, but I was able to do it using
extensions.wrapcommand
and modifying the options.I've included the source of the resulting extension here.
Upon detecting the lack of a case in the commit message, my version prompts the user to either enter one, ignore the warning, or abort the commit.
If the user responds to the prompt by specifying a case number, it is appended to the existing commit message.
If the user responds with 'x', the commit is aborted and the changes remain outstanding.
If the user response by just hitting enter, the commit proceeds with the original caseless commit message.
I've also added the nofb option, which skips the prompt if a user is purposefully making a commit with no case number.
Here is the extension:
To use this extension, copy the source into a file named
fogbugzreminder.py
. Then in your Mercurial.ini file (or hgrc, whatever your preference is), add the following line to the[extensions]
section: