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