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