48
48
self._unbind = False
50
50
self._destroy_reference = False
51
self._create_reference = False
52
self._destroy_branch = False
51
53
self._create_branch = False
52
54
self._destroy_tree = False
53
55
self._create_tree = False
54
56
self._create_repository = False
57
self._destroy_repository = False
57
60
def to_branch(bzrdir):
98
101
reconfiguration = Reconfigure(bzrdir, bound_location)
99
102
reconfiguration._plan_changes(want_tree=True, want_branch=True,
103
want_bound=True, want_reference=False)
101
104
if not reconfiguration.changes_planned():
102
105
raise errors.AlreadyCheckout(bzrdir)
103
106
return reconfiguration
105
def _plan_changes(self, want_tree, want_branch, want_bound):
109
def to_lightweight_checkout(klass, bzrdir, reference_location=None):
110
"""Make a Reconfiguration to convert bzrdir into a lightweight checkout
112
:param bzrdir: The bzrdir to reconfigure
113
:param bound_location: The location the checkout should be bound to.
114
:raise errors.AlreadyLightweightCheckout: if bzrdir is already a
116
:raise errors.ReconfigurationNotSupported: if bzrdir does not contain
117
a branch or branch reference
119
reconfiguration = klass(bzrdir, reference_location)
120
reconfiguration._plan_changes(want_tree=True, want_branch=False,
121
want_bound=False, want_reference=True)
122
if not reconfiguration.changes_planned():
123
raise errors.AlreadyLightweightCheckout(bzrdir)
124
return reconfiguration
126
def _plan_changes(self, want_tree, want_branch, want_bound,
106
128
"""Determine which changes are needed to assume the configuration"""
129
if not want_branch and not want_reference:
130
raise errors.ReconfigurationNotSupported(self.bzrdir)
131
if want_branch and want_reference:
132
raise errors.ReconfigurationNotSupported(self.bzrdir)
133
if (want_branch or want_reference) and (self.local_branch is None and
134
self.referenced_branch
136
raise errors.ReconfigurationNotSupported(self.bzrdir)
107
137
if self.repository is None:
108
self._create_repository = True
138
if not want_reference:
139
self._create_repository = True
141
if want_reference and (self.repository.bzrdir.root_transport.base
142
== self.bzrdir.root_transport.base):
143
self._destroy_repository = True
144
if self.referenced_branch is None:
146
self._create_reference = True
148
if not want_reference:
149
self._destroy_reference = True
109
150
if self.local_branch is None:
110
151
if want_branch is True:
111
if self.referenced_branch is not None:
112
self._destroy_reference = True
113
self._create_branch = True
117
raise errors.ReconfigurationNotSupported(self.bzrdir)
152
self._create_branch = True
120
157
if self.local_branch.get_bound_location() is None:
141
178
raise errors.UncommittedChanges(self.tree)
143
180
def _select_bind_location(self):
144
"""Select a location to bind to.
181
"""Select a location to bind or create a reference to.
147
184
1. user specified location
148
185
2. branch reference location (it's a kind of bind location)
149
3. previous bind location (it was a good choice once)
150
4. push location (it's writeable, so committable)
151
5. parent location (it's pullable, so update-from-able)
186
3. current bind location
187
4. previous bind location (it was a good choice once)
188
5. push location (it's writeable, so committable)
189
6. parent location (it's pullable, so update-from-able)
153
191
if self.new_bound_location is not None:
154
192
return self.new_bound_location
155
193
if self.local_branch is not None:
194
bound = self.local_branch.get_bound_location()
195
if bound is not None:
156
197
old_bound = self.local_branch.get_old_bound_location()
157
198
if old_bound is not None:
188
229
if self._destroy_reference:
189
230
reference_info = self.referenced_branch.last_revision_info()
190
231
self.bzrdir.destroy_branch()
232
if self._destroy_branch:
233
reference_info = self.local_branch.last_revision_info()
234
self.bzrdir.destroy_branch()
191
235
if self._create_branch:
192
236
local_branch = self.bzrdir.create_branch()
193
237
local_branch.set_last_revision_info(*reference_info)
195
239
local_branch = self.local_branch
240
if self._create_reference:
241
reference_branch = branch.Branch.open(self._select_bind_location())
242
format = branch.BranchReferenceFormat().initialize(self.bzrdir,
196
244
if self._destroy_tree:
197
245
self.bzrdir.destroy_workingtree()
198
246
if self._create_tree: