Rev 4473: (robertc) Do not permit stacking a branch on itself. (Robert Collins, in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Tue Jun 23 10:05:55 BST 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4473 [merge]
revision-id: pqm at pqm.ubuntu.com-20090623090552-hzfy5mv9hfcral7j
parent: pqm at pqm.ubuntu.com-20090623080828-0ohge796hwkgui9s
parent: robertc at robertcollins.net-20090623072428-dr2ley397is964ry
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2009-06-23 10:05:52 +0100
message:
(robertc) Do not permit stacking a branch on itself. (Robert Collins,
\#376243)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/errors.py errors.py-20050309040759-20512168c4e14fbd
bzrlib/tests/branch_implementations/test_stacking.py test_stacking.py-20080214020755-msjlkb7urobwly0f-1
bzrlib/tests/bzrdir_implementations/test_push.py test_push.py-20090403142358-xnn0wtsk3gx238ot-1
bzrlib/tests/test_errors.py test_errors.py-20060210110251-41aba2deddf936a8
=== modified file 'NEWS'
--- a/NEWS 2009-06-23 04:02:23 +0000
+++ b/NEWS 2009-06-23 09:05:52 +0000
@@ -52,6 +52,13 @@
longer error during commit or push operations when an autopack operation
is triggered. (Robert Collins, #365615)
+* Stacking will no longer accept requests to stack on the same
+ branch/repository. Existing branches that incorrectly reference the same
+ repository in a stacking configuration will now raise
+ UnstackableLocationError when the branch is opened. This can be fixed by
+ removing the stacking location inside ``.bzr/branch``.
+ (Robert Collins, #376243)
+
* Unshelve works correctly when multiple zero-length files are present on
the shelf. (Aaron Bentley, #363444)
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2009-06-17 03:53:51 +0000
+++ b/bzrlib/branch.py 2009-06-19 00:33:36 +0000
@@ -105,6 +105,8 @@
def _activate_fallback_location(self, url):
"""Activate the branch/repository from url as a fallback repository."""
repo = self._get_fallback_repository(url)
+ if repo.has_same_location(self.repository):
+ raise errors.UnstackableLocationError(self.base, url)
self.repository.add_fallback_repository(repo)
def break_lock(self):
=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py 2009-06-17 05:05:28 +0000
+++ b/bzrlib/errors.py 2009-06-19 00:33:36 +0000
@@ -636,6 +636,16 @@
self.url = url
+class UnstackableLocationError(BzrError):
+
+ _fmt = "The branch '%(branch_url)s' cannot be stacked on '%(target_url)s'."
+
+ def __init__(self, branch_url, target_url):
+ BzrError.__init__(self)
+ self.branch_url = branch_url
+ self.target_url = target_url
+
+
class UnstackableRepositoryFormat(BzrError):
_fmt = ("The repository '%(url)s'(%(format)s) is not a stackable format. "
=== modified file 'bzrlib/tests/branch_implementations/test_stacking.py'
--- a/bzrlib/tests/branch_implementations/test_stacking.py 2009-06-11 07:43:56 +0000
+++ b/bzrlib/tests/branch_implementations/test_stacking.py 2009-06-19 00:33:36 +0000
@@ -78,6 +78,34 @@
return
self.assertEqual('../target', branch.get_stacked_on_url())
+ def test_set_stacked_on_same_branch_raises(self):
+ # Stacking on the same branch silently raises and doesn't execute the
+ # change. Reported in bug 376243.
+ branch = self.make_branch('branch')
+ try:
+ self.assertRaises(errors.UnstackableLocationError,
+ branch.set_stacked_on_url, '../branch')
+ except unstackable_format_errors:
+ # if the set failed, so must the get
+ self.assertRaises(unstackable_format_errors, branch.get_stacked_on_url)
+ return
+ self.assertRaises(errors.NotStacked, branch.get_stacked_on_url)
+
+ def test_set_stacked_on_same_branch_after_being_stacked_raises(self):
+ # Stacking on the same branch silently raises and doesn't execute the
+ # change.
+ branch = self.make_branch('branch')
+ target = self.make_branch('target')
+ try:
+ branch.set_stacked_on_url('../target')
+ except unstackable_format_errors:
+ # if the set failed, so must the get
+ self.assertRaises(unstackable_format_errors, branch.get_stacked_on_url)
+ return
+ self.assertRaises(errors.UnstackableLocationError,
+ branch.set_stacked_on_url, '../branch')
+ self.assertEqual('../target', branch.get_stacked_on_url())
+
def assertRevisionInRepository(self, repo_path, revid):
"""Check that a revision is in a repository, disregarding stacking."""
repo = bzrdir.BzrDir.open(repo_path).open_repository()
=== modified file 'bzrlib/tests/bzrdir_implementations/test_push.py'
--- a/bzrlib/tests/bzrdir_implementations/test_push.py 2009-04-03 14:24:40 +0000
+++ b/bzrlib/tests/bzrdir_implementations/test_push.py 2009-06-19 00:07:31 +0000
@@ -33,13 +33,13 @@
tree.commit('one', rev_id='r1')
return tree
- def test_push_new_branch(self):
+ def test_push_new_branch(self):
tree = self.create_simple_tree()
dir = self.make_repository('dir').bzrdir
result = dir.push_branch(tree.branch)
self.assertEquals(tree.branch, result.source_branch)
self.assertEquals(dir.open_branch().base, result.target_branch.base)
- self.assertEquals(dir.open_branch().base,
+ self.assertEquals(dir.open_branch().base,
tree.branch.get_push_location())
def test_push_new_empty(self):
@@ -47,7 +47,7 @@
dir = self.make_repository('dir').bzrdir
result = dir.push_branch(tree.branch)
self.assertEquals(tree.branch.base, result.source_branch.base)
- self.assertEquals(dir.open_branch().base,
+ self.assertEquals(dir.open_branch().base,
result.target_branch.base)
def test_push_incremental(self):
@@ -58,7 +58,7 @@
tree.add(['b'])
tree.commit('two', rev_id='r2')
result = dir.push_branch(tree.branch)
- self.assertEquals(tree.last_revision(),
+ self.assertEquals(tree.last_revision(),
result.branch_push_result.new_revid)
self.assertEquals(2, result.branch_push_result.new_revno)
self.assertEquals(tree.branch.base, result.source_branch.base)
=== modified file 'bzrlib/tests/test_errors.py'
--- a/bzrlib/tests/test_errors.py 2009-05-01 06:42:30 +0000
+++ b/bzrlib/tests/test_errors.py 2009-06-19 00:33:36 +0000
@@ -242,6 +242,11 @@
"You will need to upgrade the branch to permit branch stacking.",
str(error))
+ def test_unstackable_location(self):
+ error = errors.UnstackableLocationError('foo', 'bar')
+ self.assertEqualDiff("The branch 'foo' cannot be stacked on 'bar'.",
+ str(error))
+
def test_unstackable_repository_format(self):
format = u'foo'
url = "/foo"
More information about the bazaar-commits
mailing list