/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: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
 
63
63
    def test_branch_to_branch(self):
64
64
        branch = self.make_branch('branch')
65
 
        self.assertRaises(reconfigure.AlreadyBranch,
 
65
        self.assertRaises(errors.AlreadyBranch,
66
66
                          reconfigure.Reconfigure.to_branch, branch.controldir)
67
67
 
68
68
    def test_repo_to_branch(self):
73
73
    def test_checkout_to_branch(self):
74
74
        branch = self.make_branch('branch')
75
75
        checkout = branch.create_checkout('checkout')
76
 
        reconfiguration = reconfigure.Reconfigure.to_branch(
77
 
            checkout.controldir)
 
76
        reconfiguration = reconfigure.Reconfigure.to_branch(checkout.controldir)
78
77
        reconfiguration.apply()
79
78
        reconfigured = controldir.ControlDir.open('checkout').open_branch()
80
79
        self.assertIs(None, reconfigured.get_bound_location())
82
81
    def prepare_lightweight_checkout_to_branch(self):
83
82
        branch = self.make_branch('branch')
84
83
        checkout = branch.create_checkout('checkout', lightweight=True)
85
 
        checkout.commit('first commit', rev_id=b'rev1')
86
 
        reconfiguration = reconfigure.Reconfigure.to_branch(
87
 
            checkout.controldir)
 
84
        checkout.commit('first commit', rev_id='rev1')
 
85
        reconfiguration = reconfigure.Reconfigure.to_branch(checkout.controldir)
88
86
        return reconfiguration, checkout
89
87
 
90
88
    def test_lightweight_checkout_to_branch(self):
94
92
        checkout_branch = checkout.controldir.open_branch()
95
93
        self.assertEqual(checkout_branch.controldir.root_transport.base,
96
94
                         checkout.controldir.root_transport.base)
97
 
        self.assertEqual(b'rev1', checkout_branch.last_revision())
 
95
        self.assertEqual('rev1', checkout_branch.last_revision())
98
96
        repo = checkout.controldir.open_repository()
99
 
        repo.get_revision(b'rev1')
 
97
        repo.get_revision('rev1')
100
98
 
101
99
    def test_lightweight_checkout_to_branch_tags(self):
102
100
        reconfiguration, checkout = \
103
101
            self.prepare_lightweight_checkout_to_branch()
104
 
        checkout.branch.tags.set_tag('foo', b'bar')
 
102
        checkout.branch.tags.set_tag('foo', 'bar')
105
103
        reconfiguration.apply()
106
104
        checkout_branch = checkout.controldir.open_branch()
107
 
        self.assertEqual(b'bar', checkout_branch.tags.lookup_tag('foo'))
 
105
        self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
108
106
 
109
107
    def prepare_lightweight_checkout_to_checkout(self):
110
108
        branch = self.make_branch('branch')
111
109
        checkout = branch.create_checkout('checkout', lightweight=True)
112
 
        reconfiguration = reconfigure.Reconfigure.to_checkout(
113
 
            checkout.controldir)
 
110
        reconfiguration = reconfigure.Reconfigure.to_checkout(checkout.controldir)
114
111
        return reconfiguration, checkout
115
112
 
116
113
    def test_lightweight_checkout_to_checkout(self):
123
120
    def test_lightweight_checkout_to_checkout_tags(self):
124
121
        reconfiguration, checkout = \
125
122
            self.prepare_lightweight_checkout_to_checkout()
126
 
        checkout.branch.tags.set_tag('foo', b'bar')
 
123
        checkout.branch.tags.set_tag('foo', 'bar')
127
124
        reconfiguration.apply()
128
125
        checkout_branch = checkout.controldir.open_branch()
129
 
        self.assertEqual(b'bar', checkout_branch.tags.lookup_tag('foo'))
 
126
        self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
130
127
 
131
128
    def test_lightweight_conversion_uses_shared_repo(self):
132
129
        parent = self.make_branch('parent')
139
136
 
140
137
    def test_branch_to_tree(self):
141
138
        branch = self.make_branch('branch')
142
 
        reconfiguration = reconfigure.Reconfigure.to_tree(branch.controldir)
 
139
        reconfiguration=reconfigure.Reconfigure.to_tree(branch.controldir)
143
140
        reconfiguration.apply()
144
141
        branch.controldir.open_workingtree()
145
142
 
146
143
    def test_tree_to_tree(self):
147
144
        tree = self.make_branch_and_tree('tree')
148
 
        self.assertRaises(reconfigure.AlreadyTree,
149
 
                          reconfigure.Reconfigure.to_tree, tree.controldir)
 
145
        self.assertRaises(errors.AlreadyTree, reconfigure.Reconfigure.to_tree,
 
146
                          tree.controldir)
150
147
 
151
148
    def test_select_bind_location(self):
152
149
        branch = self.make_branch('branch')
153
150
        reconfiguration = reconfigure.Reconfigure(branch.controldir)
154
 
        self.assertRaises(reconfigure.NoBindLocation,
 
151
        self.assertRaises(errors.NoBindLocation,
155
152
                          reconfiguration._select_bind_location)
156
153
        branch.set_parent('http://parent')
157
154
        reconfiguration = reconfigure.Reconfigure(branch.controldir)
192
189
 
193
190
        tree = self.make_branch_and_tree('tree')
194
191
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree.controldir)
195
 
        self.assertRaises(reconfigure.NoBindLocation, reconfiguration.apply)
 
192
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
196
193
        # setting a parent allows it to become a checkout
197
194
        tree.branch.set_parent(parent.base)
198
195
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree.controldir)
211
208
        tree = self.make_branch_and_tree('tree')
