有用的Mercurial Hooks

Nat*_*Lee 23 mercurial hook

您遇到过哪些有用的Mercurial钩子?

Mercurial书中有一些示例钩子:

我个人认为这些非常有用.我想看看:

  • 拒绝多个头
  • 使用合并拒绝更改组(如果您希望用户始终重新绑定,则非常有用)
    • 除非提交消息具有特殊字符串,否则使用合并拒绝更改组
  • 自动链接到Fogbugz或TFS(类似于bugzilla钩子)
  • 黑名单,会拒绝具有某些变更组ID的推送.(如果使用MQ从其他克隆中提取更改,则非常有用)

请坚持使用bat和bash或Python的钩子.这样,*nix和Windows用户都可以使用它们.

Ry4*_*ase 16

我最喜欢的正式存储库钩子就是那个拒绝多个头的人.当你有一个需要合并后提示自动构建的持续集成系统时,这很棒.

这里有一些例子:MercurialWiki:TipsAndTricks - 防止产生多个头的推送

我使用Netbeans的这个版本:

# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
#
# To forbid pushes which creates two or more headss
#
# [hooks]
# pretxnchangegroup.forbid_2heads = python:forbid2_head.forbid_2heads

from mercurial import ui
from mercurial.i18n import gettext as _

def forbid_2heads(ui, repo, hooktype, node, **kwargs):
    if len(repo.heads()) > 1:
        ui.warn(_('Trying to push more than one head, try run "hg merge" before it.\n'))
        return True
Run Code Online (Sandbox Code Playgroud)

  • http://hg.python.org/hooks/file/tips/checkheads.py - 这更好,因为允许分支.... (4认同)

Mac*_*cke 9

我刚刚创建了一个小的pretxncommit钩子,它检查选项卡和尾随空格,并向用户报告它.它还提供清理这些文件(或所有文件)的命令.

请参阅CheckFiles扩展.


Nat*_*Lee 5

另一个好钩子是这个.它允许多个头,但只有它们在不同的分支中.

每个分支单头

def hook(ui, repo, **kwargs):
    for b in repo.branchtags():
        if len(repo.branchheads(b)) > 1:
            print "Two heads detected on branch '%s'" % b
            print "Only one head per branch is allowed!"
            return 1
    return 0
Run Code Online (Sandbox Code Playgroud)