[PATCH] branch and tag subcommands don't accept colons in labels/names

Fabian Kreutz fabian.kreutz at qvantel.com
Thu Nov 24 06:09:07 CST 2011


Hi!

The branch subcommand allows creating branches with a colon (":") inside, 
although that is invalid.
Such a branch cannot be addressed e.g. in "update", as first matches against 
revision intervals  and fails with an unhelpful error message.

It says clearly in "hg help revision" that a colon is not allowed in branch 
and tag names, so the "hg branch" subcommand should abort instead of creating 
that branch.

I submitted this as http://mercurial.selenic.com/bts/issue3125



# HG changeset patch
# User fabian.kreutz at qvantel.com
# Date 1322136389 -7200
# Node ID ab9c80eb563461e9a3ba037892199ea65c387dda
# Parent  3e13ade423f08031045c2d5a2ef2a87a863a2614
branch and tag subcommands don't accept colons in labels/names

diff -r 3e13ade423f0 -r ab9c80eb5634 mercurial/commands.py
--- a/mercurial/commands.py     Mon Nov 21 01:49:20 2011 +0100
+++ b/mercurial/commands.py     Thu Nov 24 14:06:29 2011 +0200
@@ -855,6 +855,8 @@
         repo.dirstate.setbranch(label)
         ui.status(_('reset working directory to branch %s\n') % label)
     elif label:
+        if label.find(':') > -1:
+            raise util.Abort(_('branch names cannot contain a ":"'))
         if not opts.get('force') and label in repo.branchtags():
             if label not in [p.branch() for p in repo.parents()]:
                 raise util.Abort(_('a branch of the same name already exists'),
@@ -5452,6 +5454,8 @@
             raise util.Abort(_("the name '%s' is reserved") % n)
         if not n:
             raise util.Abort(_('tag names cannot consist entirely of whitespace'))
+        if n.find(':') > -1:
+            raise util.Abort(_('tag names cannot contain a ":"'))
     if opts.get('rev') and opts.get('remove'):
         raise util.Abort(_("--rev and --remove are incompatible"))
     if opts.get('rev'):


More information about the Mercurial-devel mailing list