changeset 17984:b74361cf7c0a stable

update: allow update to existing branches with invalid names (issue3710) Starting with 361ab1e2086f, users are no longer able to update a working copy to a branch named with a "bad" character (such as ':'). Prior to v2.4, it was possible to create branch names using "bad" characters, so this breaks backwards compatibility. Mercurial must allow users to update to existing branches with bad names. However, it should continue to prevent the creation of new branches with bad names. A test was added to confirm that 'hg update' works as expected. The test uses a bundled repo that was created with an earlier version of Mercurial.
author Tim Henigan <tim.henigan@gmail.com>
date Tue, 27 Nov 2012 08:47:35 -0500
parents e689b0d91546
children f94ead934067
files mercurial/commands.py mercurial/dirstate.py tests/bundles/test-invalid-branch-name.hg tests/test-branches.t
diffstat 4 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Wed Nov 28 11:20:56 2012 +0100
+++ b/mercurial/commands.py	Tue Nov 27 08:47:35 2012 -0500
@@ -924,6 +924,7 @@
                                        ' exists'),
                                      # i18n: "it" refers to an existing branch
                                      hint=_("use 'hg update' to switch to it"))
+            scmutil.checknewlabel(None, label, 'branch')
             repo.dirstate.setbranch(label)
             ui.status(_('marked working directory as branch %s\n') % label)
             ui.status(_('(branches are permanent and global, '
--- a/mercurial/dirstate.py	Wed Nov 28 11:20:56 2012 +0100
+++ b/mercurial/dirstate.py	Tue Nov 27 08:47:35 2012 -0500
@@ -261,7 +261,6 @@
 
     def setbranch(self, branch):
         # no repo object here, just check for reserved names
-        scmutil.checknewlabel(None, branch, 'branch')
         self._branch = encoding.fromlocal(branch)
         f = self._opener('branch', 'w', atomictemp=True)
         try:
Binary file tests/bundles/test-invalid-branch-name.hg has changed
--- a/tests/test-branches.t	Wed Nov 28 11:20:56 2012 +0100
+++ b/tests/test-branches.t	Tue Nov 27 08:47:35 2012 -0500
@@ -68,6 +68,23 @@
   abort: '\n' cannot be used in a name
   [255]
 
+verify update will accept invalid legacy branch names
+
+  $ hg init test-invalid-branch-name
+  $ cd test-invalid-branch-name
+  $ hg pull -u "$TESTDIR"/bundles/test-invalid-branch-name.hg
+  pulling from *test-invalid-branch-name.hg (glob)
+  requesting all changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 3 changesets with 3 changes to 2 files
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ hg update '"colon:test"'
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cd ..
+
   $ echo 'd' >d
   $ hg add d
   $ hg branch 'a branch name much longer than the default justification used by branches'