/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_branch.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
"""
24
24
 
25
25
from .. import (
26
 
    bedding,
27
26
    branch as _mod_branch,
28
27
    config,
29
28
    controldir,
41
40
    BzrBranchFormat5,
42
41
    )
43
42
from ..sixish import (
44
 
    StringIO,
 
43
    BytesIO,
45
44
    )
46
45
 
47
46
 
62
61
    def test_default_format(self):
63
62
        # update this if you change the default branch format
64
63
        self.assertIsInstance(_mod_branch.format_registry.get_default(),
65
 
                              _mod_bzrbranch.BzrBranchFormat7)
 
64
                _mod_bzrbranch.BzrBranchFormat7)
66
65
 
67
66
    def test_default_format_is_same_as_bzrdir_default(self):
68
67
        # XXX: it might be nice if there was only one place the default was
113
112
        branch = self.make_branch('.', format='knit')
114
113
        branch.set_push_location('foo')
115
114
        local_path = urlutils.local_path_from_url(branch.base[:-1])
116
 
        self.assertFileEqual(b"# comment\n"
117
 
                             b"[%s]\n"
118
 
                             b"push_location = foo\n"
119
 
                             b"push_location:policy = norecurse\n" % local_path.encode(
120
 
                                 'utf-8'),
121
 
                             bedding.locations_config_path())
 
115
        self.assertFileEqual("# comment\n"
 
116
                             "[%s]\n"
 
117
                             "push_location = foo\n"
 
118
                             "push_location:policy = norecurse\n" % local_path,
 
119
                             config.locations_config_filename())
122
120
 
123
121
    # TODO RBC 20051029 test getting a push location from a branch in a
124
122
    # recursive section - that is, it appends the branch name.
156
154
SampleSupportedBranchFormatString = b"Sample supported branch format."
157
155
 
158
156
# And the format class can then reference the constant to avoid skew.
159
 
 
160
 
 
161
157
class SampleSupportedBranchFormat(_mod_bzrbranch.BranchFormatMetadir):
162
158
    """A sample supported format."""
163
159
 
203
199
        # create a branch with a few known format objects.
204
200
        # this is not quite the same as
205
201
        self.build_tree(["foo/", "bar/"])
206
 
 
207
202
        def check_format(format, url):
208
203
            dir = format._matchingcontroldir.initialize(url)
209
204
            dir.create_repository()
217
212
            SampleBranchFormat.from_string(b"Sample branch format."),
218
213
            SampleBranchFormat)
219
214
        self.assertRaises(AssertionError,
220
 
                          SampleBranchFormat.from_string, b"Different branch format.")
 
215
            SampleBranchFormat.from_string, b"Different branch format.")
221
216
 
222
217
    def test_find_format_not_branch(self):
223
218
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
235
230
    def test_find_format_with_features(self):
236
231
        tree = self.make_branch_and_tree('.', format='2a')
237
232
        tree.branch.update_feature_flags({b"name": b"optional"})
238
 
        found_format = _mod_bzrbranch.BranchFormatMetadir.find_format(
239
 
            tree.controldir)
 
233
        found_format = _mod_bzrbranch.BranchFormatMetadir.find_format(tree.controldir)
240
234
        self.assertIsInstance(found_format, _mod_bzrbranch.BranchFormatMetadir)
241
235
        self.assertEqual(found_format.features.get(b"name"), b"optional")
242
236
        tree.branch.update_feature_flags({b"name": None})
260
254
        format = SampleBranchFormat()
261
255
        self.registry.register(format)
262
256
        self.assertEqual(format,
263
 
                         self.registry.get(b"Sample branch format."))
 
257
            self.registry.get(b"Sample branch format."))
264
258
        self.registry.remove(format)
265
259
        self.assertRaises(KeyError, self.registry.get,
266
 
                          b"Sample branch format.")
 
260
            b"Sample branch format.")
267
261
 
268
262
    def test_get_all(self):
269
263
        format = SampleBranchFormat()
280
274
    def test_register_extra_lazy(self):
281
275
        self.assertEqual([], self.registry._get_all())
282
276
        self.registry.register_extra_lazy("breezy.tests.test_branch",
283
 
                                          "SampleExtraBranchFormat")
 
277
            "SampleExtraBranchFormat")
284
278
        formats = self.registry._get_all()
285
279
        self.assertEqual(1, len(formats))
286
280
        self.assertIsInstance(formats[0], SampleExtraBranchFormat)
327
321
        self.assertPathDoesNotExist('a/.bzr/branch/bound')
328
322
        self.assertEqual('ftp://example.com', branch.get_bound_location())
329
323
 
330
 
    def do_checkout_test(self, lightweight):
 
324
    def do_checkout_test(self, lightweight=False):
331
325
        tree = self.make_branch_and_tree('source',
332
 
                                         format=self.get_format_name_subtree())
 
326
            format=self.get_format_name_subtree())
333
327
        subtree = self.make_branch_and_tree('source/subtree',
334
 
                                            format=self.get_format_name_subtree())
 
328
            format=self.get_format_name_subtree())
335
329
        subsubtree = self.make_branch_and_tree('source/subtree/subsubtree',
336
 
                                               format=self.get_format_name_subtree())
 
330
            format=self.get_format_name_subtree())
337
331
        self.build_tree(['source/subtree/file',
338
332
                         'source/subtree/subsubtree/file'])
339
333
        subsubtree.add('file')
340
334
        subtree.add('file')
341
335
        subtree.add_reference(subsubtree)
342
 
        subtree.set_reference_info('subsubtree', subsubtree.branch.user_url)
343
336
        tree.add_reference(subtree)
344
 
        tree.set_reference_info('subtree', subtree.branch.user_url)
345
337
        tree.commit('a revision')
346
338
        subtree.commit('a subtree file')
347
339
        subsubtree.commit('a subsubtree file')
357
349
            self.assertEndsWith(subbranch.base, 'target/subtree/subsubtree/')
358
350
 
359
351
    def test_checkout_with_references(self):
360
 
        self.do_checkout_test(lightweight=False)
 
352
        self.do_checkout_test()
361
353
 
362
354
    def test_light_checkout_with_references(self):
363
355
        self.do_checkout_test(lightweight=True)
377
369
    def test_set_stacked_on_url_errors(self):
378
370
        branch = self.make_branch('a', format=self.get_format_name())
379
371
        self.assertRaises(_mod_branch.UnstackableBranchFormat,
380
 
                          branch.set_stacked_on_url, None)
 
372
            branch.set_stacked_on_url, None)
381
373
 
382
374
    def test_default_stacked_location(self):
383
375
        branch = self.make_branch('a', format=self.get_format_name())
384
 
        self.assertRaises(_mod_branch.UnstackableBranchFormat,
385
 
                          branch.get_stacked_on_url)
 
376
        self.assertRaises(_mod_branch.UnstackableBranchFormat, branch.get_stacked_on_url)
386
377
 
387
378
 
388
379
class TestBranch7(TestBranch67, tests.TestCaseWithTransport):
402
393
        branch = _mod_bzrbranch.BzrBranchFormat7().initialize(control)
403
394
        target = self.make_branch('b')
404
395
        self.assertRaises(errors.UnstackableRepositoryFormat,
405
 
                          branch.set_stacked_on_url, target.base)
 
396
            branch.set_stacked_on_url, target.base)
406
397
 
407
398
    def test_clone_stacked_on_unstackable_repo(self):
408
399
        repo = self.make_repository('a', format='dirstate-tags')
446
437
 
447
438
    def create_branch_with_reference(self):
448
439
        branch = self.make_branch('branch')
449
 
        branch._set_all_reference_info({'path': ('location', b'file-id')})
 
440
        branch._set_all_reference_info({'path': ('location', 'file-id')})
450
441
        return branch
451
442
 
452
443
    @staticmethod
453
444
    def instrument_branch(branch, gets):
454
445
        old_get = branch._transport.get
455
 
 
456
446
        def get(*args, **kwargs):
457
447
            gets.append((args, kwargs))
458
448
            return old_get(*args, **kwargs)
482
472
        branch.lock_write()
483
473
        self.instrument_branch(branch, gets)
484
474
        self.addCleanup(branch.unlock)
485
 
        branch._set_all_reference_info({'path2': ('location2', b'file-id')})
 
475
        branch._set_all_reference_info({'path2': ('location2', 'file-id')})
486
476
        location, file_id = branch.get_reference_info('path2')
487
477
        self.assertEqual(0, len(gets))
488
 
        self.assertEqual(b'file-id', file_id)
 
478
        self.assertEqual('file-id', file_id)
489
479
        self.assertEqual('location2', location)
490
480
 
491
481
    def test_reference_info_caches_cleared(self):
492
482
        branch = self.make_branch('branch')
493
483
        with branch.lock_write():
494
 
            branch.set_reference_info(b'file-id', 'location2', 'path2')
 
484
            branch.set_reference_info('path2', 'location2', b'file-id')
495
485
        doppelganger = _mod_branch.Branch.open('branch')
496
 
        doppelganger.set_reference_info(b'file-id', 'location3', 'path3')
497
 
        self.assertEqual(('location3', 'path3'),
498
 
                         branch.get_reference_info(b'file-id'))
 
486
        doppelganger.set_reference_info('path3', 'location3', b'file-id')
 
487
        self.assertEqual(('location3', b'file-id'),
 
488
                         branch.get_reference_info('path3'))
499
489
 
500
490
    def _recordParentMapCalls(self, repo):
501
491
        self._parent_map_calls = []
502
492
        orig_get_parent_map = repo.revisions.get_parent_map
503
 
 
504
493
        def get_parent_map(q):
505
494
            q = list(q)
506
495
            self._parent_map_calls.extend([e[0] for e in q])
533
522
        reference_url = branch.controldir.root_transport.abspath('') + '/'
534
523
        # if the api for create_checkout changes to return different checkout types
535
524
        # then this file read will fail.
536
 
        self.assertFileEqual(reference_url.encode('utf-8'),
537
 
                             'checkout/.bzr/branch/location')
 
525
        self.assertFileEqual(reference_url, 'checkout/.bzr/branch/location')
538
526
        self.assertEqual(reference_url,
539
 
                         _mod_bzrbranch.BranchReferenceFormat().get_reference(checkout.controldir))
 
527
            _mod_bzrbranch.BranchReferenceFormat().get_reference(checkout.controldir))
540
528
 
541
529
 
542
530
class TestHooks(tests.TestCaseWithTransport):
545
533
        """Check that creating a BranchHooks instance has the right defaults."""
546
534
        hooks = _mod_branch.BranchHooks()
547
535
        self.assertTrue("post_push" in hooks, "post_push not in %s" % hooks)
548
 
        self.assertTrue("post_commit" in hooks,
549
 
                        "post_commit not in %s" % hooks)
 
536
        self.assertTrue("post_commit" in hooks, "post_commit not in %s" % hooks)
550
537
        self.assertTrue("pre_commit" in hooks, "pre_commit not in %s" % hooks)
551
538
        self.assertTrue("post_pull" in hooks, "post_pull not in %s" % hooks)
552
539
        self.assertTrue("post_uncommit" in hooks,
567
554
    def test_post_branch_init_hook(self):
568
555
        calls = []
569
556
        _mod_branch.Branch.hooks.install_named_hook('post_branch_init',
570
 
                                                    calls.append, None)
 
557
            calls.append, None)
571
558
        self.assertLength(0, calls)
572
559
        branch = self.make_branch('a')
573
560
        self.assertLength(1, calls)
579
566
    def test_post_branch_init_hook_repr(self):
580
567
        param_reprs = []
581
568
        _mod_branch.Branch.hooks.install_named_hook('post_branch_init',
582
 
                                                    lambda params: param_reprs.append(repr(params)), None)
 
569
            lambda params: param_reprs.append(repr(params)), None)
583
570
        branch = self.make_branch('a')
584
571
        self.assertLength(1, param_reprs)
585
572
        param_repr = param_reprs[0]
589
576
        from .. import switch
590
577
        calls = []
591
578
        _mod_branch.Branch.hooks.install_named_hook('post_switch',
592
 
                                                    calls.append, None)
 
579
            calls.append, None)
593
580
        tree = self.make_branch_and_tree('branch-1')
594
581
        self.build_tree(['branch-1/file-1'])
595
582
        tree.add('file-1')
625
612
 
626
613
    def test_valid_append_revisions_only(self):
627
614
        self.assertEqual(None,
628
 
                         self.config_stack.get('append_revisions_only'))
 
615
                          self.config_stack.get('append_revisions_only'))
629
616
        self.check_append_revisions_only(None)
630
617
        self.check_append_revisions_only(False, 'False')
631
618
        self.check_append_revisions_only(True, 'True')
637
624
    def test_invalid_append_revisions_only(self):
638
625
        """Ensure warning is noted on invalid settings"""
639
626
        self.warnings = []
640
 
 
641
627
        def warning(*args):
642
628
            self.warnings.append(args[0] % args[1:])
643
629
        self.overrideAttr(trace, 'warning', warning)
697
683
 
698
684
    def test_report_changed(self):
699
685
        r = _mod_branch.PullResult()
700
 
        r.old_revid = b"old-revid"
 
686
        r.old_revid = "old-revid"
701
687
        r.old_revno = 10
702
 
        r.new_revid = b"new-revid"
 
688
        r.new_revid = "new-revid"
703
689
        r.new_revno = 20
704
 
        f = StringIO()
 
690
        f = BytesIO()
705
691
        r.report(f)
706
692
        self.assertEqual("Now on revision 20.\n", f.getvalue())
 
693
        self.assertEqual("Now on revision 20.\n", f.getvalue())
707
694
 
708
695
    def test_report_unchanged(self):
709
696
        r = _mod_branch.PullResult()
710
 
        r.old_revid = b"same-revid"
711
 
        r.new_revid = b"same-revid"
712
 
        f = StringIO()
 
697
        r.old_revid = "same-revid"
 
698
        r.new_revid = "same-revid"
 
699
        f = BytesIO()
713
700
        r.report(f)
714
701
        self.assertEqual("No revisions or tags to pull.\n", f.getvalue())