/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/blackbox/test_push.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-11 04:08:32 UTC
  • mto: (7143.16.20 even-more-cleanups)
  • mto: This revision was merged to the branch mainline in revision 7175.
  • Revision ID: jelmer@jelmer.uk-20181111040832-nsljjynzzwmznf3h
Run autopep8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
        # If there is no parent location set, :parent isn't mentioned.
69
69
        out = self.run_bzr('push', working_dir='a', retcode=3)
70
70
        self.assertEqual(out,
71
 
                ('', 'brz: ERROR: No push location known or specified.\n'))
 
71
                         ('', 'brz: ERROR: No push location known or specified.\n'))
72
72
 
73
73
        # If there is a parent location set, the error suggests :parent.
74
74
        tree_a.branch.set_parent(tree_b.branch.base)
75
75
        out = self.run_bzr('push', working_dir='a', retcode=3)
76
76
        self.assertEqual(out,
77
 
            ('', 'brz: ERROR: No push location known or specified. '
78
 
                'To push to the parent branch '
79
 
                '(at %s), use \'brz push :parent\'.\n' %
80
 
                urlutils.unescape_for_display(tree_b.branch.base, 'utf-8')))
 
77
                         ('', 'brz: ERROR: No push location known or specified. '
 
78
                          'To push to the parent branch '
 
79
                          '(at %s), use \'brz push :parent\'.\n' %
 
80
                          urlutils.unescape_for_display(tree_b.branch.base, 'utf-8')))
81
81
 
82
82
    def test_push_remember(self):
83
83
        """Push changes from one branch to another and test push location."""
103
103
        # test push for failure without push location set
104
104
        out = self.run_bzr('push', working_dir='branch_a', retcode=3)
105
105
        self.assertEqual(out,
106
 
                ('', 'brz: ERROR: No push location known or specified.\n'))
 
106
                         ('', 'brz: ERROR: No push location known or specified.\n'))
107
107
 
108
108
        # test not remembered if cannot actually push
109
109
        self.run_bzr('push path/which/doesnt/exist',
110
110
                     working_dir='branch_a', retcode=3)
111
111
        out = self.run_bzr('push', working_dir='branch_a', retcode=3)
112
112
        self.assertEqual(
113
 
                ('', 'brz: ERROR: No push location known or specified.\n'),
114
 
                out)
 
113
            ('', 'brz: ERROR: No push location known or specified.\n'),
 
114
            out)
115
115
 
116
116
        # test implicit --remember when no push location set, push fails
117
117
        out = self.run_bzr('push ../branch_b',
118
118
                           working_dir='branch_a', retcode=3)
119
119
        self.assertEqual(out,
120
 
                ('', 'brz: ERROR: These branches have diverged.  '
121
 
                 'See "brz help diverged-branches" for more information.\n'))
 
120
                         ('', 'brz: ERROR: These branches have diverged.  '
 
121
                          'See "brz help diverged-branches" for more information.\n'))
122
122
        # Refresh the branch as 'push' modified it
123
123
        branch_a = branch_a.controldir.open_branch()
124
124
        self.assertEqual(osutils.abspath(branch_a.get_push_location()),
125
 
                          osutils.abspath(branch_b.controldir.root_transport.base))
 
125
                         osutils.abspath(branch_b.controldir.root_transport.base))
126
126
 
127
127
        # test implicit --remember after resolving previous failure
128
128
        uncommit.uncommit(branch=branch_b, tree=tree_b)
143
143
        # Refresh the branch as 'push' modified it
144
144
        branch_a = branch_a.controldir.open_branch()
145
145
        self.assertEqual(branch_a.get_push_location(),
146
 
                          branch_c.controldir.root_transport.base)
 
146
                         branch_c.controldir.root_transport.base)
147
147
 
148
148
    def test_push_without_tree(self):
149
149
        # brz push from a branch that does not have a checkout should work.
242
242
    def test_push_dash_d(self):
243
243
        t = self.make_branch_and_tree('from')
244
244
        t.commit(allow_pointless=True,
245
 
                message='first commit')
 
245
                 message='first commit')
246
246
        self.run_bzr('push -d from to-one')
247
247
        self.assertPathExists('to-one')
