Rev 2826: Add reconfigure command in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Mon Sep 17 15:29:39 BST 2007
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 2826
revision-id: pqm at pqm.ubuntu.com-20070917142923-f06edfgw1d0cvj4w
parent: pqm at pqm.ubuntu.com-20070917005035-cshdkpzbj63id1uw
parent: abentley at panoramicfeedback.com-20070917124656-j3hhxhx9igy11mfc
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2007-09-17 15:29:23 +0100
message:
Add reconfigure command
added:
bzrlib/reconfigure.py reconfigure.py-20070908040425-6ykgo7escxhyrg9p-1
bzrlib/tests/blackbox/test_reconfigure.py test_reconfigure.py-20070908173426-khfo5fi2rgzgtwj3-1
bzrlib/tests/test_reconfigure.py test_reconfigure.py-20070908040425-6ykgo7escxhyrg9p-2
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
bzrlib/errors.py errors.py-20050309040759-20512168c4e14fbd
bzrlib/merge.py merge.py-20050513021216-953b65a438527106
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/blackbox/__init__.py __init__.py-20051128053524-eba30d8255e08dc3
bzrlib/tests/blackbox/test_merge.py test_merge.py-20060323225809-9bc0459c19917f41
bzrlib/tests/bzrdir_implementations/test_bzrdir.py test_bzrdir.py-20060131065642-0ebeca5e30e30866
------------------------------------------------------------
revno: 2796.2.18
merged: abentley at panoramicfeedback.com-20070917124656-j3hhxhx9igy11mfc
parent: abentley at panoramicfeedback.com-20070917124554-87bcpjl0szn74mdk
parent: pqm at pqm.ubuntu.com-20070917005035-cshdkpzbj63id1uw
committer: Aaron Bentley <abentley at panoramicfeedback.com>
branch nick: bzr.reconfigure
timestamp: Mon 2007-09-17 08:46:56 -0400
message:
merge bzr.dev
------------------------------------------------------------
revno: 2796.2.17
merged: abentley at panoramicfeedback.com-20070917124554-87bcpjl0szn74mdk
parent: abentley at panoramicfeedback.com-20070914144555-3rynerknpoivm2xv
committer: Aaron Bentley <abentley at panoramicfeedback.com>
branch nick: bzr.reconfigure
timestamp: Mon 2007-09-17 08:45:54 -0400
message:
Update docs from review
------------------------------------------------------------
revno: 2796.2.16
merged: abentley at panoramicfeedback.com-20070914144555-3rynerknpoivm2xv
parent: abentley at panoramicfeedback.com-20070914141314-iypr5xj1vnjf1yqt
committer: Aaron Bentley <abentley at panoramicfeedback.com>
branch nick: bzr.reconfigure
timestamp: Fri 2007-09-14 10:45:55 -0400
message:
Documentation updates from review
------------------------------------------------------------
revno: 2796.2.15
merged: abentley at panoramicfeedback.com-20070914141314-iypr5xj1vnjf1yqt
parent: abentley at panoramicfeedback.com-20070914135832-pav71k9dtjl7fcto
committer: Aaron Bentley <abentley at panoramicfeedback.com>
branch nick: bzr.reconfigure
timestamp: Fri 2007-09-14 10:13:14 -0400
message:
More updates from review
------------------------------------------------------------
revno: 2796.2.14
merged: abentley at panoramicfeedback.com-20070914135832-pav71k9dtjl7fcto
parent: aaron.bentley at utoronto.ca-20070913015700-cnv3agbyafac2xh6
committer: Aaron Bentley <abentley at panoramicfeedback.com>
branch nick: bzr.reconfigure
timestamp: Fri 2007-09-14 09:58:32 -0400
message:
Updates from review
------------------------------------------------------------
revno: 2796.2.13
merged: aaron.bentley at utoronto.ca-20070913015700-cnv3agbyafac2xh6
parent: aaron.bentley at utoronto.ca-20070913015449-bjjw2njf3in5roq7
committer: Aaron Bentley <aaron.bentley at utoronto.ca>
branch nick: bzr.reconfigure
timestamp: Wed 2007-09-12 21:57:00 -0400
message:
Update NEWS
------------------------------------------------------------
revno: 2796.2.12
merged: aaron.bentley at utoronto.ca-20070913015449-bjjw2njf3in5roq7
parent: aaron.bentley at utoronto.ca-20070913015420-l766kszjaexug01y
parent: pqm at pqm.ubuntu.com-20070912222627-zvqit350mf6gvrbh
committer: Aaron Bentley <aaron.bentley at utoronto.ca>
branch nick: bzr.reconfigure
timestamp: Wed 2007-09-12 21:54:49 -0400
message:
Merge bzr.dev
------------------------------------------------------------
revno: 2796.2.11
merged: aaron.bentley at utoronto.ca-20070913015420-l766kszjaexug01y
parent: aaron.bentley at utoronto.ca-20070913013916-lucqpfjli2nclzw1
committer: Aaron Bentley <aaron.bentley at utoronto.ca>
branch nick: bzr.reconfigure
timestamp: Wed 2007-09-12 21:54:20 -0400
message:
Cleanups
------------------------------------------------------------
revno: 2796.2.10
merged: aaron.bentley at utoronto.ca-20070913013916-lucqpfjli2nclzw1
parent: aaron.bentley at utoronto.ca-20070913012152-6rahc1x9dn8wjkij
committer: Aaron Bentley <aaron.bentley at utoronto.ca>
branch nick: bzr.reconfigure
timestamp: Wed 2007-09-12 21:39:16 -0400
message:
Ensure that shared repositories are used where possible
------------------------------------------------------------
revno: 2796.2.9
merged: aaron.bentley at utoronto.ca-20070913012152-6rahc1x9dn8wjkij
parent: aaron.bentley at utoronto.ca-20070909202338-gib7crs18xor345t
committer: Aaron Bentley <aaron.bentley at utoronto.ca>
branch nick: bzr.reconfigure
timestamp: Wed 2007-09-12 21:21:52 -0400
message:
Ensure conversion from lightweight checkout works
------------------------------------------------------------
revno: 2796.2.8
merged: aaron.bentley at utoronto.ca-20070909202338-gib7crs18xor345t
parent: aaron.bentley at utoronto.ca-20070909080032-rj0kri2uwfqfvrif
committer: Aaron Bentley <aaron.bentley at utoronto.ca>
branch nick: bzr.reconfigure
timestamp: Sun 2007-09-09 16:23:38 -0400
message:
Ensure conversion from lightweight fetches revisions and sets revision info
------------------------------------------------------------
revno: 2796.2.7
merged: aaron.bentley at utoronto.ca-20070909080032-rj0kri2uwfqfvrif
parent: aaron.bentley at utoronto.ca-20070909071315-9rdv0zzhp3ksc238
committer: Aaron Bentley <aaron.bentley at utoronto.ca>
branch nick: bzr.reconfigure
timestamp: Sun 2007-09-09 04:00:32 -0400
message:
Implement converting a lightweight checkout to a branch
------------------------------------------------------------
revno: 2796.2.6
merged: aaron.bentley at utoronto.ca-20070909071315-9rdv0zzhp3ksc238
parent: aaron.bentley at utoronto.ca-20070908174550-c351ibe2qsh0k2p1
committer: Aaron Bentley <aaron.bentley at utoronto.ca>
branch nick: bzr.reconfigure
timestamp: Sun 2007-09-09 03:13:15 -0400
message:
Implement destroy_branch
------------------------------------------------------------
revno: 2796.2.5
merged: aaron.bentley at utoronto.ca-20070908174550-c351ibe2qsh0k2p1
parent: aaron.bentley at utoronto.ca-20070908173254-u00xy1nhibmazory
committer: Aaron Bentley <aaron.bentley at utoronto.ca>
branch nick: bzr.reconfigure
timestamp: Sat 2007-09-08 13:45:50 -0400
message:
Implement reconfigure command
------------------------------------------------------------
revno: 2796.2.4
merged: aaron.bentley at utoronto.ca-20070908173254-u00xy1nhibmazory
parent: aaron.bentley at utoronto.ca-20070908162726-op1auop97ec4vo2s
committer: Aaron Bentley <aaron.bentley at utoronto.ca>
branch nick: bzr.reconfigure
timestamp: Sat 2007-09-08 13:32:54 -0400
message:
Fix support for reconfiguring to selected bound location
------------------------------------------------------------
revno: 2796.2.3
merged: aaron.bentley at utoronto.ca-20070908162726-op1auop97ec4vo2s
parent: aaron.bentley at utoronto.ca-20070908062626-5yrpwrz4436vlfwe
committer: Aaron Bentley <aaron.bentley at utoronto.ca>
branch nick: bzr.reconfigure
timestamp: Sat 2007-09-08 12:27:26 -0400
message:
Implement conversion to tree and checkout
------------------------------------------------------------
revno: 2796.2.2
merged: aaron.bentley at utoronto.ca-20070908062626-5yrpwrz4436vlfwe
parent: aaron.bentley at utoronto.ca-20070908060259-e1bzvj22gu66qk22
committer: Aaron Bentley <aaron.bentley at utoronto.ca>
branch nick: bzr.reconfigure
timestamp: Sat 2007-09-08 02:26:26 -0400
message:
Refuse to turn lightweight checkouts into branches
------------------------------------------------------------
revno: 2796.2.1
merged: aaron.bentley at utoronto.ca-20070908060259-e1bzvj22gu66qk22
parent: pqm at pqm.ubuntu.com-20070905023600-6h6s51el362b171a
committer: Aaron Bentley <aaron.bentley at utoronto.ca>
branch nick: bzr.reconfigure
timestamp: Sat 2007-09-08 02:02:59 -0400
message:
Begin work on reconfigure command
=== added file 'bzrlib/reconfigure.py'
--- a/bzrlib/reconfigure.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/reconfigure.py 2007-09-14 14:45:55 +0000
@@ -0,0 +1,204 @@
+# Copyright (C) 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""Reconfigure a bzrdir into a new tree/branch/repository layout"""
+
+from bzrlib import (
+ branch,
+ errors,
+ )
+
+class Reconfigure(object):
+
+ def __init__(self, bzrdir, new_bound_location=None):
+ self.bzrdir = bzrdir
+ self.new_bound_location = new_bound_location
+ try:
+ self.repository = self.bzrdir.find_repository()
+ except errors.NoRepositoryPresent:
+ self.repository = None
+ try:
+ branch = self.bzrdir.open_branch()
+ if branch.bzrdir.root_transport.base == bzrdir.root_transport.base:
+ self.local_branch = branch
+ self.referenced_branch = None
+ else:
+ self.local_branch = None
+ self.referenced_branch = branch
+ except errors.NotBranchError:
+ self.local_branch = None
+ self.referenced_branch = None
+ try:
+ self.tree = bzrdir.open_workingtree()
+ except errors.NoWorkingTree:
+ self.tree = None
+ self._unbind = False
+ self._bind = False
+ self._destroy_reference = False
+ self._create_branch = False
+ self._destroy_tree = False
+ self._create_tree = False
+ self._create_repository = False
+
+ @staticmethod
+ def to_branch(bzrdir):
+ """Return a Reconfiguration to convert this bzrdir into a branch
+
+ :param bzrdir: The bzrdir to reconfigure
+ :raise errors.AlreadyBranch: if bzrdir is already a branch
+ :raise errors.ReconfigurationNotSupported: if bzrdir does not contain
+ a branch or branch reference
+ """
+ reconfiguration = Reconfigure(bzrdir)
+ reconfiguration._plan_changes(want_tree=False, want_branch=True,
+ want_bound=False)
+ if not reconfiguration.changes_planned():
+ raise errors.AlreadyBranch(bzrdir)
+ return reconfiguration
+
+ @staticmethod
+ def to_tree(bzrdir):
+ """Return a Reconfiguration to convert this bzrdir into a tree
+
+ :param bzrdir: The bzrdir to reconfigure
+ :raise errors.AlreadyTree: if bzrdir is already a tree
+ :raise errors.ReconfigurationNotSupported: if bzrdir does not contain
+ a branch or branch reference
+ """
+ reconfiguration = Reconfigure(bzrdir)
+ reconfiguration._plan_changes(want_tree=True, want_branch=True,
+ want_bound=False)
+ if not reconfiguration.changes_planned():
+ raise errors.AlreadyTree(bzrdir)
+ return reconfiguration
+
+ @staticmethod
+ def to_checkout(bzrdir, bound_location=None):
+ """Return a Reconfiguration to convert this bzrdir into a checkout
+
+ :param bzrdir: The bzrdir to reconfigure
+ :param bound_location: The location the checkout should be bound to.
+ :raise errors.AlreadyCheckout: if bzrdir is already a checkout
+ :raise errors.ReconfigurationNotSupported: if bzrdir does not contain
+ a branch or branch reference
+ """
+ reconfiguration = Reconfigure(bzrdir, bound_location)
+ reconfiguration._plan_changes(want_tree=True, want_branch=True,
+ want_bound=True)
+ if not reconfiguration.changes_planned():
+ raise errors.AlreadyCheckout(bzrdir)
+ return reconfiguration
+
+ def _plan_changes(self, want_tree, want_branch, want_bound):
+ """Determine which changes are needed to assume the configuration"""
+ if self.repository is None:
+ self._create_repository = True
+ if self.local_branch is None:
+ if want_branch is True:
+ if self.referenced_branch is not None:
+ self._destroy_reference = True
+ self._create_branch = True
+ if want_bound:
+ self._bind = True
+ else:
+ raise errors.ReconfigurationNotSupported(self.bzrdir)
+ else:
+ if want_bound:
+ if self.local_branch.get_bound_location() is None:
+ self._bind = True
+ else:
+ if self.local_branch.get_bound_location() is not None:
+ self._unbind = True
+ if not want_tree and self.tree is not None:
+ self._destroy_tree = True
+ if want_tree and self.tree is None:
+ self._create_tree = True
+
+ def changes_planned(self):
+ """Return True if changes are planned, False otherwise"""
+ return (self._unbind or self._bind or self._destroy_tree
+ or self._create_tree or self._destroy_reference
+ or self._create_branch or self._create_repository)
+
+ def _check(self):
+ """Raise if reconfiguration would destroy local changes"""
+ if self._destroy_tree:
+ changes = self.tree.changes_from(self.tree.basis_tree())
+ if changes.has_changed():
+ raise errors.UncommittedChanges(self.tree)
+
+ def _select_bind_location(self):
+ """Select a location to bind to.
+
+ Preference is:
+ 1. user specified location
+ 2. branch reference location (it's a kind of bind location)
+ 3. previous bind location (it was a good choice once)
+ 4. push location (it's writeable, so committable)
+ 5. parent location (it's pullable, so update-from-able)
+ """
+ if self.new_bound_location is not None:
+ return self.new_bound_location
+ if self.local_branch is not None:
+ old_bound = self.local_branch.get_old_bound_location()
+ if old_bound is not None:
+ return old_bound
+ push_location = self.local_branch.get_push_location()
+ if push_location is not None:
+ return push_location
+ parent = self.local_branch.get_parent()
+ if parent is not None:
+ return parent
+ elif self.referenced_branch is not None:
+ return self.referenced_branch.base
+ raise errors.NoBindLocation(self.bzrdir)
+
+ def apply(self, force=False):
+ """Apply the reconfiguration
+
+ :param force: If true, the reconfiguration is applied even if it will
+ destroy local changes.
+ :raise errors.UncommittedChanges: if the local tree is to be destroyed
+ but contains uncommitted changes.
+ :raise errors.NoBindLocation: if no bind location was specified and
+ none could be autodetected.
+ """
+ if not force:
+ self._check()
+ if self._create_repository:
+ repo = self.bzrdir.create_repository()
+ else:
+ repo = self.repository
+ if self._create_branch:
+ repo.fetch(self.referenced_branch.repository,
+ self.referenced_branch.last_revision())
+ if self._destroy_reference:
+ reference_info = self.referenced_branch.last_revision_info()
+ self.bzrdir.destroy_branch()
+ if self._create_branch:
+ local_branch = self.bzrdir.create_branch()
+ local_branch.set_last_revision_info(*reference_info)
+ else:
+ local_branch = self.local_branch
+ if self._destroy_tree:
+ self.bzrdir.destroy_workingtree()
+ if self._create_tree:
+ self.bzrdir.create_workingtree()
+ if self._unbind:
+ self.local_branch.unbind()
+ if self._bind:
+ bind_location = self._select_bind_location()
+ local_branch.bind(branch.Branch.open(bind_location))
=== added file 'bzrlib/tests/blackbox/test_reconfigure.py'
--- a/bzrlib/tests/blackbox/test_reconfigure.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/blackbox/test_reconfigure.py 2007-09-17 12:45:54 +0000
@@ -0,0 +1,58 @@
+# Copyright (C) 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+from bzrlib import (
+ errors,
+ tests,
+ workingtree,
+ )
+
+
+class TestReconfigure(tests.TestCaseWithTransport):
+
+ def test_no_type(self):
+ branch = self.make_branch('branch')
+ self.run_bzr_error(['No target configuration specified'],
+ 'reconfigure branch')
+
+ def test_branch_to_tree(self):
+ branch = self.make_branch('branch')
+ self.run_bzr('reconfigure --tree branch')
+ tree = workingtree.WorkingTree.open('branch')
+
+ def test_tree_to_branch(self):
+ tree = self.make_branch_and_tree('tree')
+ self.run_bzr('reconfigure --branch tree')
+ self.assertRaises(errors.NoWorkingTree,
+ workingtree.WorkingTree.open, 'tree')
+
+ def test_branch_to_specified_checkout(self):
+ branch = self.make_branch('branch')
+ parent = self.make_branch('parent')
+ self.run_bzr('reconfigure branch --checkout --bind-to parent')
+
+ def test_force(self):
+ tree = self.make_branch_and_tree('tree')
+ self.build_tree(['tree/file'])
+ tree.add('file')
+ self.run_bzr_error(['Working tree ".*" has uncommitted changes'],
+ 'reconfigure --branch tree')
+ self.run_bzr('reconfigure --force --branch tree')
+
+ def test_lightweight_checkout_to_checkout(self):
+ branch = self.make_branch('branch')
+ checkout = branch.create_checkout('checkout', lightweight=True)
+ self.run_bzr('reconfigure --checkout checkout')
=== added file 'bzrlib/tests/test_reconfigure.py'
--- a/bzrlib/tests/test_reconfigure.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/test_reconfigure.py 2007-09-13 01:54:20 +0000
@@ -0,0 +1,150 @@
+# Copyright (C) 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+from bzrlib import (
+ branch as _mod_branch,
+ errors,
+ reconfigure,
+ tests,
+ workingtree,
+ )
+
+
+class TestReconfigure(tests.TestCaseWithTransport):
+
+ def test_tree_to_branch(self):
+ tree = self.make_branch_and_tree('tree')
+ reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
+ reconfiguration.apply()
+ self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
+ 'tree')
+
+ def test_modified_tree_to_branch(self):
+ tree = self.make_branch_and_tree('tree')
+ self.build_tree(['tree/file'])
+ tree.add('file')
+ reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
+ self.assertRaises(errors.UncommittedChanges, reconfiguration.apply)
+ reconfiguration.apply(force=True)
+ self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
+ 'tree')
+
+ def test_branch_to_branch(self):
+ branch = self.make_branch('branch')
+ self.assertRaises(errors.AlreadyBranch,
+ reconfigure.Reconfigure.to_branch, branch.bzrdir)
+
+ def test_repo_to_branch(self):
+ repo = self.make_repository('repo')
+ self.assertRaises(errors.ReconfigurationNotSupported,
+ reconfigure.Reconfigure.to_branch, repo.bzrdir)
+
+ def test_checkout_to_branch(self):
+ branch = self.make_branch('branch')
+ checkout = branch.create_checkout('checkout')
+ reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
+ reconfiguration.apply()
+ self.assertIs(None, checkout.branch.get_bound_location())
+
+ def test_lightweight_checkout_to_branch(self):
+ branch = self.make_branch('branch')
+ checkout = branch.create_checkout('checkout', lightweight=True)
+ checkout.commit('first commit', rev_id='rev1')
+ reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
+ reconfiguration.apply()
+ checkout_branch = checkout.bzrdir.open_branch()
+ self.assertEqual(checkout_branch.bzrdir.root_transport.base,
+ checkout.bzrdir.root_transport.base)
+ self.assertEqual('rev1', checkout_branch.last_revision())
+ repo = checkout.bzrdir.open_repository()
+ repo.get_revision('rev1')
+
+ def test_lightweight_checkout_to_checkout(self):
+ branch = self.make_branch('branch')
+ checkout = branch.create_checkout('checkout', lightweight=True)
+ reconfiguration = reconfigure.Reconfigure.to_checkout(checkout.bzrdir)
+ reconfiguration.apply()
+ checkout_branch = checkout.bzrdir.open_branch()
+ self.assertIsNot(checkout_branch.get_bound_location(), None)
+
+ def test_lightweight_conversion_uses_shared_repo(self):
+ parent = self.make_branch('parent')
+ shared_repo = self.make_repository('repo', shared=True)
+ checkout = parent.create_checkout('repo/checkout', lightweight=True)
+ reconfigure.Reconfigure.to_tree(checkout.bzrdir).apply()
+ checkout_repo = checkout.bzrdir.open_branch().repository
+ self.assertEqual(shared_repo.bzrdir.root_transport.base,
+ checkout_repo.bzrdir.root_transport.base)
+
+ def test_branch_to_tree(self):
+ branch = self.make_branch('branch')
+ reconfiguration=reconfigure.Reconfigure.to_tree(branch.bzrdir)
+ reconfiguration.apply()
+ branch.bzrdir.open_workingtree()
+
+ def test_tree_to_tree(self):
+ tree = self.make_branch_and_tree('tree')
+ self.assertRaises(errors.AlreadyTree, reconfigure.Reconfigure.to_tree,
+ tree.bzrdir)
+
+ def test_select_bind_location(self):
+ branch = self.make_branch('branch')
+ reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
+ self.assertRaises(errors.NoBindLocation,
+ reconfiguration._select_bind_location)
+ branch.set_parent('http://parent')
+ self.assertEqual('http://parent',
+ reconfiguration._select_bind_location())
+ branch.set_push_location('sftp://push')
+ self.assertEqual('sftp://push',
+ reconfiguration._select_bind_location())
+ branch.set_bound_location('bzr:old-bound')
+ branch.set_bound_location(None)
+ self.assertEqual('bzr:old-bound',
+ reconfiguration._select_bind_location())
+ reconfiguration.new_bound_location = 'ftp://user-specified'
+ self.assertEqual('ftp://user-specified',
+ reconfiguration._select_bind_location())
+
+ def test_select_reference_bind_location(self):
+ branch = self.make_branch('branch')
+ checkout = branch.create_checkout('checkout', lightweight=True)
+ reconfiguration = reconfigure.Reconfigure(checkout.bzrdir)
+ self.assertEqual(branch.base,
+ reconfiguration._select_bind_location())
+
+ def test_tree_to_checkout(self):
+ # A tree with no related branches and no supplied bind location cannot
+ # become a checkout
+ parent = self.make_branch('parent')
+
+ tree = self.make_branch_and_tree('tree')
+ reconfiguration = reconfigure.Reconfigure.to_checkout(tree.bzrdir)
+ self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
+ # setting a parent allows it to become a checkout
+ tree.branch.set_parent(parent.base)
+ reconfiguration.apply()
+ # supplying a location allows it to become a checkout
+ tree2 = self.make_branch_and_tree('tree2')
+ reconfiguration = reconfigure.Reconfigure.to_checkout(tree2.bzrdir,
+ parent.base)
+ reconfiguration.apply()
+
+ def test_checkout_to_checkout(self):
+ parent = self.make_branch('parent')
+ checkout = parent.create_checkout('checkout')
+ self.assertRaises(errors.AlreadyCheckout,
+ reconfigure.Reconfigure.to_checkout, checkout.bzrdir)
=== modified file 'NEWS'
--- a/NEWS 2007-09-16 19:29:00 +0000
+++ b/NEWS 2007-09-17 12:46:56 +0000
@@ -11,6 +11,8 @@
FEATURES:
+ * New ``reconfigure`` command (Aaron Bentley)
+
PERFORMANCE:
* Commit in quiet mode is now slightly faster as the information to
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2007-09-16 19:29:00 +0000
+++ b/bzrlib/builtins.py 2007-09-17 12:46:56 +0000
@@ -42,6 +42,7 @@
merge as _mod_merge,
merge_directive,
osutils,
+ reconfigure,
registry,
repository,
revision as _mod_revision,
@@ -4152,6 +4153,49 @@
self.outf.write('%-20s %s\n' % (tag_name, target))
+class cmd_reconfigure(Command):
+ """Reconfigure the type of a bzr directory.
+
+ A target configuration must be specified.
+
+ For checkouts, the bind-to location will be auto-detected if not specified.
+ The order of preference is
+ 1. For a lightweight checkout, the current bound location.
+ 2. For branches that used to be checkouts, the previously-bound location.
+ 3. The push location.
+ 4. The parent location.
+ If none of these is available, --bind-to must be specified.
+ """
+
+ takes_args = ['location?']
+ takes_options = [RegistryOption.from_kwargs('target_type',
+ title='Target type',
+ help='The type to reconfigure the directory to.',
+ value_switches=True, enum_switch=False,
+ branch='Reconfigure to a branch.',
+ tree='Reconfigure to a tree.',
+ checkout='Reconfigure to a checkout.'),
+ Option('bind-to', help='Branch to bind checkout to.',
+ type=str),
+ Option('force',
+ help='Perform reconfiguration even if local changes'
+ ' will be lost.')
+ ]
+
+ def run(self, location=None, target_type=None, bind_to=None, force=False):
+ directory = bzrdir.BzrDir.open(location)
+ if target_type is None:
+ raise BzrCommandError('No target configuration specified')
+ elif target_type == 'branch':
+ reconfiguration = reconfigure.Reconfigure.to_branch(directory)
+ elif target_type == 'tree':
+ reconfiguration = reconfigure.Reconfigure.to_tree(directory)
+ elif target_type == 'checkout':
+ reconfiguration = reconfigure.Reconfigure.to_checkout(directory,
+ bind_to)
+ reconfiguration.apply(force)
+
+
def _create_prefix(cur_transport):
needed = [cur_transport]
# Recurse upwards until we can create a directory successfully
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py 2007-09-13 22:41:38 +0000
+++ b/bzrlib/bzrdir.py 2007-09-17 12:46:56 +0000
@@ -244,6 +244,10 @@
"""
raise NotImplementedError(self.create_branch)
+ def destroy_branch(self):
+ """Destroy the branch in this BzrDir"""
+ raise NotImplementedError(self.destroy_branch)
+
@staticmethod
def create_branch_and_repo(base, force_new_repo=False, format=None):
"""Create a new BzrDir, Branch and Repository at the url 'base'.
@@ -894,6 +898,10 @@
"""See BzrDir.create_branch."""
return self.open_branch()
+ def destroy_branch(self):
+ """See BzrDir.destroy_branch."""
+ raise errors.UnsupportedOperation(self.destroy_branch, self)
+
def create_repository(self, shared=False):
"""See BzrDir.create_repository."""
if shared:
@@ -1070,6 +1078,10 @@
"""See BzrDir.create_branch."""
return self._format.get_branch_format().initialize(self)
+ def destroy_branch(self):
+ """See BzrDir.create_branch."""
+ self.transport.delete_tree('branch')
+
def create_repository(self, shared=False):
"""See BzrDir.create_repository."""
return self._format.repository_format.initialize(self, shared)
=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py 2007-09-06 01:46:00 +0000
+++ b/bzrlib/errors.py 2007-09-13 01:54:49 +0000
@@ -2404,3 +2404,48 @@
class DefaultSMTPConnectionRefused(SMTPConnectionRefused):
_fmt = "Please specify smtp_server. No server at default %(host)s."
+
+
+class BzrDirError(BzrError):
+
+ def __init__(self, bzrdir):
+ import bzrlib.urlutils as urlutils
+ display_url = urlutils.unescape_for_display(bzrdir.root_transport.base,
+ 'ascii')
+ BzrError.__init__(self, bzrdir=bzrdir, display_url=display_url)
+
+
+class AlreadyBranch(BzrDirError):
+
+ _fmt = "'%(display_url)s' is already a branch."
+
+
+class AlreadyTree(BzrDirError):
+
+ _fmt = "'%(display_url)s' is already a tree."
+
+
+class AlreadyCheckout(BzrDirError):
+
+ _fmt = "'%(display_url)s' is already a checkout."
+
+
+class ReconfigurationNotSupported(BzrDirError):
+
+ _fmt = "Requested reconfiguration of '%(display_url)s' is not supported."
+
+
+class NoBindLocation(BzrDirError):
+
+ _fmt = "No location could be found to bind to at %(display_url)s."
+
+
+class UncommittedChanges(BzrError):
+
+ _fmt = 'Working tree "%(display_url)s" has uncommitted changes.'
+
+ def __init__(self, tree):
+ import bzrlib.urlutils as urlutils
+ display_url = urlutils.unescape_for_display(
+ tree.bzrdir.root_transport.base, 'ascii')
+ BzrError.__init__(self, tree=tree, display_url=display_url)
=== modified file 'bzrlib/merge.py'
--- a/bzrlib/merge.py 2007-08-03 01:46:21 +0000
+++ b/bzrlib/merge.py 2007-09-08 06:02:59 +0000
@@ -209,7 +209,7 @@
if check_clean:
self.compare_basis()
if self.this_basis != self.this_rev_id:
- raise BzrCommandError("Working tree has uncommitted changes.")
+ raise errors.UncommittedChanges(self.this_tree)
def compare_basis(self):
try:
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2007-08-22 05:28:32 +0000
+++ b/bzrlib/remote.py 2007-09-14 14:45:55 +0000
@@ -89,6 +89,11 @@
real_branch = self._real_bzrdir.create_branch()
return RemoteBranch(self, self.find_repository(), real_branch)
+ def destroy_branch(self):
+ """See BzrDir.destroy_branch"""
+ self._ensure_real()
+ self._real_bzrdir.destroy_branch()
+
def create_workingtree(self, revision_id=None):
raise errors.NotLocalUrl(self.transport.base)
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2007-09-05 08:18:57 +0000
+++ b/bzrlib/tests/__init__.py 2007-09-13 01:54:49 +0000
@@ -2426,6 +2426,7 @@
'bzrlib.tests.test_permissions',
'bzrlib.tests.test_plugins',
'bzrlib.tests.test_progress',
+ 'bzrlib.tests.test_reconfigure',
'bzrlib.tests.test_reconcile',
'bzrlib.tests.test_registry',
'bzrlib.tests.test_remote',
=== modified file 'bzrlib/tests/blackbox/__init__.py'
--- a/bzrlib/tests/blackbox/__init__.py 2007-09-05 01:54:07 +0000
+++ b/bzrlib/tests/blackbox/__init__.py 2007-09-17 12:46:56 +0000
@@ -84,6 +84,7 @@
'bzrlib.tests.blackbox.test_pull',
'bzrlib.tests.blackbox.test_push',
'bzrlib.tests.blackbox.test_reconcile',
+ 'bzrlib.tests.blackbox.test_reconfigure',
'bzrlib.tests.blackbox.test_remerge',
'bzrlib.tests.blackbox.test_remove',
'bzrlib.tests.blackbox.test_re_sign',
=== modified file 'bzrlib/tests/blackbox/test_merge.py'
--- a/bzrlib/tests/blackbox/test_merge.py 2007-09-05 04:35:21 +0000
+++ b/bzrlib/tests/blackbox/test_merge.py 2007-09-14 13:58:32 +0000
@@ -164,9 +164,8 @@
# test implicit --remember when no parent set, this merge conflicts
self.build_tree(['d'])
tree_b.add('d')
- out = self.run_bzr('merge ../branch_a', retcode=3)
- self.assertEquals(out,
- ('','bzr: ERROR: Working tree has uncommitted changes.\n'))
+ self.run_bzr_error(['Working tree ".*" has uncommitted changes'],
+ 'merge ../branch_a')
self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
# test implicit --remember after resolving conflict
tree_b.commit('commit d')
=== modified file 'bzrlib/tests/bzrdir_implementations/test_bzrdir.py'
--- a/bzrlib/tests/bzrdir_implementations/test_bzrdir.py 2007-09-05 04:35:21 +0000
+++ b/bzrlib/tests/bzrdir_implementations/test_bzrdir.py 2007-09-13 01:54:49 +0000
@@ -47,6 +47,7 @@
ChrootedTestCase,
TestCase,
TestCaseWithTransport,
+ TestNotApplicable,
TestSkipped,
)
from bzrlib.tests.bzrdir_implementations import TestCaseWithBzrDir
@@ -167,6 +168,17 @@
self.failUnlessExists('tree/file')
self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
+ def test_destroy_branch(self):
+ branch = self.make_branch('branch')
+ bzrdir = branch.bzrdir
+ try:
+ bzrdir.destroy_branch()
+ except (errors.UnsupportedOperation, errors.TransportNotPossible):
+ raise TestNotApplicable('Format does not support destroying tree')
+ self.assertRaises(errors.NotBranchError, bzrdir.open_branch)
+ bzrdir.create_branch()
+ bzrdir.open_branch()
+
def test_open_workingtree_raises_no_working_tree(self):
"""BzrDir.open_workingtree() should raise NoWorkingTree (rather than
e.g. NotLocalUrl) if there is no working tree.
More information about the bazaar-commits
mailing list