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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Reconfigure a bzrdir into a new tree/branch/repository layout"""
19
19
from bzrlib import (
31
30
self.repository = self.bzrdir.find_repository()
32
31
except errors.NoRepositoryPresent:
33
32
self.repository = None
35
if (self.repository.bzrdir.root_transport.base ==
36
self.bzrdir.root_transport.base):
37
self.local_repository = self.repository
39
self.local_repository = None
41
34
branch = self.bzrdir.open_branch()
42
35
if branch.bzrdir.root_transport.base == bzrdir.root_transport.base:
123
115
raise errors.AlreadyLightweightCheckout(bzrdir)
124
116
return reconfiguration
127
def to_use_shared(klass, bzrdir):
128
"""Convert a standalone branch into a repository branch"""
129
reconfiguration = klass(bzrdir)
130
reconfiguration._set_use_shared(use_shared=True)
131
if not reconfiguration.changes_planned():
132
raise errors.AlreadyUsingShared(bzrdir)
133
return reconfiguration
136
def to_standalone(klass, bzrdir):
137
"""Convert a repository branch into a standalone branch"""
138
reconfiguration = klass(bzrdir)
139
reconfiguration._set_use_shared(use_shared=False)
140
if not reconfiguration.changes_planned():
141
raise errors.AlreadyStandalone(bzrdir)
142
return reconfiguration
145
def set_repository_trees(klass, bzrdir, with_trees):
146
"""Adjust a repository's working tree presence default"""
147
reconfiguration = klass(bzrdir)
148
if not reconfiguration.repository.is_shared():
149
raise errors.ReconfigurationNotSupported(reconfiguration.bzrdir)
150
if with_trees and reconfiguration.repository.make_working_trees():
151
raise errors.AlreadyWithTrees(bzrdir)
153
and not reconfiguration.repository.make_working_trees()):
154
raise errors.AlreadyWithNoTrees(bzrdir)
156
reconfiguration._repository_trees = with_trees
157
return reconfiguration
159
118
def _plan_changes(self, want_tree, want_branch, want_bound,
161
120
"""Determine which changes are needed to assume the configuration"""
196
155
if want_tree and self.tree is None:
197
156
self._create_tree = True
199
def _set_use_shared(self, use_shared=None):
200
if use_shared is None:
203
if self.local_repository is not None:
204
self._destroy_repository = True
206
if self.local_repository is None:
207
self._create_repository = True
209
158
def changes_planned(self):
210
159
"""Return True if changes are planned, False otherwise"""
211
160
return (self._unbind or self._bind or self._destroy_tree
212
161
or self._create_tree or self._destroy_reference
213
162
or self._create_branch or self._create_repository
214
or self._create_reference or self._destroy_repository)
163
or self._create_reference)
216
165
def _check(self):
217
166
"""Raise if reconfiguration would destroy local changes"""
219
168
changes = self.tree.changes_from(self.tree.basis_tree())
220
169
if changes.has_changed():
221
170
raise errors.UncommittedChanges(self.tree)
222
if self._create_reference and self.local_branch is not None:
223
reference_branch = branch.Branch.open(self._select_bind_location())
224
if (reference_branch.last_revision() !=
225
self.local_branch.last_revision()):
226
raise errors.UnsyncedBranches(self.bzrdir, reference_branch)
228
172
def _select_bind_location(self):
229
173
"""Select a location to bind or create a reference to.
270
214
if self._create_repository:
271
215
repo = self.bzrdir.create_repository()
272
if self.local_branch and not self._destroy_branch:
273
repo.fetch(self.local_branch.repository,
274
self.local_branch.last_revision())
276
217
repo = self.repository
277
218
if self._create_branch and self.referenced_branch is not None:
282
223
if self._destroy_repository:
283
224
if self._create_reference:
284
225
reference_branch.repository.fetch(self.repository)
285
elif self.local_branch is not None and not self._destroy_branch:
286
up = self.local_branch.bzrdir.root_transport.clone('..')
287
up_bzrdir = bzrdir.BzrDir.open_containing_from_transport(up)[0]
288
new_repo = up_bzrdir.find_repository()
289
new_repo.fetch(self.repository)
290
226
last_revision_info = None
291
227
if self._destroy_reference:
292
228
last_revision_info = self.referenced_branch.last_revision_info()
318
254
local_branch.bind(branch.Branch.open(bind_location))
319
255
if self._destroy_repository:
320
256
self.bzrdir.destroy_repository()
321
if self._repository_trees is not None:
322
repo.set_make_working_trees(self._repository_trees)