How to show hook output in Tortoise Hg log window?
I got it to work by making it an in-process hook rather than an external hook. In-process hooks are defined quite differently, however.
First, the python file needs only a single function that will be called by the name in the hook definition. The hook function is passed ui
, repo
, and hooktype
objects. It is also passed additional objects based on the type of hook. For pretrxncommit
, it is passed node
, parent1
, and parent2
, but you're only interested in node, so the rest are gathered in kwargs
. The ui
object is used to give the status and error messages.
Contents of check_comment.py
:
#!/usr/bin/env python
import re
def check_comment(ui, repo, hooktype, node=None, **kwargs):
ui.status('Checking comment...\n')
comment = repo[node].description()
pattern = '^((Issue \d+:)|(No Issue:)).+'
if not re.match(pattern, comment, flags=re.IGNORECASE):
ui.warn('Comment does not match pattern. You must start it with "Issue 12323:" or "No Issue:"\n')
return True
In the hgrc
, the hook would be defined with python:/path/to/file.py:function_name
, like this:
[hooks]
pretxncommit.check_comment = python:/path/to/check_comment.py:check_comment
The .suffix_name
on pretxncommit
is to avoid overriding any globally defined hook, especially if this is defined in the repository's hgrc
rather than the global one. Suffixes are how one allows multiple responses to the same hook.