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

Fabian Kreutz fabian.kreutz at qvantel.com
Thu Nov 24 06:29:05 CST 2011


Added tests and longer commit message to the patch:

# HG changeset patch
# User fabian.kreutz at qvantel.com
# Date 1322137649 -7200
# Node ID d321f12b39293f766f1416cdc399ab0a0ee6e491
# Parent  3e13ade423f08031045c2d5a2ef2a87a863a2614
Disallow colon in tag or branch name
Branch and tag names containing a colon (":") are not allowed as they would
be confused with revision intervals.
Subcommands branch and tag do not allow the creation of such labels anymore.

diff -r 3e13ade423f0 -r d321f12b3929 mercurial/commands.py
--- a/mercurial/commands.py     Mon Nov 21 01:49:20 2011 +0100
+++ b/mercurial/commands.py     Thu Nov 24 14:27: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'):
diff -r 3e13ade423f0 -r d321f12b3929 tests/test-branches.t
--- a/tests/test-branches.t     Mon Nov 21 01:49:20 2011 +0100
+++ b/tests/test-branches.t     Thu Nov 24 14:27:29 2011 +0200
@@ -398,3 +398,10 @@
   \x1b[0;34mc\x1b[0m \x1b[0;36m                            14:f894c25619d3\x1b[0m (closed) (esc)
   \x1b[0;35ma\x1b[0m \x1b[0;36m                             5:d8cbc61dbaa6\x1b[0m (inactive) (esc)
   \x1b[0;35mdefault\x1b[0m \x1b[0;36m                       0:19709c5a4e75\x1b[0m (inactive) (esc)
+
+invalid branch name:
+
+  $ hg branch foo:bar
+  abort: branch names cannot contain a ":"
+  $ hg commit -m "ignored"
+  nothing changed
diff -r 3e13ade423f0 -r d321f12b3929 tests/test-tags.t
--- a/tests/test-tags.t Mon Nov 21 01:49:20 2011 +0100
+++ b/tests/test-tags.t Thu Nov 24 14:27:29 2011 +0200
@@ -380,3 +380,8 @@
   tip                                1:a0b6fe111088
   localtag                           0:bbd179dfa0a7 local
   globaltag                          0:bbd179dfa0a7
+
+Invalid tag name:
+
+  $ hg tag foo:bar
+  abort: tag names cannot contain a ":"


----- Original Message -----
From: "Fabian Kreutz" <fabian.kreutz at qvantel.com>
To: mercurial-devel at selenic.com
Sent: Thursday, November 24, 2011 2:09:07 PM
Subject: [PATCH] branch and tag subcommands don't accept colons in labels/names


More information about the Mercurial-devel mailing list