~bzr-pqm/bzr/bzr.dev

4597.9.2 by Vincent Ladeuil
Merge bzr.dev into cleanup
1
# Copyright (C) 2007-2010 Canonical Ltd
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
16
6207.3.3 by jelmer at samba
Fix tests and the like.
17
"""Reconfigure a controldir into a new tree/branch/repository layout.
4509.3.38 by Martin Pool
Move reconfigure --stacked-on core code into reconfigure.py
18
19
Various types of reconfiguration operation are available either by
20
constructing a class or using a factory method on Reconfigure.
21
"""
22
6379.6.7 by Jelmer Vernooij
Move importing from future until after doc string, otherwise the doc string will disappear.
23
from __future__ import absolute_import
24
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
25
26
from bzrlib import (
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
27
    branch,
6207.3.3 by jelmer at samba
Fix tests and the like.
28
    controldir,
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
29
    errors,
4509.3.38 by Martin Pool
Move reconfigure --stacked-on core code into reconfigure.py
30
    trace,
31
    ui,
32
    urlutils,
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
33
    )
6138.3.4 by Jonathan Riddell
add gettext() to uses of trace.note()
34
from bzrlib.i18n import gettext
4509.3.38 by Martin Pool
Move reconfigure --stacked-on core code into reconfigure.py
35
36
# TODO: common base class for all reconfigure operations, making no
37
# assumptions about what kind of change will be done.
38
39
40
class ReconfigureStackedOn(object):
41
    """Reconfigures a branch to be stacked on another branch."""
42
43
    def apply(self, bzrdir, stacked_on_url):
44
        branch = bzrdir.open_branch()
45
        # it may be a path relative to the cwd or a url; the branch wants
46
        # a path relative to itself...
47
        on_url = urlutils.relative_url(branch.base,
48
            urlutils.normalize_url(stacked_on_url))
49
        branch.lock_write()
50
        try:
51
            branch.set_stacked_on_url(on_url)
52
            if not trace.is_quiet():
6138.3.4 by Jonathan Riddell
add gettext() to uses of trace.note()
53
                ui.ui_factory.note(gettext(
54
                    "{0} is now stacked on {1}\n").format(
55
                      branch.base, branch.get_stacked_on_url()))
4509.3.38 by Martin Pool
Move reconfigure --stacked-on core code into reconfigure.py
56
        finally:
57
            branch.unlock()
58
59
4509.3.39 by Martin Pool
Move reconfigure --unstacked to reconfigure.py
60
class ReconfigureUnstacked(object):
61
62
    def apply(self, bzrdir):
63
        branch = bzrdir.open_branch()
64
        branch.lock_write()
65
        try:
66
            branch.set_stacked_on_url(None)
67
            if not trace.is_quiet():
6138.3.4 by Jonathan Riddell
add gettext() to uses of trace.note()
68
                ui.ui_factory.note(gettext(
69
                    "%s is now not stacked\n")
4509.3.39 by Martin Pool
Move reconfigure --unstacked to reconfigure.py
70
                    % (branch.base,))
71
        finally:
72
            branch.unlock()
73
74
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
75
class Reconfigure(object):
76
3983.3.2 by Marius Kruger
make changes directly in set_repository_trees()
77
    def __init__(self, bzrdir, new_bound_location=None):
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
78
        self.bzrdir = bzrdir
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
79
        self.new_bound_location = new_bound_location
4509.1.1 by Jelmer Vernooij
Fix for unbound variable in reconfiguring lightweight checkout
80
        self.local_repository = None
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
81
        try:
2796.2.10 by Aaron Bentley
Ensure that shared repositories are used where possible
82
            self.repository = self.bzrdir.find_repository()
2796.2.7 by Aaron Bentley
Implement converting a lightweight checkout to a branch
83
        except errors.NoRepositoryPresent:
84
            self.repository = None
4324.2.1 by Jelmer Vernooij
Make sure class member local_repository of reconfigure is initialized.
85
            self.local_repository = None
