/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: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

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