【发布时间】:2012-05-09 18:12:44
【问题描述】:
编辑 制作了这个基本钩子以防止分支名称和提交消息 bugID 不匹配。 https://gist.github.com/2583189
所以基本上的想法是,如果分支名称类似于 bug_123 或 feature_123,则挂钩应将“BugID:xyz”附加到提交消息的末尾。但是,我在找出如何执行此操作时遇到问题,因为大多数 pretxncommit 示例人们不想改变变更集描述。
这是我目前所拥有的。它使用正确的消息更新 .hg/commit.save,但此消息永远不会传输到提交。但是,它会显示在下一次提交的默认消息框 (tortoisehg) 中。也许 pretxncommit 不是正确的钩子?
我可以使用预提交挂钩,阅读 commit.save 和 repo['tip'].branch() 文件并更改 那,如果是这样,我从哪里获取分支名称?
#
# Fogbugz automaticically add BugID:123 to commit messages based on branch names.
# Your branch name must be in the format feature_123_description or bug_123_description
#
import re
import mercurial, sys, os
_branch_regex = re.compile('(feature|bug|case|bugid|fogbugz)_(\d+)')
_commit_regex = re.compile(r'\b(?P<case>(review|case|bug[zs]?(\s| )*(id)?:?)s?(\s| )*([#:; ]| )+)((([ ,:;#]|and)*)(?P<bugid>\d+))+',re.I)
def pretxncommithook(ui, repo, **kwargs):
ui.write('hook pretxncommithook running from fogbugz.py\n')
"""
Checks a single commit message for adherence to commit message rules.
To use add the following to your project .hg/hgrc for each
project you want to check, or to your user hgrc to apply to all projects.
[hooks]
pretxncommit.fogbugz = python:fogbugz.pretxncommithook
"""
hg_commit_message = repo['tip'].description()
commit_has_bugid = _commit_regex.match(hg_commit_message) is not None
match = _branch_regex.match(repo['tip'].branch())
if match:
hg_commit_message = hg_commit_message + ' BugID:'+ match.groups()[1]
#hg_commit_message needs to be escaped for characters like >
os.system('echo ' + hg_commit_message + ' > .hg/commit.save')
在一个稍微不相关的注释中,如果 Fogbugz/Kiln 团队的任何人看到这个......请更新您的软件以读取分支名称,我不需要在每个该死的提交上放置 BugID:x。首先,它浪费了我的时间。其次,如果案例 ID 输入不正确,它不会出现在错误上,而不会引起很多混乱。许多开发人员使用每个错误/功能系统的分支。这是我工作的公司政策。 Fogbugz 很烂。
【问题讨论】:
-
出于好奇:你为什么需要它?您始终可以检索提交所属的分支名称。 PS:哦,这是Kiln要求:-S好奇怪
-
它不是供人类使用的。 Fogbugz,我们的错误跟踪器通过读取提交描述中的 BugID:x 或 case y 将提交与错误相关联。是的,我什至需要它是荒谬的。
-
FogBugz mercurial 集成使用更改组挂钩将相关信息推送到 FogBugz。您可以更改它以从分支名称而不是从提交消息中获取 FogBugz 案例 ID。当然,如果您升级 FogBugz 版本,您必须让您的变更组挂钩保持最新。
-
我无权访问fogbugz服务器。
标签: python mercurial mercurial-hook