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