Comments
Patch
@@ -1110,7 +1110,12 @@ def branch(ui, repo, label=None, **opts)
ui.status(_('reset working directory to branch %s\n') % label)
elif label:
if not opts.get('force') and label in repo.branchmap():
- if label not in [p.branch() for p in repo.parents()]:
+ if (new and
+ util.any(repo.changelog.isancestor(repo[label].node(),
+ p.node())
+ for p in repo.parents())):
+ pass # reviving old branch head
+ elif label not in [p.branch() for p in repo.parents()]:
raise util.Abort(_('a branch of the same name already'
' exists'),
# i18n: "it" refers to an existing branch
@@ -28,7 +28,7 @@
(branches are permanent and global, did you want a bookmark?)
$ hg ci -m "change branch name"
-Branch shadowing:
+Branch shadowing - only possible with --new on ancestor or with force:
$ hg branch default
abort: a branch of the same name already exists
@@ -42,6 +42,16 @@ Branch shadowing:
$ hg ci -m "clear branch name"
created new head
+ $ hg branch --new foo
+ marked working directory as branch foo
+ (branches are permanent and global, did you want a bookmark?)
+ $ hg up -qC 0
+
+ $ hg branch --new foo
+ abort: a branch of the same name already exists
+ (use 'hg update' to switch to it)
+ [255]
+
There should be only one default branch head
$ hg heads .