# HG changeset patch # User Brendan Cully # Date 1173735854 25200 # Node ID b2873c587b1a87b207ba5b1e2758dfdfe46be906 # Parent 7e95381a9f1ef8aaef105a6587423261b01a626b branch: require --force to shadow existing branches diff -r 7e95381a9f1e -r b2873c587b1a mercurial/commands.py --- a/mercurial/commands.py Mon Mar 12 13:58:06 2007 -0700 +++ b/mercurial/commands.py Mon Mar 12 14:44:14 2007 -0700 @@ -247,14 +247,21 @@ ui.status(_('(use "backout --merge" ' 'if you want to auto-merge)\n')) -def branch(ui, repo, label=None): +def branch(ui, repo, label=None, **opts): """set or show the current branch name With , set the current branch name. Otherwise, show the current branch name. + + Unless --force is specified, branch will not let you set a + branch name that shadows an existing branch. """ if label is not None: + if not opts.get('force') and label in repo.branchtags(): + if label not in [p.branch() for p in repo.workingctx().parents()]: + raise util.Abort(_('a branch of the same name already exists' + ' (use --force to override)')) repo.opener("branch", "w").write(util.fromlocal(label) + '\n') else: b = util.tolocal(repo.workingctx().branch()) @@ -2622,7 +2629,10 @@ ('u', 'user', '', _('record user as committer')), ] + walkopts + commitopts, _('hg backout [OPTION]... REV')), - "branch": (branch, [], _('hg branch [NAME]')), + "branch": (branch, + [('f', 'force', None, + _('create branch even if it shadows an existing branch'))], + _('hg branch [NAME]')), "branches": (branches, [], _('hg branches')), "bundle": (bundle,