212
209
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
213
210
            tree.controldir)
214
 
        self.assertRaises(reconfigure.NoBindLocation, reconfiguration.apply)
 
211
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
215
212
        # setting a parent allows it to become a checkout
216
213
        tree.branch.set_parent(parent.base)
217
214
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
226
223
    def test_checkout_to_checkout(self):
227
224
        parent = self.make_branch('parent')
228
225
        checkout = parent.create_checkout('checkout')
229
 
        self.assertRaises(reconfigure.AlreadyCheckout,
 
226
        self.assertRaises(errors.AlreadyCheckout,
230
227
                          reconfigure.Reconfigure.to_checkout, checkout.controldir)
231
228
 
232
229
    def make_unsynced_checkout(self):
233
230
        parent = self.make_branch('parent')
234
231
        checkout = parent.create_checkout('checkout')
235
 
        checkout.commit('test', rev_id=b'new-commit', local=True)
 
232
        checkout.commit('test', rev_id='new-commit', local=True)
236
233
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
237
234
            checkout.controldir)
238
235
        return checkout, parent, reconfiguration
239
236
 
240
237
    def test_unsynced_checkout_to_lightweight(self):
241
238
        checkout, parent, reconfiguration = self.make_unsynced_checkout()
242
 
        self.assertRaises(reconfigure.UnsyncedBranches, reconfiguration.apply)
 
239
        self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
243
240
 
244
241
    def test_synced_checkout_to_lightweight(self):
245
242
        checkout, parent, reconfiguration = self.make_unsynced_checkout()
248
245
        wt = checkout.controldir.open_workingtree()
249
246
        self.assertTrue(parent.repository.has_same_location(
250
247
            wt.branch.repository))
251
 
        parent.repository.get_revision(b'new-commit')
 
248
        parent.repository.get_revision('new-commit')
252
249
        self.assertRaises(errors.NoRepositoryPresent,
253
250
                          checkout.controldir.open_repository)
254
251
 
255
252
    def prepare_branch_to_lightweight_checkout(self):
256
253
        parent = self.make_branch('parent')
257
254
        child = parent.controldir.sprout('child').open_workingtree()
258
 
        child.commit('test', rev_id=b'new-commit')
 
255
        child.commit('test', rev_id='new-commit')
259
256
        parent.pull(child.branch)
260
257
        child.controldir.destroy_workingtree()
261
258
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
270
267
        wt = child.controldir.open_workingtree()
271
268
        self.assertTrue(parent.repository.has_same_location(
272
269
            wt.branch.repository))
273
 
        parent.repository.get_revision(b'new-commit')
 
270
        parent.repository.get_revision('new-commit')
274
271
        self.assertRaises(errors.NoRepositoryPresent,
275
272
                          child.controldir.open_repository)
276
273
 
289
286
    def test_branch_to_lightweight_checkout_fetch_tags(self):
290
287
        parent, child, reconfiguration = \
291
288
            self.prepare_branch_to_lightweight_checkout()
292
 
        child.branch.tags.set_tag('foo', b'bar')
 
289
        child.branch.tags.set_tag('foo', 'bar')
293
290
        reconfiguration.apply()
294
291
        child = _mod_branch.Branch.open('child')
295
 
        self.assertEqual(b'bar', parent.tags.lookup_tag('foo'))
 
292
        self.assertEqual('bar', parent.tags.lookup_tag('foo'))
296
293
 
297
294
    def test_lightweight_checkout_to_lightweight_checkout(self):
298
295
        parent = self.make_branch('parent')
299
296
        checkout = parent.create_checkout('checkout', lightweight=True)
