1
# Copyright (C) 2007-2010 Canonical Ltd
1
# Copyright (C) 2007 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
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.
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):
82
34
self.repository = None
83
35
self.local_repository = None
85
if (self.repository.user_url == self.bzrdir.user_url):
37
if (self.repository.bzrdir.root_transport.base ==
38
self.bzrdir.root_transport.base):
86
39
self.local_repository = self.repository
88
41
self.local_repository = None
90
43
branch = self.bzrdir.open_branch()
91
if branch.user_url == bzrdir.user_url:
44
if branch.bzrdir.root_transport.base == bzrdir.root_transport.base:
92
45
self.local_branch = branch
93
46
self.referenced_branch = None
216
169
if not want_reference:
217
170
self._create_repository = True
219
if want_reference and (
220
self.repository.user_url == self.bzrdir.user_url):
172
if want_reference and (self.repository.bzrdir.root_transport.base
173
== self.bzrdir.root_transport.base):
221
174
if not self.repository.is_shared():
222
175
self._destroy_repository = True
223
176
if self.referenced_branch is None:
265
218
def _check(self):
266
219
"""Raise if reconfiguration would destroy local changes"""
267
if self._destroy_tree and self.tree.has_changes():
220
if self._destroy_tree:
221
changes = self.tree.changes_from(self.tree.basis_tree())
222
if changes.has_changed():
268
223
raise errors.UncommittedChanges(self.tree)
269
224
if self._create_reference and self.local_branch is not None:
270
225
reference_branch = branch.Branch.open(self._select_bind_location())
343
298
if self._create_reference:
344
299
reference_branch.repository.fetch(self.repository)
345
300
elif self.local_branch is not None and not self._destroy_branch:
346
up = self.local_branch.user_transport.clone('..')
301
up = self.local_branch.bzrdir.root_transport.clone('..')
347
302
up_bzrdir = bzrdir.BzrDir.open_containing_from_transport(up)[0]
348
303
new_repo = up_bzrdir.find_repository()
349
304
new_repo.fetch(self.repository)
367
322
local_branch = self.local_branch
368
323
if self._create_reference:
369
324
format = branch.BranchReferenceFormat().initialize(self.bzrdir,
370
target_branch=reference_branch)
371
326
if self._destroy_tree:
372
327
self.bzrdir.destroy_workingtree()
373
328
if self._create_tree: