[PATCH stable] branch: strip whitespace before testing known branch name
Yuya Nishihara
yuya at tcha.org
Tue May 7 17:45:56 CDT 2013
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1367938143 -32400
# Tue May 07 23:49:03 2013 +0900
# Branch stable
# Node ID f42a6337cac2c3920fb7587797ada022c1141182
# Parent 0a12e5f3a979ee302dc10647483200df00a105ab
branch: strip whitespace before testing known branch name
Because dirstate._branch() strips leading/trailing spaces from .hg/branch,
"hg branch ' foo '" should abort if branch "foo" exists in another head.
tag command had a similar bug and fixed by 3d0a9c8d7184.
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -943,6 +943,9 @@ def branch(ui, repo, label=None, **opts)
Returns 0 on success.
"""
+ if label:
+ label = label.strip()
+
if not opts.get('clean') and not label:
ui.write("%s\n" % repo.dirstate.branch())
return
diff --git a/tests/test-branches.t b/tests/test-branches.t
--- a/tests/test-branches.t
+++ b/tests/test-branches.t
@@ -68,6 +68,18 @@ invalid characters
abort: '\n' cannot be used in a name
[255]
+trailing or leading spaces should be stripped before testing duplicates
+
+ $ hg branch 'b '
+ abort: a branch of the same name already exists
+ (use 'hg update' to switch to it)
+ [255]
+
+ $ hg branch ' b'
+ abort: a branch of the same name already exists
+ (use 'hg update' to switch to it)
+ [255]
+
verify update will accept invalid legacy branch names
$ hg init test-invalid-branch-name
More information about the Mercurial-devel
mailing list