3311.2.2 by Aaron Bentley
Flesh out to_sharing
86
        else:
5158.6.9 by Martin Pool
Simplify various code to use user_url
87
            if (self.repository.user_url == self.bzrdir.user_url):
3311.2.2 by Aaron Bentley
Flesh out to_sharing
88
                self.local_repository = self.repository
89
            else:
90
                self.local_repository = None
2796.2.7 by Aaron Bentley
Implement converting a lightweight checkout to a branch
91
        try:
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
92
            branch = self.bzrdir.open_branch()
5158.6.9 by Martin Pool
Simplify various code to use user_url
93
            if branch.user_url == bzrdir.user_url:
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
94
                self.local_branch = branch
95
                self.referenced_branch = None
96
            else:
97
                self.local_branch = None
98
                self.referenced_branch = branch
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
99
        except errors.NotBranchError:
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
100
            self.local_branch = None
2796.2.9 by Aaron Bentley
Ensure conversion from lightweight checkout works
101
            self.referenced_branch = None
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
102
        try:
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
103
            self.tree = bzrdir.open_workingtree()
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
104
        except errors.NoWorkingTree:
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
105
            self.tree = None
2796.2.14 by Aaron Bentley
Updates from review
106
        self._unbind = False
107
        self._bind = False
108
        self._destroy_reference = False
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
109
        self._create_reference = False
110
        self._destroy_branch = False
2796.2.14 by Aaron Bentley
Updates from review
111
        self._create_branch = False
112
        self._destroy_tree = False
113
        self._create_tree = False
114
        self._create_repository = False
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
115
        self._destroy_repository = False
3983.3.7 by Marius Kruger
apply changes in apply again
116
        self._repository_trees = None
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
117
118
    @staticmethod
119
    def to_branch(bzrdir):
2796.2.16 by Aaron Bentley
Documentation updates from review
120
        """Return a Reconfiguration to convert this bzrdir into a branch
121
122
        :param bzrdir: The bzrdir to reconfigure
123
        :raise errors.AlreadyBranch: if bzrdir is already a branch
124
        """
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
125
        reconfiguration = Reconfigure(bzrdir)
2796.2.15 by Aaron Bentley
More updates from review
126
        reconfiguration._plan_changes(want_tree=False, want_branch=True,
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
127
                                      want_bound=False, want_reference=False)
2796.2.14 by Aaron Bentley
Updates from review
128
        if not reconfiguration.changes_planned():
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
129
            raise errors.AlreadyBranch(bzrdir)
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
130
        return reconfiguration
131
132
    @staticmethod
133
    def to_tree(bzrdir):
2796.2.16 by Aaron Bentley
Documentation updates from review
134
        """Return a Reconfiguration to convert this bzrdir into a tree
135
136
        :param bzrdir: The bzrdir to reconfigure
137
        :raise errors.AlreadyTree: if bzrdir is already a tree
138
        """
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
139
        reconfiguration = Reconfigure(bzrdir)
2796.2.15 by Aaron Bentley
More updates from review
140
        reconfiguration._plan_changes(want_tree=True, want_branch=True,
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
141
                                      want_bound=False, want_reference=False)
2796.2.14 by Aaron Bentley
Updates from review
142
        if not reconfiguration.changes_planned():
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
143
            raise errors.AlreadyTree(bzrdir)
144
        return reconfiguration
145
146
    @staticmethod
147
    def to_checkout(bzrdir, bound_location=None):
2796.2.16 by Aaron Bentley
Documentation updates from review
148
        """Return a Reconfiguration to convert this bzrdir into a checkout
149
150
        :param bzrdir: The bzrdir to reconfigure
151
        :param bound_location: The location the checkout should be bound to.
152
        :raise errors.AlreadyCheckout: if bzrdir is already a checkout
153
        """
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
154
        reconfiguration = Reconfigure(bzrdir, bound_location)
