[PATCH 1 of 3] branch: detect and prevent adding branches that would be shadowed by a tag
Dan Villiom Podlaski Christiansen
danchr at gmail.com
Fri Nov 12 10:40:18 CST 2010
# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
# Date 1289579971 -3600
# Node ID bdf95be4ea789a13d088f0955ffcd072590a1eb6
# Parent a2aa26f9513b7aeabaf1c105cd18c19077ec2d43
branch: detect and prevent adding branches that would be shadowed by a tag.
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -489,10 +489,14 @@ def branch(ui, repo, label=None, **opts)
ui.status(_('reset working directory to branch %s\n') % label)
elif label:
utflabel = encoding.fromlocal(label)
- if not opts.get('force') and utflabel in repo.branchtags():
- if label not in [p.branch() for p in repo.parents()]:
+ if not opts.get('force'):
+ if (utflabel in repo.branchtags()
+ and label not in [p.branch() for p in repo.parents()]):
raise util.Abort(_('a branch of the same name already exists'
" (use 'hg update' to switch to it)"))
+ elif utflabel in repo.tags() and repo.tagtype(utflabel):
+ raise util.Abort(_('a tag of the same name already exists'))
+
repo.dirstate.setbranch(utflabel)
ui.status(_('marked working directory as branch %s\n') % label)
else:
diff --git a/tests/test-branch-tag-confict.t b/tests/test-branch-tag-confict.t
--- a/tests/test-branch-tag-confict.t
+++ b/tests/test-branch-tag-confict.t
@@ -12,7 +12,7 @@ Create a tag.
Create a branch with the same name as the tag.
- $ hg branch branchortag
+ $ hg branch -f branchortag
marked working directory as branch branchortag
$ hg ci -m 'Create a branch with the same name as a tag.'
diff --git a/tests/test-newbranch.t b/tests/test-newbranch.t
--- a/tests/test-newbranch.t
+++ b/tests/test-newbranch.t
@@ -15,6 +15,16 @@
$ hg branch bar
marked working directory as branch bar
$ hg ci -m "change branch name"
+ $ hg tag thetag
+
+Shadowed by a tag:
+
+ $ hg branch thetag
+ abort: a tag of the same name already exists
+ [255]
+
+ $ hg branch -f thetag
+ marked working directory as branch thetag
Branch shadowing:
@@ -31,7 +41,7 @@ Branch shadowing:
There should be only one default branch head
$ hg heads .
- changeset: 3:9d567d0b51f9
+ changeset: 4:e82099c60d52
tag: tip
user: test
date: Thu Jan 01 00:00:00 1970 +0000
@@ -39,14 +49,14 @@ There should be only one default branch
$ hg co foo
- 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
$ hg branch
foo
$ echo bleah > a
$ hg ci -m "modify a branch"
$ hg merge default
- 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)
$ hg branch
@@ -54,29 +64,36 @@ There should be only one default branch
$ hg ci -m "merge"
$ hg log
- changeset: 5:dc140083783b
+ changeset: 6:3f5c5fc3592a
branch: foo
tag: tip
- parent: 4:98d14f698afe
- parent: 3:9d567d0b51f9
+ parent: 5:98d14f698afe
+ parent: 4:e82099c60d52
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: merge
- changeset: 4:98d14f698afe
+ changeset: 5:98d14f698afe
branch: foo
parent: 1:0079f24813e2
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: modify a branch
- changeset: 3:9d567d0b51f9
+ changeset: 4:e82099c60d52
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: clear branch name
+ changeset: 3:dcc4db38c57b
+ branch: bar
+ user: test
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: Added tag thetag for changeset ed2bbf4e0102
+
changeset: 2:ed2bbf4e0102
branch: bar
+ tag: thetag
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: change branch name
@@ -93,9 +110,9 @@ There should be only one default branch
summary: initial
$ hg branches
- foo 5:dc140083783b
- default 3:9d567d0b51f9 (inactive)
- bar 2:ed2bbf4e0102 (inactive)
+ foo 6:3f5c5fc3592a
+ default 4:e82099c60d52 (inactive)
+ bar 3:dcc4db38c57b (inactive)
$ hg branches -q
foo
@@ -105,12 +122,12 @@ There should be only one default branch
Test for invalid branch cache:
$ hg rollback
- rolling back to revision 4 (undo commit)
+ rolling back to revision 5 (undo commit)
$ cp $branchcache .hg/bc-invalid
$ hg log -r foo
- changeset: 4:98d14f698afe
+ changeset: 5:98d14f698afe
branch: foo
tag: tip
parent: 1:0079f24813e2
@@ -122,12 +139,12 @@ Test for invalid branch cache:
$ hg --debug log -r foo
invalidating branch cache (tip differs)
- changeset: 4:98d14f698afeaff8cb612dcf215ce95e639effc3
+ changeset: 5:98d14f698afeaff8cb612dcf215ce95e639effc3
branch: foo
tag: tip
parent: 1:0079f24813e2b73a891577c243684c5066347bc8
parent: -1:0000000000000000000000000000000000000000
- manifest: 4:d01b250baaa05909152f7ae07d7a649deea0df9a
+ manifest: 5:d01b250baaa05909152f7ae07d7a649deea0df9a
user: test
date: Thu Jan 01 00:00:00 1970 +0000
files: a
@@ -140,13 +157,13 @@ Test for invalid branch cache:
$ echo corrupted > $branchcache
$ hg log -qr foo
- 4:98d14f698afe
+ 5:98d14f698afe
$ cat $branchcache
- 98d14f698afeaff8cb612dcf215ce95e639effc3 4
- 9d567d0b51f9e2068b054e1948e1a927f99b5874 default
+ 98d14f698afeaff8cb612dcf215ce95e639effc3 5
+ e82099c60d523212ee0a83a975bab144f4077c8e default
98d14f698afeaff8cb612dcf215ce95e639effc3 foo
- ed2bbf4e01029020711be82ca905283e883f0e11 bar
+ dcc4db38c57b0c212ed56941856db90c17bbeb4c bar
Push should update the branch cache:
@@ -165,17 +182,17 @@ Pushing everything:
$ hg push -qf ../target
$ cat ../target/$branchcache
- 98d14f698afeaff8cb612dcf215ce95e639effc3 4
- 9d567d0b51f9e2068b054e1948e1a927f99b5874 default
+ 98d14f698afeaff8cb612dcf215ce95e639effc3 5
+ e82099c60d523212ee0a83a975bab144f4077c8e default
98d14f698afeaff8cb612dcf215ce95e639effc3 foo
- ed2bbf4e01029020711be82ca905283e883f0e11 bar
+ dcc4db38c57b0c212ed56941856db90c17bbeb4c bar
Update with no arguments: tipmost revision of the current branch:
$ hg up -q -C 0
$ hg up -q
$ hg id
- 9d567d0b51f9
+ e82099c60d52
$ hg up -q 1
$ hg up -q
@@ -209,11 +226,11 @@ Fastforward merge:
foo
$ hg commit -m'Merge ff into foo'
$ hg parents
- changeset: 6:917eb54e1b4b
+ changeset: 7:917eb54e1b4b
branch: foo
tag: tip
- parent: 4:98d14f698afe
- parent: 5:6683a60370cb
+ parent: 5:98d14f698afe
+ parent: 6:6683a60370cb
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: Merge ff into foo
More information about the Mercurial-devel
mailing list