/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_reconfigure.py

  • Committer: Marius Kruger
  • Date: 2010-07-10 21:28:56 UTC
  • mto: (5384.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5385.
  • Revision ID: marius.kruger@enerweb.co.za-20100710212856-uq4ji3go0u5se7hx
* Update documentation
* add NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2008, 2009, 2011, 2012 Canonical Ltd
 
1
# Copyright (C) 2007, 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from breezy import (
 
17
from bzrlib import (
18
18
    branch as _mod_branch,
19
 
    controldir,
 
19
    bzrdir,
20
20
    errors,
21
21
    reconfigure,
22
22
    repository,
23
23
    tests,
24
24
    workingtree,
25
25
    )
26
 
from breezy.bzr import (
27
 
    branch as _mod_bzrbranch,
28
 
    vf_repository,
29
 
    )
30
26
 
31
27
 
32
28
class TestReconfigure(tests.TestCaseWithTransport):
33
29
 
34
30
    def test_tree_to_branch(self):
35
31
        tree = self.make_branch_and_tree('tree')
36
 
        reconfiguration = reconfigure.Reconfigure.to_branch(tree.controldir)
 
32
        reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
37
33
        reconfiguration.apply()
38
34
        self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
39
35
                          'tree')
42
38
        tree = self.make_branch_and_tree('tree')
43
39
        self.build_tree(['tree/file'])
44
40
        tree.add('file')
45
 
        reconfiguration = reconfigure.Reconfigure.to_branch(tree.controldir)
 
41
        reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
46
42
        self.assertRaises(errors.UncommittedChanges, reconfiguration.apply)
47
43
        reconfiguration.apply(force=True)
48
44
        self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
50
46
 
51
47
    def test_tree_with_pending_merge_to_branch(self):
52
48
        tree = self.make_branch_and_tree('tree')
53
 
        tree.commit('unchanged')
54
 
        other_tree = tree.controldir.sprout('other').open_workingtree()
55
 
        other_tree.commit('mergeable commit')
 
49
        other_tree = tree.bzrdir.sprout('other').open_workingtree()
 
50
        self.build_tree(['other/file'])
 
51
        other_tree.add('file')
 
52
        other_tree.commit('file added')
56
53
        tree.merge_from_branch(other_tree.branch)
57
 
        reconfiguration = reconfigure.Reconfigure.to_branch(tree.controldir)
 
54
        reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
58
55
        self.assertRaises(errors.UncommittedChanges, reconfiguration.apply)
59
56
        reconfiguration.apply(force=True)
60
57
        self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
62
59
 
63
60
    def test_branch_to_branch(self):
64
61
        branch = self.make_branch('branch')
65
 
        self.assertRaises(reconfigure.AlreadyBranch,
66
 
                          reconfigure.Reconfigure.to_branch, branch.controldir)
 
62
        self.assertRaises(errors.AlreadyBranch,
 
63
                          reconfigure.Reconfigure.to_branch, branch.bzrdir)
67
64
 
68
65
    def test_repo_to_branch(self):
69
66
        repo = self.make_repository('repo')
70
 
        reconfiguration = reconfigure.Reconfigure.to_branch(repo.controldir)
 
67
        reconfiguration = reconfigure.Reconfigure.to_branch(repo.bzrdir)
71
68
        reconfiguration.apply()
72
69
 
73
70
    def test_checkout_to_branch(self):
74
71
        branch = self.make_branch('branch')
75
72
        checkout = branch.create_checkout('checkout')
76
 
        reconfiguration = reconfigure.Reconfigure.to_branch(
77
 
            checkout.controldir)
 
73
        reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
78
74
        reconfiguration.apply()
79
 
        reconfigured = controldir.ControlDir.open('checkout').open_branch()
80
 
        self.assertIs(None, reconfigured.get_bound_location())
 
75
        self.assertIs(None, checkout.branch.get_bound_location())
81
76
 
82
77
    def prepare_lightweight_checkout_to_branch(self):
83
78
        branch = self.make_branch('branch')
84
79
        checkout = branch.create_checkout('checkout', lightweight=True)
85
 
        checkout.commit('first commit', rev_id=b'rev1')
86
 
        reconfiguration = reconfigure.Reconfigure.to_branch(
87
 
            checkout.controldir)
 
