Check for bad branch names.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Mon, 18 Jul 2011 16:37:38 +0300
changeset 894 d7b21de5bb44
parent 893 50b41a290439
child 895 41b0efe7f3b7
Check for bad branch names.
hg.rst
--- a/hg.rst	Mon Jul 11 11:11:18 2011 +0300
+++ b/hg.rst	Mon Jul 18 16:37:38 2011 +0300
@@ -93,6 +93,10 @@
   $ hg convert --filemap filemap.txt $repo_orig $repo_new
   $ hg -R $repo_new up
 
+** Fix branch names.
+
+
+
 * Join history of two repos.
 
   $ cat >filemap1.txt <<EOF
@@ -337,3 +341,32 @@
   http://mercurial.selenic.com/wiki/TipsAndTricks#Merge_or_rebase_with_uncommitted_changes
   http://mercurial.selenic.com/wiki/ShelveExtension
 
+* Hooks.
+
+** Check for bad branch names.
+
+.hg/hgcheck.py::
+
+  import re
+  goodbranch_re = r'((bug|feature)#\d|release-1\.\d\.\d|default)$'
+  def precommit_badbranchname(ui, repo, hooktype, **kwargs):
+      ui.warn('"%s" hook failed\n' % hooktype)
+      for rev in repo:
+          branch = repo[rev].branch()
+          re_ = re.compile(goodbranch_re)
+          if not re_.match(branch):
+              ui.warn('Invalid branch name "%s".\nUse one of default, bug#ID, feature#ID or release-1.XX.XX.\n' % branch)
+              return True
+      return False
+
+.hg/hgrc::
+
+  [hooks]
+  precommit.badbranchname = python:.hg/hgcheck.py:precommit_badbranchname
+  # precommit.gg = python:my.hgcheck.py.precommit_badbranch
+  prechangegroup.badbranchname = python:.hg/hgcheck.py:precommit_badbranchname
+
+Read more:
+
+  http://mercurial.selenic.com/wiki/HookExamples
+