248
248
        self.run_bzr('push -d %s %s'
249
 
            % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
 
249
                     % tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
250
250
        self.assertPathExists('to-two')
251
251
 
252
252
    def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
264
264
        self.addCleanup(target_repo.lock_read().unlock)
265
265
        # We should have pushed 'C', but not 'B', since it isn't in the
266
266
        # ancestry
267
 
        self.assertEqual([(b'A',), (b'C',)], sorted(target_repo.revisions.keys()))
 
267
        self.assertEqual([(b'A',), (b'C',)], sorted(
 
268
            target_repo.revisions.keys()))
268
269
 
269
270
    def test_push_smart_non_stacked_streaming_acceptance(self):
270
271
        self.setup_smart_server_with_call_log()
289
290
        local.commit(message='local commit')
290
291
        self.reset_smart_call_log()
291
292
        self.run_bzr(['push', '--stacked', '--stacked-on', '../parent',
292
 
            self.get_url('public')], working_dir='local')
 
293
                      self.get_url('public')], working_dir='local')
293
294
        # This figure represent the amount of work to perform this use case. It
294
295
        # is entirely ok to reduce this number if a test fails due to rpc_count
295
296
        # being too low. If rpc_count increases, more network roundtrips have
390
391
 
391
392
        self.run_bzr_error(['Target directory ../target already exists',
392
393
                            'Supply --use-existing-dir',
393
 
                           ],
 
394
                            ],
394
395
                           'push ../target', working_dir='tree')
395
396
 
396
397
        self.run_bzr('push --use-existing-dir ../target',
439
440
        a_controldir = self.make_controldir('dir')
440
441
 
441
442
        self.run_bzr_error(['At ../dir you have a valid .bzr control'],
442
 
                'push ../dir',
443
 
                working_dir='tree')
 
443
                           'push ../dir',
 
444
                           working_dir='tree')
444
445
 
445
446
    def test_push_with_revisionspec(self):
446
447
        """We should be able to push a revision older than the tip."""
466
467
    def create_trunk_and_feature_branch(self):
467
468
        # We have a mainline
468
469
        trunk_tree = self.make_branch_and_tree('target',
469
 
            format='1.9')
 
470
                                               format='1.9')
470
471
        trunk_tree.commit('mainline')
471
472
        # and a branch from it
472
473
        branch_tree = self.make_branch_and_tree('branch',
473
 
            format='1.9')
 
474
                                                format='1.9')
474
475
        branch_tree.pull(trunk_tree.branch)
475
476
        branch_tree.branch.set_parent(trunk_tree.branch.base)
476
477
        # with some work on it
490
491
        trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
491
492
        # we publish branch_tree with a reference to the mainline.
492
493
        out, err = self.run_bzr(['push', '--stacked-on', trunk_tree.branch.base,
493
 
            self.get_url('published')], working_dir='branch')
 
494
                                 self.get_url('published')], working_dir='branch')
494
495
        self.assertEqual('', out)
495
496
        self.assertEqual('Created new stacked branch referring to %s.\n' %
496
 
            trunk_tree.branch.base, err)
 
497
                         trunk_tree.branch.base, err)
497
498
        self.assertPublished(branch_tree.last_revision(),
498
 
            trunk_tree.branch.base)
 
499
                             trunk_tree.branch.base)
499
500
 
500
501
    def test_push_new_branch_stacked_uses_parent_when_no_public_url(self):
501
502
        """When the parent has no public url the parent is used as-is."""
503
504
        # now we do a stacked push, which should determine the public location
504
505
        # for us.
505
506
        out, err = self.run_bzr(['push', '--stacked',
506
 
            self.get_url('published')], working_dir='branch')
 
507
                                 self.get_url('published')], working_dir='branch')
507
508
        self.assertEqual('', out)
508
509
        self.assertEqual('Created new stacked branch referring to %s.\n' %
509
 
            trunk_tree.branch.base, err)
 
510
                         trunk_tree.branch.base, err)
510
511
        self.assertPublished(branch_tree.last_revision(),
511
512
                             trunk_tree.branch.base)
512
513
 
523
524
        # now we do a stacked push, which should determine the public location
524
525
        # for us.
525
526
        out, err = self.run_bzr(['push', '--stacked',
526
 
            self.get_url('published')], working_dir='branch')
 
527
                                 self.get_url('published')], working_dir='branch')
527
528
        self.assertEqual('', out)
528
529
        self.assertEqual('Created new stacked branch referring to %s.\n' %
529
 
            trunk_public_url, err)
 
530
                         trunk_public_url, err)
530
531
        self.assertPublished(branch_tree.last_revision(), trunk_public_url)
531
532
 
532
533
    def test_push_new_branch_stacked_no_parent(self):
536
537
        # cannot be determined.
537
538
        out, err = self.run_bzr_error(
538
539
            ['Could not determine branch to refer to\\.'], ['push', '--stacked',
539
 
            self.get_url('published')], working_dir='branch')
 
540
                                                            self.get_url('published')], working_dir='branch')