300
 
        self.assertRaises(reconfigure.AlreadyLightweightCheckout,
 
297
        self.assertRaises(errors.AlreadyLightweightCheckout,
301
298
                          reconfigure.Reconfigure.to_lightweight_checkout,
302
299
                          checkout.controldir)
303
300
 
311
308
        repo = self.make_repository('repo', shared=True)
312
309
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
313
310
            repo.controldir)
314
 
        self.assertRaises(reconfigure.NoBindLocation, reconfiguration.apply)
315
 
        self.make_branch('branch')
 
311
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
 
312
        branch = self.make_branch('branch')
316
313
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
317
314
            repo.controldir, 'branch')
318
315
        reconfiguration.apply()
321
318
 
322
319
    def test_unshared_repo_to_lightweight_checkout(self):
323
320
        repo = self.make_repository('repo', shared=False)
324
 
        self.make_branch('branch')
 
321
        branch = self.make_branch('branch')
325
322
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
326
323
            repo.controldir, 'branch')
327
324
        reconfiguration.apply()
332
329
    def test_standalone_to_use_shared(self):
333
330
        self.build_tree(['root/'])
334
331
        tree = self.make_branch_and_tree('root/tree')
335
 
        tree.commit('Hello', rev_id=b'hello-id')
 
332
        tree.commit('Hello', rev_id='hello-id')
336
333
        repo = self.make_repository('root', shared=True)
337
 
        reconfiguration = reconfigure.Reconfigure.to_use_shared(
338
 
            tree.controldir)
 
334
        reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.controldir)
339
335
        reconfiguration.apply()
340
336
        tree = workingtree.WorkingTree.open('root/tree')
341
337
        self.assertTrue(repo.has_same_location(tree.branch.repository))
342
 
        self.assertEqual('Hello', repo.get_revision(b'hello-id').message)
 
338
        self.assertEqual('Hello', repo.get_revision('hello-id').message)
343
339
 
344
340
    def add_dead_head(self, tree):
345
341
        revno, revision_id = tree.branch.last_revision_info()
346
 
        tree.commit('Dead head', rev_id=b'dead-head-id')
 
342
        tree.commit('Dead head', rev_id='dead-head-id')
347
343
        tree.branch.set_last_revision_info(revno, revision_id)
348
344
        tree.set_last_revision(revision_id)
349
345
 
351
347
        self.build_tree(['root/'])
352
348
        tree = self.make_branch_and_tree('root/tree')
353
349
        self.add_dead_head(tree)
354
 
        tree.commit('Hello', rev_id=b'hello-id')
 
350
        tree.commit('Hello', rev_id='hello-id')
355
351
        repo = self.make_repository('root', shared=True)
356
 
        reconfiguration = reconfigure.Reconfigure.to_use_shared(
357
 
            tree.controldir)
 
352
        reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.controldir)
358
353
        reconfiguration.apply()
359
354
        tree = workingtree.WorkingTree.open('root/tree')
360
 
        message = repo.get_revision(b'dead-head-id').message
 
355
        message = repo.get_revision('dead-head-id').message
361
356
        self.assertEqual('Dead head', message)
362
357
 
363
358
    def make_repository_tree(self):
364
359
        self.build_tree(['root/'])
365
 
        self.make_repository('root', shared=True)
 
360
        repo = self.make_repository('root', shared=True)
366
361
        tree = self.make_branch_and_tree('root/tree')
367
362
        reconfigure.Reconfigure.to_use_shared(tree.controldir).apply()
368
363
        return workingtree.WorkingTree.open('root/tree')
369
364
 
370
365
    def test_use_shared_to_use_shared(self):
371
366
        tree = self.make_repository_tree()
372
 
        self.assertRaises(reconfigure.AlreadyUsingShared,
 
367
        self.assertRaises(errors.AlreadyUsingShared,
373
368
                          reconfigure.Reconfigure.to_use_shared, tree.controldir)
374
369
 
375
370
    def test_use_shared_to_standalone(self):
376
371
        tree = self.make_repository_tree()
377
 
        tree.commit('Hello', rev_id=b'hello-id')
 
372
        tree.commit('Hello', rev_id='hello-id')
378
373
        reconfigure.Reconfigure.to_standalone(tree.controldir).apply()
379
374
        tree = workingtree.WorkingTree.open('root/tree')
380
375
        repo = tree.branch.repository
381
376
        self.assertEqual(repo.controldir.root_transport.base,
382
377
                         tree.controldir.root_transport.base)
383
 
        self.assertEqual('Hello', repo.get_revision(b'hello-id').message)
 
378
        self.assertEqual('Hello', repo.get_revision('hello-id').message)
384
379
 
385
380
    def test_use_shared_to_standalone_preserves_dead_heads(self):
386
381
        tree = self.make_repository_tree()
387
382
        self.add_dead_head(tree)
388
 
        tree.commit('Hello', rev_id=b'hello-id')
 
383
        tree.commit('Hello', rev_id='hello-id')
389
384
        reconfigure.Reconfigure.to_standalone(tree.controldir).apply()
390
385
        tree = workingtree.WorkingTree.open('root/tree')
391
386
        repo = tree.branch.repository
392
387
        self.assertRaises(errors.NoSuchRevision, repo.get_revision,
393
 
                          b'dead-head-id')
 
388
                          'dead-head-id')