80
        checkout.commit('first commit', rev_id='rev1')
 
81
        reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
88
82
        return reconfiguration, checkout
89
83
 
90
84
    def test_lightweight_checkout_to_branch(self):
91
85
        reconfiguration, checkout = \
92
86
            self.prepare_lightweight_checkout_to_branch()
93
87
        reconfiguration.apply()
94
 
        checkout_branch = checkout.controldir.open_branch()
95
 
        self.assertEqual(checkout_branch.controldir.root_transport.base,
96
 
                         checkout.controldir.root_transport.base)
97
 
        self.assertEqual(b'rev1', checkout_branch.last_revision())
98
 
        repo = checkout.controldir.open_repository()
99
 
        repo.get_revision(b'rev1')
 
88
        checkout_branch = checkout.bzrdir.open_branch()
 
89
        self.assertEqual(checkout_branch.bzrdir.root_transport.base,
 
90
                         checkout.bzrdir.root_transport.base)
 
91
        self.assertEqual('rev1', checkout_branch.last_revision())
 
92
        repo = checkout.bzrdir.open_repository()
 
93
        repo.get_revision('rev1')
100
94
 
101
95
    def test_lightweight_checkout_to_branch_tags(self):
102
96
        reconfiguration, checkout = \
103
97
            self.prepare_lightweight_checkout_to_branch()
104
 
        checkout.branch.tags.set_tag('foo', b'bar')
 
98
        checkout.branch.tags.set_tag('foo', 'bar')
105
99
        reconfiguration.apply()
106
 
        checkout_branch = checkout.controldir.open_branch()
107
 
        self.assertEqual(b'bar', checkout_branch.tags.lookup_tag('foo'))
 
100
        checkout_branch = checkout.bzrdir.open_branch()
 
101
        self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
108
102
 
109
103
    def prepare_lightweight_checkout_to_checkout(self):
110
104
        branch = self.make_branch('branch')
111
105
        checkout = branch.create_checkout('checkout', lightweight=True)
112
 
        reconfiguration = reconfigure.Reconfigure.to_checkout(
113
 
            checkout.controldir)
 
106
        reconfiguration = reconfigure.Reconfigure.to_checkout(checkout.bzrdir)
114
107
        return reconfiguration, checkout
115
108
 
116
109
    def test_lightweight_checkout_to_checkout(self):
117
110
        reconfiguration, checkout = \
118
111
            self.prepare_lightweight_checkout_to_checkout()
119
112
        reconfiguration.apply()
120
 
        checkout_branch = checkout.controldir.open_branch()
 
113
        checkout_branch = checkout.bzrdir.open_branch()
121
114
        self.assertIsNot(checkout_branch.get_bound_location(), None)
122
115
 
123
116
    def test_lightweight_checkout_to_checkout_tags(self):
124
117
        reconfiguration, checkout = \
125
118
            self.prepare_lightweight_checkout_to_checkout()
126
 
        checkout.branch.tags.set_tag('foo', b'bar')
 
119
        checkout.branch.tags.set_tag('foo', 'bar')
127
120
        reconfiguration.apply()
128
 
        checkout_branch = checkout.controldir.open_branch()
129
 
        self.assertEqual(b'bar', checkout_branch.tags.lookup_tag('foo'))
 
121
        checkout_branch = checkout.bzrdir.open_branch()
 
122
        self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
130
123
 
131
124
    def test_lightweight_conversion_uses_shared_repo(self):
132
125
        parent = self.make_branch('parent')
133
126
        shared_repo = self.make_repository('repo', shared=True)
134
127
        checkout = parent.create_checkout('repo/checkout', lightweight=True)
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)
 
128
        reconfigure.Reconfigure.to_tree(checkout.bzrdir).apply()
 
129
        checkout_repo = checkout.bzrdir.open_branch().repository
 
130
        self.assertEqual(shared_repo.bzrdir.root_transport.base,
 
131
                         checkout_repo.bzrdir.root_transport.base)
139
132
 
140
133
    def test_branch_to_tree(self):
141
134
        branch = self.make_branch('branch')
142
 
        reconfiguration = reconfigure.Reconfigure.to_tree(branch.controldir)
 
135
        reconfiguration=reconfigure.Reconfigure.to_tree(branch.bzrdir)
143
136
        reconfiguration.apply()
144
 
        branch.controldir.open_workingtree()
 
137
        branch.bzrdir.open_workingtree()
145
138
 
146
139
    def test_tree_to_tree(self):
147
140
        tree = self.make_branch_and_tree('tree')
148
 
        self.assertRaises(reconfigure.AlreadyTree,
149
 
                          reconfigure.Reconfigure.to_tree, tree.controldir)
 
141
        self.assertRaises(errors.AlreadyTree, reconfigure.Reconfigure.to_tree,
 
142
                          tree.bzrdir)
150
143
 
151
144
    def test_select_bind_location(self):
152
145
        branch = self.make_branch('branch')
153
 
        reconfiguration = reconfigure.Reconfigure(branch.controldir)
154
 
        self.assertRaises(reconfigure.NoBindLocation,
 
146
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
 
147
        self.assertRaises(errors.NoBindLocation,
155
148
                          reconfiguration._select_bind_location)
156
149
        branch.set_parent('http://parent')
157
 
        reconfiguration = reconfigure.Reconfigure(branch.controldir)
158
150
        self.assertEqual('http://parent',
159
151
                         reconfiguration._select_bind_location())
160
152
        branch.set_push_location('sftp://push')
161
 
        reconfiguration = reconfigure.Reconfigure(branch.controldir)
162
153
        self.assertEqual('sftp://push',
163
154
                         reconfiguration._select_bind_location())
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()
170
 
        reconfiguration = reconfigure.Reconfigure(branch.controldir)
 
155
        branch.set_bound_location('bzr://foo/old-bound')
 
156
        branch.set_bound_location(None)
171
157
        self.assertEqual('bzr://foo/old-bound',
172
158
                         reconfiguration._select_bind_location())
173
159
        branch.set_bound_location('bzr://foo/cur-bound')
174
 
        reconfiguration = reconfigure.Reconfigure(branch.controldir)
175
160
        self.assertEqual('bzr://foo/cur-bound',
176
161
                         reconfiguration._select_bind_location())
177
162
        reconfiguration.new_bound_location = 'ftp://user-specified'
181
166
    def test_select_reference_bind_location(self):
182
167
        branch = self.make_branch('branch')
183
168
        checkout = branch.create_checkout('checkout', lightweight=True)
184
 
        reconfiguration = reconfigure.Reconfigure(checkout.controldir)
 
169
        reconfiguration = reconfigure.Reconfigure(checkout.bzrdir)
185
170
        self.assertEqual(branch.base,
186
171
                         reconfiguration._select_bind_location())
187
172
 
191
176
        parent = self.make_branch('parent')
192
177
 
193
178
        tree = self.make_branch_and_tree('tree')
194
 
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree.controldir)
195
 
        self.assertRaises(reconfigure.NoBindLocation, reconfiguration.apply)
 
179
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree.bzrdir)
 
180
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
196
181
        # setting a parent allows it to become a checkout
197
182
        tree.branch.set_parent(parent.base)
198
 
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree.controldir)
199
183
        reconfiguration.apply()
200
184
        # supplying a location allows it to become a checkout
201
185
        tree2 = self.make_branch_and_tree('tree2')
202
 
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree2.controldir,
 
186
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree2.bzrdir,
203
187
                                                              parent.base)
204
188
        reconfiguration.apply()
205
189
 
210
194
 
211
195
        tree = self.make_branch_and_tree('tree')
212
196
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
213
 
            tree.controldir)
214
 
        self.assertRaises(reconfigure.NoBindLocation, reconfiguration.apply)
 
197
            tree.bzrdir)
 
198
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
215
199
        # setting a parent allows it to become a checkout
216
200
        tree.branch.set_parent(parent.base)
217
 
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
218
 
            tree.controldir)
219
201
        reconfiguration.apply()
220
202
        # supplying a location allows it to become a checkout
221
203
        tree2 = self.make_branch_and_tree('tree2')
222
204
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
223
 
            tree2.controldir, parent.base)
 
205
            tree2.bzrdir, parent.base)
224
206
        reconfiguration.apply()
225
207
 
226
208
    def test_checkout_to_checkout(self):
