/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 breezy/tests/test_reconfigure.py

  • Committer: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

Show diffs side-by-side

added added

removed removed

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