540
541
        self.assertEqual('', out)
541
542
        self.assertFalse(self.get_transport('published').has('.'))
542
543
 
581
582
            revision_id=b'rev-1')
582
583
        builder.build_snapshot([b'rev-1'], [], revision_id=b'rev-2')
583
584
        builder.build_snapshot([b'rev-2'],
584
 
            [('modify', ('filename', b'new-content\n'))],
585
 
            revision_id=b'rev-3')
 
585
                               [('modify', ('filename', b'new-content\n'))],
 
586
                               revision_id=b'rev-3')
586
587
        builder.finish_series()
587
588
        branch = builder.get_branch()
588
589
        # Push rev-1 to "trunk", so that we can stack on it.
629
630
        revid1 = to_tree.commit('my commit')
630
631
        out = self.run_bzr(['push', '-d', 'from', 'to'])
631
632
        self.assertEqual(out,
632
 
            ('Conflicting tags:\n    mytag\n', 'No new revisions to push.\n'))
 
633
                         ('Conflicting tags:\n    mytag\n', 'No new revisions to push.\n'))
633
634
        out = self.run_bzr(['push', '-d', 'from', '--overwrite-tags', 'to'])
634
635
        self.assertEqual(out, ('', '1 tag updated.\n'))
635
636
        self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
636
 
                          b'somerevid')
 
637
                         b'somerevid')
637
638
        self.assertEqual(to_tree.branch.last_revision(), revid1)
638
639
 
639
640
 
740
741
    _default_command = ['push', '../to']
741
742
    _default_wd = 'local'
742
743
    _default_errors = ['Working tree ".*/local/" has uncommitted '
743
 
                       'changes \\(See brz status\\)\\.',]
 
744
                       'changes \\(See brz status\\)\\.', ]
744
745
    _default_additional_error = 'Use --no-strict to force the push.\n'
745
746
    _default_additional_warning = 'Uncommitted changes will not be pushed.'
746
747
 
747
 
 
748
748
    def assertPushFails(self, args):
749
749
        out, err = self.run_bzr_error(self._default_errors,
750
750
                                      self._default_command + args,
799
799
 
800
800
strict_push_change_scenarios = [
801
801
    ('uncommitted',
802
 
        dict(_changes_type= '_uncommitted_changes')),
 
802
        dict(_changes_type='_uncommitted_changes')),
803
803
    ('pending-merges',
804
 
        dict(_changes_type= '_pending_merges')),
 
804
        dict(_changes_type='_pending_merges')),
805
805
    ('out-of-sync-trees',
806
 
        dict(_changes_type= '_out_of_sync_trees')),
 
806
        dict(_changes_type='_out_of_sync_trees')),
807
807
    ]
808
808
 
809
809
 
810
810
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
811
811
                                TestPushStrictMixin):
812
812
 
813
 
    scenarios = strict_push_change_scenarios 
814
 
    _changes_type = None # Set by load_tests
 
813
    scenarios = strict_push_change_scenarios
 
814
    _changes_type = None  # Set by load_tests
815
815
 
816
816
    def setUp(self):
817
817
        super(TestPushStrictWithChanges, self).setUp()
845
845
        # Exercise commands from the checkout directory
846
846
        self._default_wd = 'checkout'
847
847
        self._default_errors = ["Working tree is out of date, please run"
848
 
                                " 'brz update'\\.",]
 
848
                                " 'brz update'\\.", ]
849
849
 
850
850
    def test_push_default(self):
851
851
        self.assertPushSucceeds([], with_warning=True)
888
888
        builder = self.make_branch_builder(
889
889
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
890
890
        builder.build_snapshot(None,
891
 
            [('add', ('', b'TREE_ROOT', 'directory', None)),
892
 
             ('add', ('foo', b'fooid', 'file', b'bar'))],
893
 
            revision_id=b'revid')
 
891
                               [('add', ('', b'TREE_ROOT', 'directory', None)),
 
892
                                ('add', ('foo', b'fooid', 'file', b'bar'))],
 
893
                               revision_id=b'revid')
894
894
        return builder
895
895
 
896
896
    def test_no_roundtripping(self):
899
899
        output, error = self.run_bzr("push -d dc dp", retcode=3)
900
900
        self.assertEqual("", output)
901
901
        self.assertEqual(error, "brz: ERROR: It is not possible to losslessly"
902
 
            " push to dummy. You may want to use dpush instead.\n")
 
902
                         " push to dummy. You may want to use dpush instead.\n")
903
903
 
904
904
 
905
905
class TestPushOutput(script.TestCaseWithTransportAndScript):