/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: 2018-07-08 14:45:27 UTC
  • mto: This revision was merged to the branch mainline in revision 7036.
  • Revision ID: jelmer@jelmer.uk-20180708144527-codhlvdcdg9y0nji
Fix a bunch of merge tests.

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