13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Reconfigure a bzrdir into a new tree/branch/repository layout.
19
Various types of reconfiguration operation are available either by
20
constructing a class or using a factory method on Reconfigure.
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Reconfigure a bzrdir into a new tree/branch/repository layout"""
24
19
from bzrlib import (
34
# TODO: common base class for all reconfigure operations, making no
35
# assumptions about what kind of change will be done.
38
class ReconfigureStackedOn(object):
39
"""Reconfigures a branch to be stacked on another branch."""
41
def apply(self, bzrdir, stacked_on_url):
42
branch = bzrdir.open_branch()
43
# it may be a path relative to the cwd or a url; the branch wants
44
# a path relative to itself...
45
on_url = urlutils.relative_url(branch.base,
46
urlutils.normalize_url(stacked_on_url))
49
branch.set_stacked_on_url(on_url)
50
if not trace.is_quiet():
52
"%s is now stacked on %s\n"
53
% (branch.base, branch.get_stacked_on_url()))
58
class ReconfigureUnstacked(object):
60
def apply(self, bzrdir):
61
branch = bzrdir.open_branch()
64
branch.set_stacked_on_url(None)
65
if not trace.is_quiet():
67
"%s is now not stacked\n"
73
25
class Reconfigure(object):
75
27
def __init__(self, bzrdir, new_bound_location=None):
76
28
self.bzrdir = bzrdir
77
29
self.new_bound_location = new_bound_location
78
self.local_repository = None
80
31
self.repository = self.bzrdir.find_repository()
81
32
except errors.NoRepositoryPresent:
82
33
self.repository = None
83
self.local_repository = None
85
35
if (self.repository.bzrdir.root_transport.base ==
86
36
self.bzrdir.root_transport.base):
191
140
raise errors.AlreadyStandalone(bzrdir)
192
141
return reconfiguration
195
def set_repository_trees(klass, bzrdir, with_trees):
196
"""Adjust a repository's working tree presence default"""
197
reconfiguration = klass(bzrdir)
198
if not reconfiguration.repository.is_shared():
199
raise errors.ReconfigurationNotSupported(reconfiguration.bzrdir)
200
if with_trees and reconfiguration.repository.make_working_trees():
201
raise errors.AlreadyWithTrees(bzrdir)
203
and not reconfiguration.repository.make_working_trees()):
204
raise errors.AlreadyWithNoTrees(bzrdir)
206
reconfiguration._repository_trees = with_trees
207
return reconfiguration
209
143
def _plan_changes(self, want_tree, want_branch, want_bound,
211
145
"""Determine which changes are needed to assume the configuration"""
266
200
def _check(self):
267
201
"""Raise if reconfiguration would destroy local changes"""
268
if self._destroy_tree and self.tree.has_changes():
202
if self._destroy_tree:
203
changes = self.tree.changes_from(self.tree.basis_tree())
204
if changes.has_changed():
269
205
raise errors.UncommittedChanges(self.tree)
270
206
if self._create_reference and self.local_branch is not None:
271
207
reference_branch = branch.Branch.open(self._select_bind_location())
318
254
if self._create_repository:
319
if self.local_branch and not self._destroy_branch:
320
old_repo = self.local_branch.repository
321
elif self._create_branch and self.referenced_branch is not None:
322
old_repo = self.referenced_branch.repository
325
if old_repo is not None:
326
repository_format = old_repo._format
328
repository_format = None
329
if repository_format is not None:
330
repo = repository_format.initialize(self.bzrdir)
332
repo = self.bzrdir.create_repository()
255
repo = self.bzrdir.create_repository()
333
256
if self.local_branch and not self._destroy_branch:
334
257
repo.fetch(self.local_branch.repository,
335
258
self.local_branch.last_revision())
363
286
local_branch.set_last_revision_info(*last_revision_info)
364
287
if self._destroy_reference:
365
288
self.referenced_branch.tags.merge_to(local_branch.tags)
366
self.referenced_branch.update_references(local_branch)
368
290
local_branch = self.local_branch
369
291
if self._create_reference: