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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Reconfigure a bzrdir into a new tree/branch/repository layout"""
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.
19
24
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"
25
73
class Reconfigure(object):
27
75
def __init__(self, bzrdir, new_bound_location=None):
28
76
self.bzrdir = bzrdir
29
77
self.new_bound_location = new_bound_location
78
self.local_repository = None
31
80
self.repository = self.bzrdir.find_repository()
32
81
except errors.NoRepositoryPresent:
33
82
self.repository = None
83
self.local_repository = None
35
85
if (self.repository.bzrdir.root_transport.base ==
36
86
self.bzrdir.root_transport.base):
216
266
def _check(self):
217
267
"""Raise if reconfiguration would destroy local changes"""
218
268
if self._destroy_tree:
219
changes = self.tree.changes_from(self.tree.basis_tree())
220
if changes.has_changed():
269
# XXX: What about pending merges ? -- vila 20090629
270
if self.tree.has_changes(self.tree.basis_tree()):
221
271
raise errors.UncommittedChanges(self.tree)
222
272
if self._create_reference and self.local_branch is not None:
223
273
reference_branch = branch.Branch.open(self._select_bind_location())
270
320
if self._create_repository:
271
repo = self.bzrdir.create_repository()
321
if self.local_branch and not self._destroy_branch:
322
old_repo = self.local_branch.repository
323
elif self._create_branch and self.referenced_branch is not None:
324
old_repo = self.referenced_branch.repository
327
if old_repo is not None:
328
repository_format = old_repo._format
330
repository_format = None
331
if repository_format is not None:
332
repo = repository_format.initialize(self.bzrdir)
334
repo = self.bzrdir.create_repository()
272
335
if self.local_branch and not self._destroy_branch:
273
336
repo.fetch(self.local_branch.repository,
274
337
self.local_branch.last_revision())
302
365
local_branch.set_last_revision_info(*last_revision_info)
303
366
if self._destroy_reference:
304
367
self.referenced_branch.tags.merge_to(local_branch.tags)
368
self.referenced_branch.update_references(local_branch)
306
370
local_branch = self.local_branch
307
371
if self._create_reference: