/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
1
# Copyright (C) 2007, 2008, 2009, 2011, 2012 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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
17
from breezy import (
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
18
    branch as _mod_branch,
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
19
    controldir,
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
20
    errors,
21
    reconfigure,
2796.2.25 by Aaron Bentley
Avoid destroying shared repositories
22
    repository,
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
23
    tests,
6670.4.1 by Jelmer Vernooij
Update imports.
24
    workingtree,
25
    )
26
from breezy.bzr import (
27
    branch as _mod_bzrbranch,
6341.1.6 by Jelmer Vernooij
Fix test.
28
    vf_repository,
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
29
    )
30
31
32
class TestReconfigure(tests.TestCaseWithTransport):
33
34
    def test_tree_to_branch(self):
35
        tree = self.make_branch_and_tree('tree')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
36
        reconfiguration = reconfigure.Reconfigure.to_branch(tree.controldir)
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
37
        reconfiguration.apply()
38
        self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
39
                          'tree')
40
41
    def test_modified_tree_to_branch(self):
42
        tree = self.make_branch_and_tree('tree')
43
        self.build_tree(['tree/file'])
44
        tree.add('file')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
45
        reconfiguration = reconfigure.Reconfigure.to_branch(tree.controldir)
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
46
        self.assertRaises(errors.UncommittedChanges, reconfiguration.apply)
47
        reconfiguration.apply(force=True)
48
        self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
49
                          'tree')
50
4721.3.2 by Vincent Ladeuil
Simplify mutable_tree.has_changes() and update call sites.
51
    def test_tree_with_pending_merge_to_branch(self):
52
        tree = self.make_branch_and_tree('tree')
5954.2.4 by Aaron Bentley
Fix broken tests.
53
        tree.commit('unchanged')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
54
        other_tree = tree.controldir.sprout('other').open_workingtree()
5954.3.2 by Vincent Ladeuil
Nitpicks.
55
        other_tree.commit('mergeable commit')
4721.3.2 by Vincent Ladeuil
Simplify mutable_tree.has_changes() and update call sites.
56
        tree.merge_from_branch(other_tree.branch)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
57
        reconfiguration = reconfigure.Reconfigure.to_branch(tree.controldir)
4721.3.2 by Vincent Ladeuil
Simplify mutable_tree.has_changes() and update call sites.
58
        self.assertRaises(errors.UncommittedChanges, reconfiguration.apply)
59
        reconfiguration.apply(force=True)
60
        self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
61
                          'tree')
62
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
63
    def test_branch_to_branch(self):
64
        branch = self.make_branch('branch')
6734.1.16 by Jelmer Vernooij
Move reconfigure errors.
65
        self.assertRaises(reconfigure.AlreadyBranch,
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
66
                          reconfigure.Reconfigure.to_branch, branch.controldir)
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
67
68
    def test_repo_to_branch(self):
69
        repo = self.make_repository('repo')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
70
        reconfiguration = reconfigure.Reconfigure.to_branch(repo.controldir)
2796.2.23 by Aaron Bentley
Add support for reconfiguring repositories into branches or trees
71
        reconfiguration.apply()
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
72
73
    def test_checkout_to_branch(self):
74
        branch = self.make_branch('branch')
75
        checkout = branch.create_checkout('checkout')
7143.15.2 by Jelmer Vernooij
Run autopep8.
76
        reconfiguration = reconfigure.Reconfigure.to_branch(
77
            checkout.controldir)
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
78
        reconfiguration.apply()
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
79
        reconfigured = controldir.ControlDir.open('checkout').open_branch()
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
80
        self.assertIs(None, reconfigured.get_bound_location())
2796.2.2 by Aaron Bentley
Refuse to turn lightweight checkouts into branches
81
2796.2.32 by Aaron Bentley
Preserve tags converting from lightweight checkouts
82
    def prepare_lightweight_checkout_to_branch(self):
83
        branch = self.make_branch('branch')
84
        checkout = branch.create_checkout('checkout', lightweight=True)
6855.4.1 by Jelmer Vernooij
Yet more bees.
85
        checkout.commit('first commit', rev_id=b'rev1')
7143.15.2 by Jelmer Vernooij
Run autopep8.
86
        reconfiguration = reconfigure.Reconfigure.to_branch(
87
            checkout.controldir)
2796.2.32 by Aaron Bentley
Preserve tags converting from lightweight checkouts
88
        return reconfiguration, checkout
89
2796.2.2 by Aaron Bentley
Refuse to turn lightweight checkouts into branches
90
    def test_lightweight_checkout_to_branch(self):
2796.2.32 by Aaron Bentley
Preserve tags converting from lightweight checkouts
91
        reconfiguration, checkout = \
92
            self.prepare_lightweight_checkout_to_branch()
2796.2.7 by Aaron Bentley
Implement converting a lightweight checkout to a branch
93
        reconfiguration.apply()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
94
        checkout_branch = checkout.controldir.open_branch()
95
        self.assertEqual(checkout_branch.controldir.root_transport.base,
96
                         checkout.controldir.root_transport.base)
6973.5.2 by Jelmer Vernooij
Add more bees.
97
        self.assertEqual(b'rev1', checkout_branch.last_revision())
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
98
        repo = checkout.controldir.open_repository()
6973.5.2 by Jelmer Vernooij
Add more bees.
99
        repo.get_revision(b'rev1')
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
100
2796.2.32 by Aaron Bentley
Preserve tags converting from lightweight checkouts
101
    def test_lightweight_checkout_to_branch_tags(self):
102
        reconfiguration, checkout = \
103
            self.prepare_lightweight_checkout_to_branch()
6973.9.1 by Jelmer Vernooij
More test fixes.
104
        checkout.branch.tags.set_tag('foo', b'bar')
2796.2.32 by Aaron Bentley
Preserve tags converting from lightweight checkouts
105
        reconfiguration.apply()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
106
        checkout_branch = checkout.controldir.open_branch()
6973.9.1 by Jelmer Vernooij
More test fixes.
107
        self.assertEqual(b'bar', checkout_branch.tags.lookup_tag('foo'))
2796.2.32 by Aaron Bentley
Preserve tags converting from lightweight checkouts
108
2796.2.33 by Aaron Bentley
Add lightweight-checkout-to-checkout tags test
109
    def prepare_lightweight_checkout_to_checkout(self):
110
        branch = self.make_branch('branch')
111
        checkout = branch.create_checkout('checkout', lightweight=True)
7143.15.2 by Jelmer Vernooij
Run autopep8.
112
        reconfiguration = reconfigure.Reconfigure.to_checkout(
113
            checkout.controldir)
2796.2.33 by Aaron Bentley
Add lightweight-checkout-to-checkout tags test
114
        return reconfiguration, checkout
115
2796.2.9 by Aaron Bentley
Ensure conversion from lightweight checkout works
116
    def test_lightweight_checkout_to_checkout(self):
2796.2.33 by Aaron Bentley
Add lightweight-checkout-to-checkout tags test
117
        reconfiguration, checkout = \
118
            self.prepare_lightweight_checkout_to_checkout()
2796.2.9 by Aaron Bentley
Ensure conversion from lightweight checkout works
119
        reconfiguration.apply()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
120
        checkout_branch = checkout.controldir.open_branch()
2796.2.9 by Aaron Bentley
Ensure conversion from lightweight checkout works
121
        self.assertIsNot(checkout_branch.get_bound_location(), None)
122
2796.2.33 by Aaron Bentley
Add lightweight-checkout-to-checkout tags test
123
    def test_lightweight_checkout_to_checkout_tags(self):
124
        reconfiguration, checkout = \
125
            self.prepare_lightweight_checkout_to_checkout()
6973.9.1 by Jelmer Vernooij
More test fixes.
126
        checkout.branch.tags.set_tag('foo', b'bar')
2796.2.33 by Aaron Bentley
Add lightweight-checkout-to-checkout tags test
127
        reconfiguration.apply()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
128
        checkout_branch = checkout.controldir.open_branch()
6973.9.1 by Jelmer Vernooij
More test fixes.
129
        self.assertEqual(b'bar', checkout_branch.tags.lookup_tag('foo'))
2796.2.33 by Aaron Bentley
Add lightweight-checkout-to-checkout tags test
130
2796.2.10 by Aaron Bentley
Ensure that shared repositories are used where possible
131
    def test_lightweight_conversion_uses_shared_repo(self):
132
        parent = self.make_branch('parent')
133
        shared_repo = self.make_repository('repo', shared=True)
134
        checkout = parent.create_checkout('repo/checkout', lightweight=True)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
135
        reconfigure.Reconfigure.to_tree(checkout.controldir).apply()
136
        checkout_repo = checkout.controldir.open_branch().repository
137
        self.assertEqual(shared_repo.controldir.root_transport.base,
138
                         checkout_repo.controldir.root_transport.base)
2796.2.10 by Aaron Bentley
Ensure that shared repositories are used where possible
139
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
140
    def test_branch_to_tree(self):
141
        branch = self.make_branch('branch')
7143.15.2 by Jelmer Vernooij
Run autopep8.
142
        reconfiguration = reconfigure.Reconfigure.to_tree(branch.controldir)
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
143
        reconfiguration.apply()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
144
        branch.controldir.open_workingtree()
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
145
146
    def test_tree_to_tree(self):
147
        tree = self.make_branch_and_tree('tree')
6734.1.16 by Jelmer Vernooij
Move reconfigure errors.
148
        self.assertRaises(reconfigure.AlreadyTree,
149
                          reconfigure.Reconfigure.to_tree, tree.controldir)
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
150
151
    def test_select_bind_location(self):
152
        branch = self.make_branch('branch')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
153
        reconfiguration = reconfigure.Reconfigure(branch.controldir)
6734.1.16 by Jelmer Vernooij
Move reconfigure errors.
154
        self.assertRaises(reconfigure.NoBindLocation,
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
155
                          reconfiguration._select_bind_location)
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
156
        branch.set_parent('http://parent')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
157
        reconfiguration = reconfigure.Reconfigure(branch.controldir)
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
158
        self.assertEqual('http://parent',
159
                         reconfiguration._select_bind_location())
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
160
        branch.set_push_location('sftp://push')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
161
        reconfiguration = reconfigure.Reconfigure(branch.controldir)
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
162
        self.assertEqual('sftp://push',
163
                         reconfiguration._select_bind_location())
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
164
        branch.lock_write()
165
        try:
166
            branch.set_bound_location('bzr://foo/old-bound')
167
            branch.set_bound_location(None)
168
        finally:
169
            branch.unlock()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
170
        reconfiguration = reconfigure.Reconfigure(branch.controldir)
2796.2.22 by Aaron Bentley
Tweak from review
171
        self.assertEqual('bzr://foo/old-bound',
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
172
                         reconfiguration._select_bind_location())
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
173
        branch.set_bound_location('bzr://foo/cur-bound')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
174
        reconfiguration = reconfigure.Reconfigure(branch.controldir)
2796.2.22 by Aaron Bentley
Tweak from review
175
        self.assertEqual('bzr://foo/cur-bound',
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
176
                         reconfiguration._select_bind_location())
2796.2.11 by Aaron Bentley
Cleanups
177
        reconfiguration.new_bound_location = 'ftp://user-specified'
178
        self.assertEqual('ftp://user-specified',
179
                         reconfiguration._select_bind_location())
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
180
2796.2.9 by Aaron Bentley
Ensure conversion from lightweight checkout works
181
    def test_select_reference_bind_location(self):
182
        branch = self.make_branch('branch')
183
        checkout = branch.create_checkout('checkout', lightweight=True)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
184
        reconfiguration = reconfigure.Reconfigure(checkout.controldir)
2796.2.9 by Aaron Bentley
Ensure conversion from lightweight checkout works
185
        self.assertEqual(branch.base,
186
                         reconfiguration._select_bind_location())
187
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
188
    def test_tree_to_checkout(self):
189
        # A tree with no related branches and no supplied bind location cannot
190
        # become a checkout
191
        parent = self.make_branch('parent')
192
193
        tree = self.make_branch_and_tree('tree')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
194
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree.controldir)
6734.1.16 by Jelmer Vernooij
Move reconfigure errors.
195
        self.assertRaises(reconfigure.NoBindLocation, reconfiguration.apply)
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
196
        # setting a parent allows it to become a checkout
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
197
        tree.branch.set_parent(parent.base)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
198
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree.controldir)
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
199
        reconfiguration.apply()
200
        # supplying a location allows it to become a checkout
201
        tree2 = self.make_branch_and_tree('tree2')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
202
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree2.controldir,
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
203
                                                              parent.base)
2796.2.4 by Aaron Bentley
Fix support for reconfiguring to selected bound location
204
        reconfiguration.apply()
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
205
2796.2.26 by Aaron Bentley
Support converting standalone tree to lightweight checkout
206
    def test_tree_to_lightweight_checkout(self):
207
        # A tree with no related branches and no supplied bind location cannot
208
        # become a checkout
209
        parent = self.make_branch('parent')
210
211
        tree = self.make_branch_and_tree('tree')
212
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
213
            tree.controldir)
6734.1.16 by Jelmer Vernooij
Move reconfigure errors.
214
        self.assertRaises(reconfigure.NoBindLocation, reconfiguration.apply)
2796.2.26 by Aaron Bentley
Support converting standalone tree to lightweight checkout
215
        # setting a parent allows it to become a checkout
6404.6.7 by Vincent Ladeuil
Change set/remove to require a lock for the branch config files.
216
        tree.branch.set_parent(parent.base)
6404.6.1 by Vincent Ladeuil
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made.
217
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
218
            tree.controldir)
2796.2.26 by Aaron Bentley
Support converting standalone tree to lightweight checkout
219
        reconfiguration.apply()
220
        # supplying a location allows it to become a checkout
221
        tree2 = self.make_branch_and_tree('tree2')
222
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
223
            tree2.controldir, parent.base)
2796.2.26 by Aaron Bentley
Support converting standalone tree to lightweight checkout
224
        reconfiguration.apply()
225
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
226
    def test_checkout_to_checkout(self):
227
        parent = self.make_branch('parent')
228
        checkout = parent.create_checkout('checkout')
6734.1.16 by Jelmer Vernooij
Move reconfigure errors.
229
        self.assertRaises(reconfigure.AlreadyCheckout,
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
230
                          reconfigure.Reconfigure.to_checkout, checkout.controldir)
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
231
3338.1.2 by Aaron Bentley
Split out tests even further
232
    def make_unsynced_checkout(self):
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
233
        parent = self.make_branch('parent')
234
        checkout = parent.create_checkout('checkout')
6855.4.1 by Jelmer Vernooij
Yet more bees.
235
        checkout.commit('test', rev_id=b'new-commit', local=True)
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
236
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
237
            checkout.controldir)
3338.1.2 by Aaron Bentley
Split out tests even further
238
        return checkout, parent, reconfiguration
239
240
    def test_unsynced_checkout_to_lightweight(self):
241
        checkout, parent, reconfiguration = self.make_unsynced_checkout()
6734.1.16 by Jelmer Vernooij
Move reconfigure errors.
242
        self.assertRaises(reconfigure.UnsyncedBranches, reconfiguration.apply)
3338.1.2 by Aaron Bentley
Split out tests even further
243
244
    def test_synced_checkout_to_lightweight(self):
245
        checkout, parent, reconfiguration = self.make_unsynced_checkout()
3338.1.1 by Aaron Bentley
Raise an error when converting a branch to a lightweight checkout loses data
246
        parent.pull(checkout.branch)
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
247
        reconfiguration.apply()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
248
        wt = checkout.controldir.open_workingtree()
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
249
        self.assertTrue(parent.repository.has_same_location(
250
            wt.branch.repository))
6973.5.2 by Jelmer Vernooij
Add more bees.
251
        parent.repository.get_revision(b'new-commit')
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
252
        self.assertRaises(errors.NoRepositoryPresent,
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
253
                          checkout.controldir.open_repository)
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
254
2796.2.31 by Aaron Bentley
Fetch tags to reference branch when converting to checkout
255
    def prepare_branch_to_lightweight_checkout(self):
256
        parent = self.make_branch('parent')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
257
        child = parent.controldir.sprout('child').open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
258
        child.commit('test', rev_id=b'new-commit')
3338.1.1 by Aaron Bentley
Raise an error when converting a branch to a lightweight checkout loses data
259
        parent.pull(child.branch)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
260
        child.controldir.destroy_workingtree()
2796.2.31 by Aaron Bentley
Fetch tags to reference branch when converting to checkout
261
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
262
            child.controldir)
2796.2.31 by Aaron Bentley
Fetch tags to reference branch when converting to checkout
263
        return parent, child, reconfiguration
264
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
265
    def test_branch_to_lightweight_checkout(self):
2796.2.31 by Aaron Bentley
Fetch tags to reference branch when converting to checkout
266
        parent, child, reconfiguration = \
267
            self.prepare_branch_to_lightweight_checkout()
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
268
        reconfiguration.apply()
2796.2.31 by Aaron Bentley
Fetch tags to reference branch when converting to checkout
269
        self.assertTrue(reconfiguration._destroy_branch)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
270
        wt = child.controldir.open_workingtree()
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
271
        self.assertTrue(parent.repository.has_same_location(
272
            wt.branch.repository))
6973.5.2 by Jelmer Vernooij
Add more bees.
273
        parent.repository.get_revision(b'new-commit')
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
274
        self.assertRaises(errors.NoRepositoryPresent,
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
275
                          child.controldir.open_repository)
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
276
2796.2.30 by Aaron Bentley
Reconfigure can safely be interrupted while fetching (#179316)
277
    def test_branch_to_lightweight_checkout_failure(self):
2796.2.31 by Aaron Bentley
Fetch tags to reference branch when converting to checkout
278
        parent, child, reconfiguration = \
279
            self.prepare_branch_to_lightweight_checkout()
6341.1.6 by Jelmer Vernooij
Fix test.
280
        old_Repository_fetch = vf_repository.VersionedFileRepository.fetch
281
        vf_repository.VersionedFileRepository.fetch = None
2796.2.30 by Aaron Bentley
Reconfigure can safely be interrupted while fetching (#179316)
282
        try:
283
            self.assertRaises(TypeError, reconfiguration.apply)
284
        finally:
6341.1.6 by Jelmer Vernooij
Fix test.
285
            vf_repository.VersionedFileRepository.fetch = old_Repository_fetch
2796.2.30 by Aaron Bentley
Reconfigure can safely be interrupted while fetching (#179316)
286
        child = _mod_branch.Branch.open('child')
287
        self.assertContainsRe(child.base, 'child/$')
288
2796.2.31 by Aaron Bentley
Fetch tags to reference branch when converting to checkout
289
    def test_branch_to_lightweight_checkout_fetch_tags(self):
290
        parent, child, reconfiguration = \
291
            self.prepare_branch_to_lightweight_checkout()
6973.9.1 by Jelmer Vernooij
More test fixes.
292
        child.branch.tags.set_tag('foo', b'bar')
2796.2.31 by Aaron Bentley
Fetch tags to reference branch when converting to checkout
293
        reconfiguration.apply()
294
        child = _mod_branch.Branch.open('child')
6973.9.1 by Jelmer Vernooij
More test fixes.
295
        self.assertEqual(b'bar', parent.tags.lookup_tag('foo'))
2796.2.31 by Aaron Bentley
Fetch tags to reference branch when converting to checkout
296
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
297
    def test_lightweight_checkout_to_lightweight_checkout(self):
298
        parent = self.make_branch('parent')
299
        checkout = parent.create_checkout('checkout', lightweight=True)
6734.1.16 by Jelmer Vernooij
Move reconfigure errors.
300
        self.assertRaises(reconfigure.AlreadyLightweightCheckout,
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
301
                          reconfigure.Reconfigure.to_lightweight_checkout,
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
302
                          checkout.controldir)
2796.2.23 by Aaron Bentley
Add support for reconfiguring repositories into branches or trees
303
304
    def test_repo_to_tree(self):
305
        repo = self.make_repository('repo')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
306
        reconfiguration = reconfigure.Reconfigure.to_tree(repo.controldir)
2796.2.23 by Aaron Bentley
Add support for reconfiguring repositories into branches or trees
307
        reconfiguration.apply()
308
        workingtree.WorkingTree.open('repo')
309
2796.2.25 by Aaron Bentley
Avoid destroying shared repositories
310
    def test_shared_repo_to_lightweight_checkout(self):
311
        repo = self.make_repository('repo', shared=True)
2796.2.23 by Aaron Bentley
Add support for reconfiguring repositories into branches or trees
312
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
313
            repo.controldir)
6734.1.16 by Jelmer Vernooij
Move reconfigure errors.
314
        self.assertRaises(reconfigure.NoBindLocation, reconfiguration.apply)
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
315
        self.make_branch('branch')
2796.2.23 by Aaron Bentley
Add support for reconfiguring repositories into branches or trees
316
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
317
            repo.controldir, 'branch')
2796.2.23 by Aaron Bentley
Add support for reconfiguring repositories into branches or trees
318
        reconfiguration.apply()
2796.2.25 by Aaron Bentley
Avoid destroying shared repositories
319
        workingtree.WorkingTree.open('repo')
320
        repository.Repository.open('repo')
321
322
    def test_unshared_repo_to_lightweight_checkout(self):
323
        repo = self.make_repository('repo', shared=False)
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
324
        self.make_branch('branch')
2796.2.25 by Aaron Bentley
Avoid destroying shared repositories
325
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
326
            repo.controldir, 'branch')
2796.2.25 by Aaron Bentley
Avoid destroying shared repositories
327
        reconfiguration.apply()
328
        workingtree.WorkingTree.open('repo')
329
        self.assertRaises(errors.NoRepositoryPresent,
330
                          repository.Repository.open, 'repo')
3311.2.1 by Aaron Bentley
Initial make-sharing functionality
331
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
332
    def test_standalone_to_use_shared(self):
3311.2.1 by Aaron Bentley
Initial make-sharing functionality
333
        self.build_tree(['root/'])
334
        tree = self.make_branch_and_tree('root/tree')
6855.4.1 by Jelmer Vernooij
Yet more bees.
335
        tree.commit('Hello', rev_id=b'hello-id')
3311.2.1 by Aaron Bentley
Initial make-sharing functionality
336
        repo = self.make_repository('root', shared=True)
7143.15.2 by Jelmer Vernooij
Run autopep8.
337
        reconfiguration = reconfigure.Reconfigure.to_use_shared(
338
            tree.controldir)
3311.2.1 by Aaron Bentley
Initial make-sharing functionality
339
        reconfiguration.apply()
340
        tree = workingtree.WorkingTree.open('root/tree')
341
        self.assertTrue(repo.has_same_location(tree.branch.repository))
6973.5.2 by Jelmer Vernooij
Add more bees.
342
        self.assertEqual('Hello', repo.get_revision(b'hello-id').message)
3311.2.2 by Aaron Bentley
Flesh out to_sharing
343
3311.2.7 by Aaron Bentley
Get head preservation under test
344
    def add_dead_head(self, tree):
345
        revno, revision_id = tree.branch.last_revision_info()
6855.4.1 by Jelmer Vernooij
Yet more bees.
346
        tree.commit('Dead head', rev_id=b'dead-head-id')
3311.2.7 by Aaron Bentley
Get head preservation under test
347
        tree.branch.set_last_revision_info(revno, revision_id)
348
        tree.set_last_revision(revision_id)
349
350
    def test_standalone_to_use_shared_preserves_dead_heads(self):
351
        self.build_tree(['root/'])
352
        tree = self.make_branch_and_tree('root/tree')
353
        self.add_dead_head(tree)
6855.4.1 by Jelmer Vernooij
Yet more bees.
354
        tree.commit('Hello', rev_id=b'hello-id')
3311.2.7 by Aaron Bentley
Get head preservation under test
355
        repo = self.make_repository('root', shared=True)
7143.15.2 by Jelmer Vernooij
Run autopep8.
356
        reconfiguration = reconfigure.Reconfigure.to_use_shared(
357
            tree.controldir)
3311.2.7 by Aaron Bentley
Get head preservation under test
358
        reconfiguration.apply()
359
        tree = workingtree.WorkingTree.open('root/tree')
6973.5.2 by Jelmer Vernooij
Add more bees.
360
        message = repo.get_revision(b'dead-head-id').message
3311.2.7 by Aaron Bentley
Get head preservation under test
361
        self.assertEqual('Dead head', message)
362
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
363
    def make_repository_tree(self):
3311.2.4 by Aaron Bentley
Implement conversion to standalone
364
        self.build_tree(['root/'])
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
365
        self.make_repository('root', shared=True)
3311.2.4 by Aaron Bentley
Implement conversion to standalone
366
        tree = self.make_branch_and_tree('root/tree')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
367
        reconfigure.Reconfigure.to_use_shared(tree.controldir).apply()
3311.2.4 by Aaron Bentley
Implement conversion to standalone
368
        return workingtree.WorkingTree.open('root/tree')
369
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
370
    def test_use_shared_to_use_shared(self):
371
        tree = self.make_repository_tree()
6734.1.16 by Jelmer Vernooij
Move reconfigure errors.
372
        self.assertRaises(reconfigure.AlreadyUsingShared,
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
373
                          reconfigure.Reconfigure.to_use_shared, tree.controldir)
3311.2.4 by Aaron Bentley
Implement conversion to standalone
374
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
375
    def test_use_shared_to_standalone(self):
376
        tree = self.make_repository_tree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
377
        tree.commit('Hello', rev_id=b'hello-id')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
378
        reconfigure.Reconfigure.to_standalone(tree.controldir).apply()
3311.2.4 by Aaron Bentley
Implement conversion to standalone
379
        tree = workingtree.WorkingTree.open('root/tree')
380
        repo = tree.branch.repository
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
381
        self.assertEqual(repo.controldir.root_transport.base,
382
                         tree.controldir.root_transport.base)
6973.5.2 by Jelmer Vernooij
Add more bees.
383
        self.assertEqual('Hello', repo.get_revision(b'hello-id').message)
3311.2.4 by Aaron Bentley
Implement conversion to standalone
384
3311.2.7 by Aaron Bentley
Get head preservation under test
385
    def test_use_shared_to_standalone_preserves_dead_heads(self):
386
        tree = self.make_repository_tree()
387
        self.add_dead_head(tree)
6855.4.1 by Jelmer Vernooij
Yet more bees.
388
        tree.commit('Hello', rev_id=b'hello-id')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
389
        reconfigure.Reconfigure.to_standalone(tree.controldir).apply()
3311.2.7 by Aaron Bentley
Get head preservation under test
390
        tree = workingtree.WorkingTree.open('root/tree')
391
        repo = tree.branch.repository
392
        self.assertRaises(errors.NoSuchRevision, repo.get_revision,
7058.4.1 by Jelmer Vernooij
Fix another 40 tests.
393
                          b'dead-head-id')
3311.2.7 by Aaron Bentley
Get head preservation under test
394
3311.2.4 by Aaron Bentley
Implement conversion to standalone
395
    def test_standalone_to_standalone(self):
396
        tree = self.make_branch_and_tree('tree')
6734.1.16 by Jelmer Vernooij
Move reconfigure errors.
397
        self.assertRaises(reconfigure.AlreadyStandalone,
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
398
                          reconfigure.Reconfigure.to_standalone, tree.controldir)
3338.1.3 by Aaron Bentley
Merge bzr.dev
399
3338.1.2 by Aaron Bentley
Split out tests even further
400
    def make_unsynced_branch_reconfiguration(self):
3338.1.1 by Aaron Bentley
Raise an error when converting a branch to a lightweight checkout loses data
401
        parent = self.make_branch_and_tree('parent')
402
        parent.commit('commit 1')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
403
        child = parent.controldir.sprout('child').open_workingtree()
3338.1.1 by Aaron Bentley
Raise an error when converting a branch to a lightweight checkout loses data
404
        child.commit('commit 2')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
405
        return reconfigure.Reconfigure.to_lightweight_checkout(child.controldir)
3338.1.2 by Aaron Bentley
Split out tests even further
406
407
    def test_unsynced_branch_to_lightweight_checkout_unforced(self):
408
        reconfiguration = self.make_unsynced_branch_reconfiguration()
6734.1.16 by Jelmer Vernooij
Move reconfigure errors.
409
        self.assertRaises(reconfigure.UnsyncedBranches, reconfiguration.apply)
3338.1.2 by Aaron Bentley
Split out tests even further
410
411
    def test_unsynced_branch_to_lightweight_checkout_forced(self):
412
        reconfiguration = self.make_unsynced_branch_reconfiguration()
3338.1.1 by Aaron Bentley
Raise an error when converting a branch to a lightweight checkout loses data
413
        reconfiguration.apply(force=True)
3921.4.4 by Matthew Fuller
Add unit tests for Reconfigure.set_repository_trees().
414
415
    def make_repository_with_without_trees(self, with_trees):
416
        repo = self.make_repository('repo', shared=True)
417
        repo.set_make_working_trees(with_trees)
418
        return repo
419
420
    def test_make_with_trees(self):
421
        repo = self.make_repository_with_without_trees(False)
422
        reconfiguration = reconfigure.Reconfigure.set_repository_trees(
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
423
            repo.controldir, True)
3921.4.4 by Matthew Fuller
Add unit tests for Reconfigure.set_repository_trees().
424
        reconfiguration.apply()
3921.4.5 by Matthew Fuller
Add assertions to the unit tests to make sure the reconfiguration
425
        self.assertIs(True, repo.make_working_trees())
3921.4.4 by Matthew Fuller
Add unit tests for Reconfigure.set_repository_trees().
426
427
    def test_make_without_trees(self):
428
        repo = self.make_repository_with_without_trees(True)
429
        reconfiguration = reconfigure.Reconfigure.set_repository_trees(
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
430
            repo.controldir, False)
3921.4.4 by Matthew Fuller
Add unit tests for Reconfigure.set_repository_trees().
431
        reconfiguration.apply()
3921.4.5 by Matthew Fuller
Add assertions to the unit tests to make sure the reconfiguration
432
        self.assertIs(False, repo.make_working_trees())
3921.4.4 by Matthew Fuller
Add unit tests for Reconfigure.set_repository_trees().
433
434
    def test_make_with_trees_already_with_trees(self):
435
        repo = self.make_repository_with_without_trees(True)
6744 by Jelmer Vernooij
Merge lp:~jelmer/brz/move-errors-knit.
436
        e = self.assertRaises(reconfigure.AlreadyWithTrees,
7143.15.2 by Jelmer Vernooij
Run autopep8.
437
                              reconfigure.Reconfigure.set_repository_trees, repo.controldir, True)
3983.3.9 by Marius Kruger
check error message too
438
        self.assertContainsRe(str(e),
7143.15.2 by Jelmer Vernooij
Run autopep8.
439
                              r"Shared repository '.*' already creates working trees.")
3921.4.4 by Matthew Fuller
Add unit tests for Reconfigure.set_repository_trees().
440
441
    def test_make_without_trees_already_no_trees(self):
442
        repo = self.make_repository_with_without_trees(False)
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
443
        e = self.assertRaises(
444
            reconfigure.AlreadyWithNoTrees,
445
            reconfigure.Reconfigure.set_repository_trees, repo.controldir,
446
            False)
447
        self.assertContainsRe(
448
            str(e),
449
            r"Shared repository '.*' already doesn't create working trees.")
3983.3.10 by Marius Kruger
add test_repository_tree_reconfiguration_not_supported
450
451
    def test_repository_tree_reconfiguration_not_supported(self):
452
        tree = self.make_branch_and_tree('tree')
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
453
        e = self.assertRaises(
454
            reconfigure.ReconfigurationNotSupported,
455
            reconfigure.Reconfigure.set_repository_trees, tree.controldir,
456
            None)
457
        self.assertContainsRe(
458
            str(e), r"Requested reconfiguration of '.*' is not supported.")
4273.1.18 by Aaron Bentley
Reconfigure preserves reference locations.
459
460
    def test_lightweight_checkout_to_tree_preserves_reference_locations(self):
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
461
        format = controldir.format_registry.make_controldir('1.9')
6653.1.10 by Jelmer Vernooij
Fix remaining two tests.
462
        format.set_branch_format(_mod_bzrbranch.BzrBranchFormat8())
4273.1.18 by Aaron Bentley
Reconfigure preserves reference locations.
463
        tree = self.make_branch_and_tree('tree', format=format)
7447.4.2 by Jelmer Vernooij
Merge tree reference fixes.
464
        tree.branch.set_reference_info(b'file_id', '../location', 'path')
4273.1.18 by Aaron Bentley
Reconfigure preserves reference locations.
465
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
466
        reconfiguration = reconfigure.Reconfigure.to_tree(checkout.controldir)
4273.1.18 by Aaron Bentley
Reconfigure preserves reference locations.
467
        reconfiguration.apply()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
468
        checkout_branch = checkout.controldir.open_branch()
7447.4.2 by Jelmer Vernooij
Merge tree reference fixes.
469
        self.assertEqual(('../location', 'path'),
470
                         checkout_branch.get_reference_info(b'file_id'))