394
389
 
395
390
    def test_standalone_to_standalone(self):
396
391
        tree = self.make_branch_and_tree('tree')
397
 
        self.assertRaises(reconfigure.AlreadyStandalone,
 
392
        self.assertRaises(errors.AlreadyStandalone,
398
393
                          reconfigure.Reconfigure.to_standalone, tree.controldir)
399
394
 
400
395
    def make_unsynced_branch_reconfiguration(self):
406
401
 
407
402
    def test_unsynced_branch_to_lightweight_checkout_unforced(self):
408
403
        reconfiguration = self.make_unsynced_branch_reconfiguration()
409
 
        self.assertRaises(reconfigure.UnsyncedBranches, reconfiguration.apply)
 
404
        self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
410
405
 
411
406
    def test_unsynced_branch_to_lightweight_checkout_forced(self):
412
407
        reconfiguration = self.make_unsynced_branch_reconfiguration()
433
428
 
434
429
    def test_make_with_trees_already_with_trees(self):
435
430
        repo = self.make_repository_with_without_trees(True)
436
 
        e = self.assertRaises(reconfigure.AlreadyWithTrees,
437
 
                              reconfigure.Reconfigure.set_repository_trees, repo.controldir, True)
 
431
        e = self.assertRaises(errors.AlreadyWithTrees,
 
432
           reconfigure.Reconfigure.set_repository_trees, repo.controldir, True)
438
433
        self.assertContainsRe(str(e),
439
 
                              r"Shared repository '.*' already creates working trees.")
 
434
            r"Shared repository '.*' already creates working trees.")
440
435
 
441
436
    def test_make_without_trees_already_no_trees(self):
442
437
        repo = self.make_repository_with_without_trees(False)
443
 
        e = self.assertRaises(
444
 
            reconfigure.AlreadyWithNoTrees,
445
 
            reconfigure.Reconfigure.set_repository_trees, repo.controldir,
446
 
            False)
447
 
        self.assertContainsRe(
448
 
            str(e),
 
438
        e = self.assertRaises(errors.AlreadyWithNoTrees,
 
439
            reconfigure.Reconfigure.set_repository_trees, repo.controldir, False)
 
440
        self.assertContainsRe(str(e),
449
441
            r"Shared repository '.*' already doesn't create working trees.")
450
442
 
451
443
    def test_repository_tree_reconfiguration_not_supported(self):
452
444
        tree = self.make_branch_and_tree('tree')
453
 
        e = self.assertRaises(
454
 
            reconfigure.ReconfigurationNotSupported,
455
 
            reconfigure.Reconfigure.set_repository_trees, tree.controldir,
456
 
            None)
457
 
        self.assertContainsRe(
458
 
            str(e), r"Requested reconfiguration of '.*' is not supported.")
 
445
        e = self.assertRaises(errors.ReconfigurationNotSupported,
 
446
            reconfigure.Reconfigure.set_repository_trees, tree.controldir, None)
 
447
        self.assertContainsRe(str(e),
 
448
            r"Requested reconfiguration of '.*' is not supported.")
459
449
 
460
450
    def test_lightweight_checkout_to_tree_preserves_reference_locations(self):
461
451
        format = controldir.format_registry.make_controldir('1.9')
462
452
        format.set_branch_format(_mod_bzrbranch.BzrBranchFormat8())
463
453
        tree = self.make_branch_and_tree('tree', format=format)
464
 
        tree.branch.set_reference_info(b'file_id', '../location', 'path')
 
454
        tree.branch.set_reference_info('file_id', 'path', '../location')
465
455
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
466
456
        reconfiguration = reconfigure.Reconfigure.to_tree(checkout.controldir)
467
457
        reconfiguration.apply()
468
458
        checkout_branch = checkout.controldir.open_branch()
469
 
        self.assertEqual(('../location', 'path'),
470
 
                         checkout_branch.get_reference_info(b'file_id'))
 
459
        self.assertEqual(('path', '../location'),
 
460
                         checkout_branch.get_reference_info('file_id'))