227
209
        parent = self.make_branch('parent')
228
210
        checkout = parent.create_checkout('checkout')
229
 
        self.assertRaises(reconfigure.AlreadyCheckout,
230
 
                          reconfigure.Reconfigure.to_checkout, checkout.controldir)
 
211
        self.assertRaises(errors.AlreadyCheckout,
 
212
                          reconfigure.Reconfigure.to_checkout, checkout.bzrdir)
231
213
 
232
214
    def make_unsynced_checkout(self):
233
215
        parent = self.make_branch('parent')
234
216
        checkout = parent.create_checkout('checkout')
235
 
        checkout.commit('test', rev_id=b'new-commit', local=True)
 
217
        checkout.commit('test', rev_id='new-commit', local=True)
236
218
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
237
 
            checkout.controldir)
 
219
            checkout.bzrdir)
238
220
        return checkout, parent, reconfiguration
239
221
 
240
222
    def test_unsynced_checkout_to_lightweight(self):
241
223
        checkout, parent, reconfiguration = self.make_unsynced_checkout()
242
 
        self.assertRaises(reconfigure.UnsyncedBranches, reconfiguration.apply)
 
224
        self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
243
225
 
244
226
    def test_synced_checkout_to_lightweight(self):
245
227
        checkout, parent, reconfiguration = self.make_unsynced_checkout()
246
228
        parent.pull(checkout.branch)
247
229
        reconfiguration.apply()
248
 
        wt = checkout.controldir.open_workingtree()
 
230
        wt = checkout.bzrdir.open_workingtree()
249
231
        self.assertTrue(parent.repository.has_same_location(
250
232
            wt.branch.repository))
251
 
        parent.repository.get_revision(b'new-commit')
 
233
        parent.repository.get_revision('new-commit')
252
234
        self.assertRaises(errors.NoRepositoryPresent,
253
 
                          checkout.controldir.open_repository)
 
235
                          checkout.bzrdir.open_repository)
254
236
 
255
237
    def prepare_branch_to_lightweight_checkout(self):
256
238
        parent = self.make_branch('parent')
257
 
        child = parent.controldir.sprout('child').open_workingtree()
258
 
        child.commit('test', rev_id=b'new-commit')
 
239
        child = parent.bzrdir.sprout('child').open_workingtree()
 
240
        child.commit('test', rev_id='new-commit')
259
241
        parent.pull(child.branch)
260
 
        child.controldir.destroy_workingtree()
 
242
        child.bzrdir.destroy_workingtree()
261
243
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
262
 
            child.controldir)
 
244
            child.bzrdir)
263
245
        return parent, child, reconfiguration
264
246
 
265
247
    def test_branch_to_lightweight_checkout(self):
267
249
            self.prepare_branch_to_lightweight_checkout()
268
250
        reconfiguration.apply()
269
251
        self.assertTrue(reconfiguration._destroy_branch)
270
 
        wt = child.controldir.open_workingtree()
 
252
        wt = child.bzrdir.open_workingtree()
271
253
        self.assertTrue(parent.repository.has_same_location(
272
254
            wt.branch.repository))
273
 
        parent.repository.get_revision(b'new-commit')
 
255
        parent.repository.get_revision('new-commit')
274
256
        self.assertRaises(errors.NoRepositoryPresent,
275
 
                          child.controldir.open_repository)
 
257
                          child.bzrdir.open_repository)
276
258
 
277
259
    def test_branch_to_lightweight_checkout_failure(self):
278
260
        parent, child, reconfiguration = \
279
261
            self.prepare_branch_to_lightweight_checkout()
280
 
        old_Repository_fetch = vf_repository.VersionedFileRepository.fetch
281
 
        vf_repository.VersionedFileRepository.fetch = None
 
262
        old_Repository_fetch = repository.Repository.fetch
 
263
        repository.Repository.fetch = None
282
264
        try:
283
265
            self.assertRaises(TypeError, reconfiguration.apply)
284
266
        finally:
285
 
            vf_repository.VersionedFileRepository.fetch = old_Repository_fetch
 
267
            repository.Repository.fetch = old_Repository_fetch
286
268
        child = _mod_branch.Branch.open('child')
287
269
        self.assertContainsRe(child.base, 'child/$')
