我需要使用模式来检查提交注释的mercurial的简单钩子。这是我的钩子:如何在Tortoise Hg日志窗口中显示钩子输出?
#!/usr/bin/env python
#
# save as .hg/check_whitespace.py and make executable
import re
def check_comment(comment):
#
print 'Checking comment...'
pattern = '^((Issue \d+:)|(No Issue:)).+'
if re.match(pattern, comment, flags=re.IGNORECASE):
return 1
else:
print >> sys.stderr, 'Comment does not match pattern. You must start it with "Issue 12323:" or "No Issue:"'
return 0
if __name__ == '__main__':
import os, sys
comment=os.popen('hg tip --template "{desc}"').read()
if not check_comment(comment):
sys.exit(1)
sys.exit(0)
它的工作原理。它甚至在我从控制台提交时显示错误消息'Comment does not match pattern. You must start it with "Issue 12323:" or "No Issue:"'
。但是当我尝试从Tortoise Hg Workbench提交时,只显示系统消息:abort: pretxncommit.check_comment hook exited with status 1
。
我需要通知用户出了什么问题。有什么办法可以迫使乌龟显示钩子的输出吗?
只是一个猜测,但你有没有尝试写入sys.out而不是sys.err? – bbaja42
是的。它没有帮助。 –