2796.2.15 by Aaron Bentley
More updates from review
155
        reconfiguration._plan_changes(want_tree=True, want_branch=True,
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
156
                                      want_bound=True, want_reference=False)
2796.2.14 by Aaron Bentley
Updates from review
157
        if not reconfiguration.changes_planned():
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
158
            raise errors.AlreadyCheckout(bzrdir)
159
        return reconfiguration
160
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
161
    @classmethod
162
    def to_lightweight_checkout(klass, bzrdir, reference_location=None):
163
        """Make a Reconfiguration to convert bzrdir into a lightweight checkout
164
165
        :param bzrdir: The bzrdir to reconfigure
166
        :param bound_location: The location the checkout should be bound to.
167
        :raise errors.AlreadyLightweightCheckout: if bzrdir is already a
168
            lightweight checkout
169
        """
170
        reconfiguration = klass(bzrdir, reference_location)
171
        reconfiguration._plan_changes(want_tree=True, want_branch=False,
172
                                      want_bound=False, want_reference=True)
173
        if not reconfiguration.changes_planned():
174
            raise errors.AlreadyLightweightCheckout(bzrdir)
175
        return reconfiguration
176
3311.2.1 by Aaron Bentley
Initial make-sharing functionality
177
    @classmethod
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
178
    def to_use_shared(klass, bzrdir):
179
        """Convert a standalone branch into a repository branch"""
3311.2.1 by Aaron Bentley
Initial make-sharing functionality
180
        reconfiguration = klass(bzrdir)
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
181
        reconfiguration._set_use_shared(use_shared=True)
3311.2.2 by Aaron Bentley
Flesh out to_sharing
182
        if not reconfiguration.changes_planned():
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
183
            raise errors.AlreadyUsingShared(bzrdir)
3311.2.1 by Aaron Bentley
Initial make-sharing functionality
184
        return reconfiguration
185
3311.2.4 by Aaron Bentley
Implement conversion to standalone
186
    @classmethod
187
    def to_standalone(klass, bzrdir):
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
188
        """Convert a repository branch into a standalone branch"""
3311.2.4 by Aaron Bentley
Implement conversion to standalone
189
        reconfiguration = klass(bzrdir)
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
190
        reconfiguration._set_use_shared(use_shared=False)
3311.2.4 by Aaron Bentley
Implement conversion to standalone
191
        if not reconfiguration.changes_planned():
192
            raise errors.AlreadyStandalone(bzrdir)
193
        return reconfiguration
194
3921.4.2 by Matthew Fuller
Add support in Reconfigure for manipulating the repository setting for
195
    @classmethod
196
    def set_repository_trees(klass, bzrdir, with_trees):
3983.3.2 by Marius Kruger
make changes directly in set_repository_trees()
197
        """Adjust a repository's working tree presence default"""
198
        reconfiguration = klass(bzrdir)
3921.4.10 by Matthew Fuller
Stop trying to use _plan_changes() wholesale and just move all the
199
        if not reconfiguration.repository.is_shared():
200
            raise errors.ReconfigurationNotSupported(reconfiguration.bzrdir)
3983.3.2 by Marius Kruger
make changes directly in set_repository_trees()
201
        if with_trees and reconfiguration.repository.make_working_trees():
202
            raise errors.AlreadyWithTrees(bzrdir)
3983.3.11 by Vincent Ladeuil
Fix indentation as per Aaron's review and then some.
203
        elif (not with_trees
204
              and not reconfiguration.repository.make_working_trees()):
3983.3.2 by Marius Kruger
make changes directly in set_repository_trees()
205
            raise errors.AlreadyWithNoTrees(bzrdir)
206
        else:
3983.3.7 by Marius Kruger
apply changes in apply again
207
            reconfiguration._repository_trees = with_trees
3921.4.2 by Matthew Fuller
Add support in Reconfigure for manipulating the repository setting for
208
        return reconfiguration