288
270
 
289
271
    def test_branch_to_lightweight_checkout_fetch_tags(self):
290
272
        parent, child, reconfiguration = \
291
273
            self.prepare_branch_to_lightweight_checkout()
292
 
        child.branch.tags.set_tag('foo', b'bar')
 
274
        child.branch.tags.set_tag('foo', 'bar')
293
275
        reconfiguration.apply()
294
276
        child = _mod_branch.Branch.open('child')
295
 
        self.assertEqual(b'bar', parent.tags.lookup_tag('foo'))
 
277
        self.assertEqual('bar', parent.tags.lookup_tag('foo'))
296
278
 
297
279
    def test_lightweight_checkout_to_lightweight_checkout(self):
298
280
        parent = self.make_branch('parent')
299
281
        checkout = parent.create_checkout('checkout', lightweight=True)
300
 
        self.assertRaises(reconfigure.AlreadyLightweightCheckout,
 
282
        self.assertRaises(errors.AlreadyLightweightCheckout,
301
283
                          reconfigure.Reconfigure.to_lightweight_checkout,
302
 
                          checkout.controldir)
 
284
                          checkout.bzrdir)
303
285
 
304
286
    def test_repo_to_tree(self):
305
287
        repo = self.make_repository('repo')
306
 
        reconfiguration = reconfigure.Reconfigure.to_tree(repo.controldir)
 
288
        reconfiguration = reconfigure.Reconfigure.to_tree(repo.bzrdir)
307
289
        reconfiguration.apply()
308
290
        workingtree.WorkingTree.open('repo')
309
291
 
310
292
    def test_shared_repo_to_lightweight_checkout(self):
311
293
        repo = self.make_repository('repo', shared=True)
312
294
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
313
 
            repo.controldir)
314
 
        self.assertRaises(reconfigure.NoBindLocation, reconfiguration.apply)
315
 
        self.make_branch('branch')
 
295
            repo.bzrdir)
 
296
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
 
297
        branch = self.make_branch('branch')
316
298
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
317
 
            repo.controldir, 'branch')
 
299
            repo.bzrdir, 'branch')
318
300
        reconfiguration.apply()
319
301
        workingtree.WorkingTree.open('repo')
320
302
        repository.Repository.open('repo')
321
303
 
322
304
    def test_unshared_repo_to_lightweight_checkout(self):
323
305
        repo = self.make_repository('repo', shared=False)
324
 
        self.make_branch('branch')
 
306
        branch = self.make_branch('branch')
325
307
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
326
 
            repo.controldir, 'branch')
 
308
            repo.bzrdir, 'branch')
327
309
        reconfiguration.apply()
328
310
        workingtree.WorkingTree.open('repo')
329
311
        self.assertRaises(errors.NoRepositoryPresent,
332
314
    def test_standalone_to_use_shared(self):
333
315
        self.build_tree(['root/'])
334
316
        tree = self.make_branch_and_tree('root/tree')
335
 
        tree.commit('Hello', rev_id=b'hello-id')
 
317
        tree.commit('Hello', rev_id='hello-id')
336
318
        repo = self.make_repository('root', shared=True)
337
 
        reconfiguration = reconfigure.Reconfigure.to_use_shared(
338
 
            tree.controldir)
 
319
        reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.bzrdir)
339
320
        reconfiguration.apply()
340
321
        tree = workingtree.WorkingTree.open('root/tree')
341
322
        self.assertTrue(repo.has_same_location(tree.branch.repository))
342
 
        self.assertEqual('Hello', repo.get_revision(b'hello-id').message)
 
323
        self.assertEqual('Hello', repo.get_revision('hello-id').message)
343
324
 
344
325
    def add_dead_head(self, tree):
345
326
        revno, revision_id = tree.branch.last_revision_info()
346
 
        tree.commit('Dead head', rev_id=b'dead-head-id')
 
327
        tree.commit('Dead head', rev_id='dead-head-id')
347
328
        tree.branch.set_last_revision_info(revno, revision_id)
348
329
        tree.set_last_revision(revision_id)
349
330
 
351
332
        self.build_tree(['root/'])
352
333
        tree = self.make_branch_and_tree('root/tree')
353
334
        self.add_dead_head(tree)
