2009-11-10 55 views
23

你遇到过什么有用的水银挂钩?有用的水银挂钩

几个例子钩位于Mercurial book

我个人不觉得这是非常有用的。我想看看:

  • 拒绝多头
  • 拒绝(如果你希望用户随时可以变基有用)与合并Changegroups
    • 拒绝Changegroups与合并,除非提交信息有特殊字符串
  • 自动链接到Fogbugz或TFS(类似于bugzilla钩子)
  • 黑名单,将拒绝推送具有某些changeset id的用户。 (如果你使用MQ从其他克隆中引入更改,这很有用)

请坚持使用bat或bash或Python。这样它们可以被* nix和Windows用户使用。

+0

也许更多的想法可以从这些Subversion问题中收集:http://stackoverflow.com/questions/6155/common-types-of-subversion-hooks和http://stackoverflow.com/questions/884608/share- common-useful-svn-pre-commit-hooks ... – Macke 2010-12-29 10:11:54

回答

16

我最喜欢的形式化存储库的钩子是拒绝多个头部的钩子。当你有一个需要合并后提示自动构建的持续集成系统时,这非常棒。

几个例子在这里:MercurialWiki: TipsAndTricks - prevent a push that would create multiple heads

我使用这个版本的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 
+4

http://hg.python.org/hooks/file/tips/checkheads.py - 这更好,因为允许分支.... – gavenkoa 2011-10-20 21:03:50

+0

确实,有一些不错的变体,每个命名分支只允许一个头(匿名分支也是分支)。 – 2011-10-21 23:03:37

+1

@gavenkoa:链接应该是http://hg.python.org/hooks/file/tip/checkheads.py(不是/ tips /) – Macke 2011-10-23 11:25:45

8

我刚刚创建了一个小pretxncommit挂钩,检查标签和结尾的空白,并将其报告相当好听给用户。它还提供了清理这些文件(或所有文件)的命令。

请参阅CheckFiles的扩展。

5

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

Single head per branch

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 
0

我喜欢的单头每如上所述科钩;但是,branchtags()应替换为branchmap(),因为branchtags()不再可用。 (我不能评论那个,所以我坚持下来)。

我也喜欢https://bobhood.wordpress.com/2012/12/14/branch-freezing-with-mercurial/的冻结分支。你在你的hgrc添加一个部分是这样的:

[frozen_branches] 
freeze_list = BranchFoo, BranchBar 

,并添加了钩:

def frozenbranches(ui, repo, **kwargs): 
    hooktype = kwargs['hooktype'] 
    if hooktype != 'pretxnchangegroup': 
     ui.warn('frozenbranches: Only "pretxnchangegroup" hooks are supported by this hook\n') 
     return True 
    frozen_list = ui.configlist('frozen_branches', 'freeze_list') 
    if frozen_list is None: 
     # no frozen branches listed; allow all changes 
     return False 
    try: 
     ctx = repo[kwargs['node']] 
     start = ctx.rev() 
     end = len(repo) 

     for rev in xrange(start, end): 
      node = repo[rev] 
      branch = node.branch() 
      if branch in frozen_list: 
       ui.warn("abort: %d:%s includes modifications to frozen branch: '%s'!\n" % (rev, node.hex()[:12], branch)) 
       # reject the entire changegroup 
       return True 
    except: 
     e = sys.exc_info()[0] 
     ui.warn("\nERROR !!!\n%s" % e) 
     return True 

    # allow the changegroup 
    return False 

如果有人试图更新冻结分支机构(例如,BranchFoo,BranchBar)的交易将被中止。