209
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
210
    def _plan_changes(self, want_tree, want_branch, want_bound,
3921.4.9 by Matthew Fuller
Back out _plan_changes() changes for trees frobbing. It's way more
211
                      want_reference):
2796.2.10 by Aaron Bentley
Ensure that shared repositories are used where possible
212
        """Determine which changes are needed to assume the configuration"""
3921.4.9 by Matthew Fuller
Back out _plan_changes() changes for trees frobbing. It's way more
213
        if not want_branch and not want_reference:
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
214
            raise errors.ReconfigurationNotSupported(self.bzrdir)
215
        if want_branch and want_reference:
216
            raise errors.ReconfigurationNotSupported(self.bzrdir)
2796.2.7 by Aaron Bentley
Implement converting a lightweight checkout to a branch
217
        if self.repository is None:
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
218
            if not want_reference:
219
                self._create_repository = True
220
        else:
5158.6.9 by Martin Pool
Simplify various code to use user_url
221
            if want_reference and (
222
                self.repository.user_url == self.bzrdir.user_url):
2796.2.25 by Aaron Bentley
Avoid destroying shared repositories
223
                if not self.repository.is_shared():
224
                    self._destroy_repository = True
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
225
        if self.referenced_branch is None:
226
            if want_reference:
227
                self._create_reference = True
2796.2.31 by Aaron Bentley
Fetch tags to reference branch when converting to checkout
228
                if self.local_branch is not None:
229
                    self._destroy_branch = True
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
230
        else:
231
            if not want_reference:
232
                self._destroy_reference = True
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
233
        if self.local_branch is None:
2796.2.15 by Aaron Bentley
More updates from review
234
            if want_branch is True:
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
235
                self._create_branch = True
236
                if want_bound:
237
                    self._bind = True
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
238
        else:
2796.2.15 by Aaron Bentley
More updates from review
239
            if want_bound:
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
240
                if self.local_branch.get_bound_location() is None:
2796.2.14 by Aaron Bentley
Updates from review
241
                    self._bind = True
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
242
            else:
243
                if self.local_branch.get_bound_location() is not None:
2796.2.14 by Aaron Bentley
Updates from review
244
                    self._unbind = True
2796.2.15 by Aaron Bentley
More updates from review
245
        if not want_tree and self.tree is not None:
2796.2.14 by Aaron Bentley
Updates from review
246
            self._destroy_tree = True
2796.2.15 by Aaron Bentley
More updates from review
247
        if want_tree and self.tree is None:
2796.2.14 by Aaron Bentley
Updates from review
248
            self._create_tree = True
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
249
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
250
    def _set_use_shared(self, use_shared=None):
251
        if use_shared is None:
3311.2.1 by Aaron Bentley
Initial make-sharing functionality
252
            return
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
253
        if use_shared:
3311.2.2 by Aaron Bentley
Flesh out to_sharing
254
            if self.local_repository is not None:
255
                self._destroy_repository = True
3311.2.4 by Aaron Bentley
Implement conversion to standalone
256
        else:
257
            if self.local_repository is None:
258
                self._create_repository = True
3311.2.1 by Aaron Bentley
Initial make-sharing functionality
259
2796.2.14 by Aaron Bentley
Updates from review
260
    def changes_planned(self):
2796.2.11 by Aaron Bentley
Cleanups
261
        """Return True if changes are planned, False otherwise"""
2796.2.14 by Aaron Bentley
Updates from review
262
        return (self._unbind or self._bind or self._destroy_tree
263
                or self._create_tree or self._destroy_reference
2796.2.26 by Aaron Bentley
Support converting standalone tree to lightweight checkout
264
                or self._create_branch or self._create_repository
3983.3.5 by Marius Kruger
put bracket back where we found it
265
                or self._create_reference or self._destroy_repository)
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
266
267
    def _check(self):
2796.2.11 by Aaron Bentley
Cleanups
268
        """Raise if reconfiguration would destroy local changes"""