354
 
        tree.commit('Hello', rev_id=b'hello-id')
 
335
        tree.commit('Hello', rev_id='hello-id')
355
336
        repo = self.make_repository('root', shared=True)
356
 
        reconfiguration = reconfigure.Reconfigure.to_use_shared(
357
 
            tree.controldir)
 
337
        reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.bzrdir)
358
338
        reconfiguration.apply()
359
339
        tree = workingtree.WorkingTree.open('root/tree')
360
 
        message = repo.get_revision(b'dead-head-id').message
 
340
        message = repo.get_revision('dead-head-id').message
361
341
        self.assertEqual('Dead head', message)
362
342
 
363
343
    def make_repository_tree(self):
364
344
        self.build_tree(['root/'])
365
 
        self.make_repository('root', shared=True)
 
345
        repo = self.make_repository('root', shared=True)
366
346
        tree = self.make_branch_and_tree('root/tree')
367
 
        reconfigure.Reconfigure.to_use_shared(tree.controldir).apply()
 
347
        reconfigure.Reconfigure.to_use_shared(tree.bzrdir).apply()
368
348
        return workingtree.WorkingTree.open('root/tree')
369
349
 
370
350
    def test_use_shared_to_use_shared(self):
371
351
        tree = self.make_repository_tree()
372
 
        self.assertRaises(reconfigure.AlreadyUsingShared,
373
 
                          reconfigure.Reconfigure.to_use_shared, tree.controldir)
 
352
        self.assertRaises(errors.AlreadyUsingShared,
 
353
                          reconfigure.Reconfigure.to_use_shared, tree.bzrdir)
374
354
 
375
355
    def test_use_shared_to_standalone(self):
376
356
        tree = self.make_repository_tree()
377
 
        tree.commit('Hello', rev_id=b'hello-id')
378
 
        reconfigure.Reconfigure.to_standalone(tree.controldir).apply()
 
357
        tree.commit('Hello', rev_id='hello-id')
 
358
        reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
379
359
        tree = workingtree.WorkingTree.open('root/tree')
380
360
        repo = tree.branch.repository
381
 
        self.assertEqual(repo.controldir.root_transport.base,
382
 
                         tree.controldir.root_transport.base)
383
 
        self.assertEqual('Hello', repo.get_revision(b'hello-id').message)
 
361
        self.assertEqual(repo.bzrdir.root_transport.base,
 
362
                         tree.bzrdir.root_transport.base)
 
363
        self.assertEqual('Hello', repo.get_revision('hello-id').message)
384
364
 
385
365
    def test_use_shared_to_standalone_preserves_dead_heads(self):
386
366
        tree = self.make_repository_tree()
387
367
        self.add_dead_head(tree)
388
 
        tree.commit('Hello', rev_id=b'hello-id')
389
 
        reconfigure.Reconfigure.to_standalone(tree.controldir).apply()
 
368
        tree.commit('Hello', rev_id='hello-id')
 
369
        reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
390
370
        tree = workingtree.WorkingTree.open('root/tree')
391
371
        repo = tree.branch.repository
392
372
        self.assertRaises(errors.NoSuchRevision, repo.get_revision,
393
 
                          b'dead-head-id')
 
373
                          'dead-head-id')
394
374
 
395
375
    def test_standalone_to_standalone(self):
396
376
        tree = self.make_branch_and_tree('tree')
397
 
        self.assertRaises(reconfigure.AlreadyStandalone,
398
 
                          reconfigure.Reconfigure.to_standalone, tree.controldir)
 
377
        self.assertRaises(errors.AlreadyStandalone,
 
378
                          reconfigure.Reconfigure.to_standalone, tree.bzrdir)
399
379
 
400
380
    def make_unsynced_branch_reconfiguration(self):
401
381
        parent = self.make_branch_and_tree('parent')
402
382
        parent.commit('commit 1')
403
 
        child = parent.controldir.sprout('child').open_workingtree()
 
383
        child = parent.bzrdir.sprout('child').open_workingtree()
404
384
        child.commit('commit 2')
405
 
        return reconfigure.Reconfigure.to_lightweight_checkout(child.controldir)
 
385
        return reconfigure.Reconfigure.to_lightweight_checkout(child.bzrdir)
406
386
 
