2009-11-10 13 views
23

Quali sono alcuni utili ganci Mercurial che hai trovato?Ganci Mercurial utili

Qualche esempio ganci si trovano nella Mercurial book:

Io personalmente non trovano questi molto utili. Mi piacerebbe vedere:

  • Rifiuta capi più
  • rifiutare Changegroups con unioni (utile se si desidera che gli utenti aggiustano sempre)
    • Rifiuta Changegroups con unioni, a meno che messaggio di commit ha stringa speciale
  • Collegamenti automatici a Fogbugz o TFS (simile al bugzilla hook)
  • Blacklist, negherebbe le push che avevano determinati ID di changeset. (Utile se usi MQ per estrarre le modifiche da altri cloni)

Si prega di attenersi ai ganci che hanno sia bat che bash o Python. In questo modo possono essere usati sia da * nix che da utenti Windows.

+0

Forse altre idee possono essere ricavate da queste domande di Subversion: http://stackoverflow.com/questions/6155/common-types-of-subversion-hooks e http://stackoverflow.com/questions/884608/share- common-useful-svn-pre-commit-hooks ... – Macke

risposta

16

Il mio hook preferito per i repository formali è quello che rifiuta più teste. È fantastico quando hai un sistema di integrazione continua che ha bisogno di un consiglio post-merge da compilare automaticamente.

Alcuni esempi sono qui: MercurialWiki: TipsAndTricks - prevent a push that would create multiple heads

Io uso questa versione da 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 - questo più buono come consentire la ramificazione .... – gavenkoa

+0

In effetti, ci sono alcune belle varianti che permettono solo una testa per ogni ramo (anche le ramificazioni anonime sono ramificate). –

+1

@gavenkoa: il collegamento deve essere http://hg.python.org/hooks/file/tip/checkheads.py (non/suggerimenti /) – Macke

8

Ho appena creato un gancio piccolo pretxncommit che verifica la presenza di schede e spazio bianco in coda e rapporti piuttosto bene per l'utente. Fornisce anche un comando per ripulire quei file (o tutti i file).

Vedere l'estensione CheckFiles.

5

Un altro buon gancio è questo. Consente più teste, ma solo se si trovano in rami diversi.

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

ho come la testa singola al gancio Filiale di cui sopra; tuttavia, branchtags() deve essere sostituito con branchmap() poiché branchtags() non è più disponibile. (Non ho potuto commentare quello così l'ho bloccato qui).

Mi piace anche il gancio da https://bobhood.wordpress.com/2012/12/14/branch-freezing-with-mercurial/ per i rami congelati.Si aggiunge una sezione nel vostro hgrc come questo:

[frozen_branches] 
freeze_list = BranchFoo, BranchBar 

e aggiungere il gancio:

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 

Se qualcuno tenta di aggiornare i rami congelati (ad esempio, BranchFoo, BranchBar) l'operazione viene interrotta.