4721.3.2 by Vincent Ladeuil
Simplify mutable_tree.has_changes() and update call sites.
269
        if self._destroy_tree and self.tree.has_changes():
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
270
                raise errors.UncommittedChanges(self.tree)
3338.1.1 by Aaron Bentley
Raise an error when converting a branch to a lightweight checkout loses data
271
        if self._create_reference and self.local_branch is not None:
272
            reference_branch = branch.Branch.open(self._select_bind_location())
273
            if (reference_branch.last_revision() !=
274
                self.local_branch.last_revision()):
275
                raise errors.UnsyncedBranches(self.bzrdir, reference_branch)
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
276
277
    def _select_bind_location(self):
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
278
        """Select a location to bind or create a reference to.
2796.2.11 by Aaron Bentley
Cleanups
279
280
        Preference is:
281
        1. user specified location
282
        2. branch reference location (it's a kind of bind location)
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
283
        3. current bind location
284
        4. previous bind location (it was a good choice once)
285
        5. push location (it's writeable, so committable)
286
        6. parent location (it's pullable, so update-from-able)
2796.2.11 by Aaron Bentley
Cleanups
287
        """
288
        if self.new_bound_location is not None:
289
            return self.new_bound_location
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
290
        if self.local_branch is not None:
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
291
            bound = self.local_branch.get_bound_location()
292
            if bound is not None:
293
                return bound
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
294
            old_bound = self.local_branch.get_old_bound_location()
295
            if old_bound is not None:
296
                return old_bound
297
            push_location = self.local_branch.get_push_location()
298
            if push_location is not None:
299
                return push_location
300
            parent = self.local_branch.get_parent()
301
            if parent is not None:
302
                return parent
2796.2.9 by Aaron Bentley
Ensure conversion from lightweight checkout works
303
        elif self.referenced_branch is not None:
304
            return self.referenced_branch.base
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
305
        raise errors.NoBindLocation(self.bzrdir)
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
306
307
    def apply(self, force=False):
2796.2.16 by Aaron Bentley
Documentation updates from review
308
        """Apply the reconfiguration
309
310
        :param force: If true, the reconfiguration is applied even if it will
311
            destroy local changes.
312
        :raise errors.UncommittedChanges: if the local tree is to be destroyed
313
            but contains uncommitted changes.
314
        :raise errors.NoBindLocation: if no bind location was specified and
315
            none could be autodetected.
316
        """
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
317
        if not force:
318
            self._check()
2796.2.14 by Aaron Bentley
Updates from review
319
        if self._create_repository:
4297.4.5 by Martin von Gagern
Use repository format from exactly the same repository we want to fetch from.
320
            if self.local_branch and not self._destroy_branch:
321
                old_repo = self.local_branch.repository
322
            elif self._create_branch and self.referenced_branch is not None:
323
                old_repo = self.referenced_branch.repository
324
            else:
325
                old_repo = None
326
            if old_repo is not None:
327
                repository_format = old_repo._format
328
            else:
329
                repository_format = None
4297.4.3 by Martin von Gagern
Cleaner implementation of reconfigure.
330
            if repository_format is not None:
331
                repo = repository_format.initialize(self.bzrdir)
332
            else:
333
                repo = self.bzrdir.create_repository()
3311.2.4 by Aaron Bentley
Implement conversion to standalone
334
            if self.local_branch and not self._destroy_branch:
335
                repo.fetch(self.local_branch.repository,
336
                           self.local_branch.last_revision())
2796.2.10 by Aaron Bentley
Ensure that shared repositories are used where possible
337
        else:
338
            repo = self.repository
2796.2.23 by Aaron Bentley
Add support for reconfiguring repositories into branches or trees
339
        if self._create_branch and self.referenced_branch is not None:
2796.2.10 by Aaron Bentley
Ensure that shared repositories are used where possible
340
            repo.fetch(self.referenced_branch.repository,
341
                       self.referenced_branch.last_revision())