407
387
    def test_unsynced_branch_to_lightweight_checkout_unforced(self):
408
388
        reconfiguration = self.make_unsynced_branch_reconfiguration()
409
 
        self.assertRaises(reconfigure.UnsyncedBranches, reconfiguration.apply)
 
389
        self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
410
390
 
411
391
    def test_unsynced_branch_to_lightweight_checkout_forced(self):
412
392
        reconfiguration = self.make_unsynced_branch_reconfiguration()
420
400
    def test_make_with_trees(self):
421
401
        repo = self.make_repository_with_without_trees(False)
422
402
        reconfiguration = reconfigure.Reconfigure.set_repository_trees(
423
 
            repo.controldir, True)
 
403
            repo.bzrdir, True)
424
404
        reconfiguration.apply()
425
405
        self.assertIs(True, repo.make_working_trees())
426
406
 
427
407
    def test_make_without_trees(self):
428
408
        repo = self.make_repository_with_without_trees(True)
429
409
        reconfiguration = reconfigure.Reconfigure.set_repository_trees(
430
 
            repo.controldir, False)
 
410
            repo.bzrdir, False)
431
411
        reconfiguration.apply()
432
412
        self.assertIs(False, repo.make_working_trees())
433
413
 
434
414
    def test_make_with_trees_already_with_trees(self):
435
415
        repo = self.make_repository_with_without_trees(True)
436
 
        e = self.assertRaises(reconfigure.AlreadyWithTrees,
437
 
                              reconfigure.Reconfigure.set_repository_trees, repo.controldir, True)
 
416
        e = self.assertRaises(errors.AlreadyWithTrees,
 
417
           reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, True)
438
418
        self.assertContainsRe(str(e),
439
 
                              r"Shared repository '.*' already creates working trees.")
 
419
            r"Shared repository '.*' already creates working trees.")
440
420
 
441
421
    def test_make_without_trees_already_no_trees(self):
442
422
        repo = self.make_repository_with_without_trees(False)
443
 
        e = self.assertRaises(
444
 
            reconfigure.AlreadyWithNoTrees,
445
 
            reconfigure.Reconfigure.set_repository_trees, repo.controldir,
446
 
            False)
447
 
        self.assertContainsRe(
448
 
            str(e),
 
423
        e = self.assertRaises(errors.AlreadyWithNoTrees,
 
424
            reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, False)
 
425
        self.assertContainsRe(str(e),
449
426
            r"Shared repository '.*' already doesn't create working trees.")
450
427
 
451
428
    def test_repository_tree_reconfiguration_not_supported(self):
452
429
        tree = self.make_branch_and_tree('tree')
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.")
 
430
        e = self.assertRaises(errors.ReconfigurationNotSupported,
 
431
            reconfigure.Reconfigure.set_repository_trees, tree.bzrdir, None)
 
432
        self.assertContainsRe(str(e),
 
433
            r"Requested reconfiguration of '.*' is not supported.")
459
434
 
460
435
    def test_lightweight_checkout_to_tree_preserves_reference_locations(self):
461
 
        format = controldir.format_registry.make_controldir('1.9')
462
 
        format.set_branch_format(_mod_bzrbranch.BzrBranchFormat8())
 
436
        format = bzrdir.format_registry.make_bzrdir('1.9')
 
437
        format.set_branch_format(_mod_branch.BzrBranchFormat8())
463
438
        tree = self.make_branch_and_tree('tree', format=format)
464
 
        tree.branch.set_reference_info(b'file_id', '../location', 'path')
 
439
        tree.branch.set_reference_info('file_id', 'path', '../location')
465
440
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
466
 
        reconfiguration = reconfigure.Reconfigure.to_tree(checkout.controldir)
 
441
        reconfiguration = reconfigure.Reconfigure.to_tree(checkout.bzrdir)
467
442
        reconfiguration.apply()
468
 
        checkout_branch = checkout.controldir.open_branch()
469
 
        self.assertEqual(('../location', 'path'),
470
 
                         checkout_branch.get_reference_info(b'file_id'))
 
443
        checkout_branch = checkout.bzrdir.open_branch()
 
444
        self.assertEqual(('path', '../location'),
 
445
                         checkout_branch.get_reference_info('file_id'))