2796.2.30 by Aaron Bentley
Reconfigure can safely be interrupted while fetching (#179316)
342
        if self._create_reference:
343
            reference_branch = branch.Branch.open(self._select_bind_location())
344
        if self._destroy_repository:
345
            if self._create_reference:
346
                reference_branch.repository.fetch(self.repository)
3311.2.1 by Aaron Bentley
Initial make-sharing functionality
347
            elif self.local_branch is not None and not self._destroy_branch:
5158.6.10 by Martin Pool
Update more code to use user_transport when it should
348
                up = self.local_branch.user_transport.clone('..')
6207.3.3 by jelmer at samba
Fix tests and the like.
349
                up_bzrdir = controldir.ControlDir.open_containing_from_transport(
350
                    up)[0]
3311.2.1 by Aaron Bentley
Initial make-sharing functionality
351
                new_repo = up_bzrdir.find_repository()
352
                new_repo.fetch(self.repository)
2796.2.23 by Aaron Bentley
Add support for reconfiguring repositories into branches or trees
353
        last_revision_info = None
2796.2.14 by Aaron Bentley
Updates from review
354
        if self._destroy_reference:
2796.2.23 by Aaron Bentley
Add support for reconfiguring repositories into branches or trees
355
            last_revision_info = self.referenced_branch.last_revision_info()
2796.2.7 by Aaron Bentley
Implement converting a lightweight checkout to a branch
356
            self.bzrdir.destroy_branch()
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
357
        if self._destroy_branch:
2796.2.23 by Aaron Bentley
Add support for reconfiguring repositories into branches or trees
358
            last_revision_info = self.local_branch.last_revision_info()
2796.2.31 by Aaron Bentley
Fetch tags to reference branch when converting to checkout
359
            if self._create_reference:
360
                self.local_branch.tags.merge_to(reference_branch.tags)
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
361
            self.bzrdir.destroy_branch()
2796.2.14 by Aaron Bentley
Updates from review
362
        if self._create_branch:
2796.2.9 by Aaron Bentley
Ensure conversion from lightweight checkout works
363
            local_branch = self.bzrdir.create_branch()
2796.2.23 by Aaron Bentley
Add support for reconfiguring repositories into branches or trees
364
            if last_revision_info is not None:
365
                local_branch.set_last_revision_info(*last_revision_info)
2796.2.32 by Aaron Bentley
Preserve tags converting from lightweight checkouts
366
            if self._destroy_reference:
367
                self.referenced_branch.tags.merge_to(local_branch.tags)
4273.1.18 by Aaron Bentley
Reconfigure preserves reference locations.
368
                self.referenced_branch.update_references(local_branch)
2796.2.9 by Aaron Bentley
Ensure conversion from lightweight checkout works
369
        else:
370
            local_branch = self.local_branch
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
371
        if self._create_reference:
6437.7.3 by Jelmer Vernooij
Use ControlDir.set_branch_reference.
372
            self.bzrdir.set_branch_reference(reference_branch)
2796.2.14 by Aaron Bentley
Updates from review
373
        if self._destroy_tree:
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
374
            self.bzrdir.destroy_workingtree()
2796.2.14 by Aaron Bentley
Updates from review
375
        if self._create_tree:
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
376
            self.bzrdir.create_workingtree()
2796.2.14 by Aaron Bentley
Updates from review
377
        if self._unbind:
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
378
            self.local_branch.unbind()
2796.2.14 by Aaron Bentley
Updates from review
379
        if self._bind:
2796.2.11 by Aaron Bentley
Cleanups
380
            bind_location = self._select_bind_location()
2796.2.9 by Aaron Bentley
Ensure conversion from lightweight checkout works
381
            local_branch.bind(branch.Branch.open(bind_location))
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
382
        if self._destroy_repository:
383
            self.bzrdir.destroy_repository()
3983.3.7 by Marius Kruger
apply changes in apply again
384
        if self._repository_trees is not None:
385
            repo.set_make_working_trees(self._repository_trees)