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

  • Committer: Jelmer Vernooij
  • Date: 2020-05-06 02:13:25 UTC
  • mfrom: (7490.7.21 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200506021325-awbmmqu1zyorz7sj
Merge 3.1 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    def example_branch(self, path='.'):
46
46
        tree = self.make_branch_and_tree(path)
47
47
        self.build_tree_contents([
48
 
            (osutils.pathjoin(path, 'hello'),   'foo'),
49
 
            (osutils.pathjoin(path, 'goodbye'), 'baz')])
 
48
            (osutils.pathjoin(path, 'hello'), b'foo'),
 
49
            (osutils.pathjoin(path, 'goodbye'), b'baz')])
50
50
        tree.add('hello')
51
51
        tree.commit(message='setup')
52
52
        tree.add('goodbye')
120
120
        """Pull some changes from one branch to another."""
121
121
        a_tree = self.example_branch('a')
122
122
        self.build_tree_contents([
123
 
            ('a/hello2',   'foo'),
124
 
            ('a/goodbye2', 'baz')])
 
123
            ('a/hello2', b'foo'),
 
124
            ('a/goodbye2', b'baz')])
125
125
        a_tree.add('hello2')
126
126
        a_tree.commit(message="setup")
127
127
        a_tree.add('goodbye2')
128
128
        a_tree.commit(message="setup")
129
129
 
130
130
        b_tree = a_tree.controldir.sprout(
131
 
                'b', revision_id=a_tree.branch.get_rev_id(1)).open_workingtree()
 
131
            'b', revision_id=a_tree.branch.get_rev_id(1)).open_workingtree()
132
132
        self.run_bzr('pull -r 2', working_dir='b')
133
133
        a = branch.Branch.open('a')
134
134
        b = branch.Branch.open('b')
145
145
        """
146
146
        # Make a source, sprout a target off it
147
147
        builder = self.make_branch_builder('source')
148
 
        source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(builder)
 
148
        source, rev1, rev2 = fixtures.build_branch_with_non_ancestral_rev(
 
149
            builder)
149
150
        source.get_config_stack().set('branch.fetch_tags', True)
150
151
        target_bzrdir = source.controldir.sprout('target')
151
152
        source.tags.set_tag('tag-a', rev2)
161
162
        # even if the target branch has merged
162
163
        # everything already.
163
164
        a_tree = self.make_branch_and_tree('a')
164
 
        self.build_tree_contents([('a/foo', 'original\n')])
 
165
        self.build_tree_contents([('a/foo', b'original\n')])
165
166
        a_tree.add('foo')
166
167
        a_tree.commit(message='initial commit')
167
168
 
168
169
        b_tree = a_tree.controldir.sprout('b').open_workingtree()
169
170
 
170
 
        self.build_tree_contents([('a/foo', 'changed\n')])
 
171
        self.build_tree_contents([('a/foo', b'changed\n')])
171
172
        a_tree.commit(message='later change')
172
173
 
173
 
        self.build_tree_contents([('a/foo', 'a third change')])
 
174
        self.build_tree_contents([('a/foo', b'a third change')])
174
175
        a_tree.commit(message='a third change')
175
176
 
176
177
        self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
189
190
        # Make sure pull --overwrite sets the revision-history
190
191
        # to be identical to the pull source, even if we have convergence
191
192
        a_tree = self.make_branch_and_tree('a')
192
 
        self.build_tree_contents([('a/foo', 'original\n')])
 
193
        self.build_tree_contents([('a/foo', b'original\n')])
193
194
        a_tree.add('foo')
194
195
        a_tree.commit(message='initial commit')
195
196
 
196
197
        b_tree = a_tree.controldir.sprout('b').open_workingtree()
197
198
 
198
 
        self.build_tree_contents([('a/foo', 'changed\n')])
 
199
        self.build_tree_contents([('a/foo', b'changed\n')])
199
200
        a_tree.commit(message='later change')
200
201
 
201
 
        self.build_tree_contents([('a/foo', 'a third change')])
 
202
        self.build_tree_contents([('a/foo', b'a third change')])
202
203
        a_tree.commit(message='a third change')
203
204
 
204
205
        self.assertEqual(a_tree.branch.last_revision_info()[0], 3)
208
209
 
209
210
        self.assertEqual(b_tree.branch.last_revision_info()[0], 2)
210
211
 
211
 
        self.build_tree_contents([('a/foo', 'a fourth change\n')])
 
212
        self.build_tree_contents([('a/foo', b'a fourth change\n')])
212
213
        a_tree.commit(message='a fourth change')
213
214
 
214
215
        rev_info_a = a_tree.branch.last_revision_info()
244
245
        # test pull for failure without parent set
245
246
        out = self.run_bzr('pull', retcode=3, working_dir='branch_b')
246
247
        self.assertEqual(out,
247
 
                ('', 'brz: ERROR: No pull location known or specified.\n'))
 
248
                         ('', 'brz: ERROR: No pull location known or specified.\n'))
248
249
        # test implicit --remember when no parent set, this pull conflicts
249
250
        self.build_tree(['branch_b/d'])
250
251
        tree_b.add('d')
252
253
        out = self.run_bzr('pull ../branch_a', retcode=3,
253
254
                           working_dir='branch_b')
254
255
        self.assertEqual(out,
255
 
                ('', 'brz: ERROR: These branches have diverged.'
256
 
                    ' Use the missing command to see how.\n'
257
 
                    'Use the merge command to reconcile them.\n'))
 
256
                         ('', 'brz: ERROR: These branches have diverged.'
 
257
                          ' Use the missing command to see how.\n'
 
258
                          'Use the merge command to reconcile them.\n'))
258
259
        tree_b = tree_b.controldir.open_workingtree()
259
260
        branch_b = tree_b.branch
260
261
        self.assertEqual(parent, branch_b.get_parent())
273
274
                         branch_b.get_parent())
274
275
 
275
276
    def test_pull_bundle(self):
276
 
        from breezy.testament import Testament
 
277
        from breezy.bzr.testament import Testament
277
278
        # Build up 2 trees and prepare for a pull
278
279
        tree_a = self.make_branch_and_tree('branch_a')
279
280
        with open('branch_a/a', 'wb') as f:
280
 
            f.write('hello')
 
281
            f.write(b'hello')
281
282
        tree_a.add('a')
282
283
        tree_a.commit('message')
283
284
 
285
286
 
286
287
        # Make a change to 'a' that 'b' can pull
287
288
        with open('branch_a/a', 'wb') as f:
288
 
            f.write('hey there')
 
289
            f.write(b'hey there')
289
290
        tree_a.commit('message')
290
291
 
291
292
        # Create the bundle for 'b' to pull
295
296
        self.assertEqual(out,
296
297
                         'Now on revision 2.\n')
297
298
        self.assertEqual(err,
298
 
                ' M  a\nAll changes applied successfully.\n')
 
299
                         ' M  a\nAll changes applied successfully.\n')
299
300
 
300
301
        self.assertEqualDiff(tree_a.branch.last_revision(),
301
302
                             tree_b.branch.last_revision())
348
349
        source.commit('commit 1')
349
350
        target = source.controldir.sprout('target').open_workingtree()
350
351
        source_last = source.commit('commit 2')
 
352
 
351
353
        class FooService(object):
352
354
            """A directory service that always returns source"""
353
355
 
354
 
            def look_up(self, name, url):
 
356
            def look_up(self, name, url, purpose=None):
355
357
                return 'source'
356
358
        directories.register('foo:', FooService, 'Testing directory service')
357
359
        self.addCleanup(directories.remove, 'foo:')
405
407
        empty = self.make_branch_and_tree('empty', format='1.9')
406
408
        self.reset_smart_call_log()
407
409
        self.run_bzr(['pull', '-r', '1', self.get_url('stacked')],
408
 
            working_dir='empty')
 
410
                     working_dir='empty')
409
411
        # This figure represent the amount of work to perform this use case. It
410
412
        # is entirely ok to reduce this number if a test fails due to rpc_count
411
413
        # being too low. If rpc_count increases, more network roundtrips have
412
414
        # become necessary for this use case. Please do not adjust this number
413
415
        # upwards without agreement from bzr's network support maintainers.
414
 
        self.assertLength(19, self.hpss_calls)
 
416
        self.assertLength(20, self.hpss_calls)
415
417
        self.assertLength(1, self.hpss_connections)
416
418
        remote = branch.Branch.open('stacked')
417
419
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
425
427
        from_tree.commit(message='first commit')
426
428
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
427
429
        self.assertContainsRe(err,
428
 
            "(?m)Doing on-the-fly conversion")
 
430
                              "(?m)Doing on-the-fly conversion")
429
431
 
430
432
    def test_pull_cross_format_warning_no_IDS(self):
431
433
        """You get a warning for probably slow cross-format pulls.
441
443
        from_tree.commit(message='first commit')
442
444
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
443
445
        self.assertContainsRe(err,
444
 
            "(?m)Doing on-the-fly conversion")
 
446
                              "(?m)Doing on-the-fly conversion")
445
447
 
446
448
    def test_pull_cross_format_from_network(self):
447
449
        self.setup_smart_server_with_call_log()
450
452
        self.assertIsInstance(from_tree.branch, remote.RemoteBranch)
451
453
        from_tree.commit(message='first commit')
452
454
        out, err = self.run_bzr(['pull', '-d', 'to',
453
 
            from_tree.branch.controldir.root_transport.base])
 
455
                                 from_tree.branch.controldir.root_transport.base])
454
456
        self.assertContainsRe(err,
455
 
            "(?m)Doing on-the-fly conversion")
 
457
                              "(?m)Doing on-the-fly conversion")
456
458
 
457
459
    def test_pull_to_experimental_format_warning(self):
458
460
        """You get a warning for pulling into experimental formats.
459
461
        """
460
 
        from_tree = self.make_branch_and_tree('from', format='development-subtree')
 
462
        from_tree = self.make_branch_and_tree(
 
463
            'from', format='development-subtree')
461
464
        to_tree = self.make_branch_and_tree('to', format='development-subtree')
462
465
        from_tree.commit(message='first commit')
463
466
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
464
467
        self.assertContainsRe(err,
465
 
            "(?m)Fetching into experimental format")
 
468
                              "(?m)Fetching into experimental format")
466
469
 
467
470
    def test_pull_cross_to_experimental_format_warning(self):
468
471
        """You get a warning for pulling into experimental formats.
472
475
        from_tree.commit(message='first commit')
473
476
        out, err = self.run_bzr(['pull', '-d', 'to', 'from'])
474
477
        self.assertContainsRe(err,
475
 
            "(?m)Fetching into experimental format")
 
478
                              "(?m)Fetching into experimental format")
476
479
 
477
480
    def test_pull_show_base(self):
478
481
        """brz pull supports --show-base
490
493
        with open(osutils.pathjoin('b', 'hello'), 'wt') as f:
491
494
            f.write('fie')
492
495
 
493
 
        out, err=self.run_bzr(['pull', '-d', 'b', 'a', '--show-base'])
 
496
        out, err = self.run_bzr(['pull', '-d', 'b', 'a', '--show-base'])
494
497
 
495
498
        # check for message here
496
499
        self.assertEqual(
517
520
        """pulling tags with conflicts will change the exit code"""
518
521
        # create a branch, see that --show-base fails
519
522
        from_tree = self.make_branch_and_tree('from')
520
 
        from_tree.branch.tags.set_tag("mytag", "somerevid")
 
523
        from_tree.branch.tags.set_tag("mytag", b"somerevid")
521
524
        to_tree = self.make_branch_and_tree('to')
522
 
        to_tree.branch.tags.set_tag("mytag", "anotherrevid")
 
525
        to_tree.branch.tags.set_tag("mytag", b"anotherrevid")
523
526
        out = self.run_bzr(['pull', '-d', 'to', 'from'], retcode=1)
524
527
        self.assertEqual(out,
525
 
            ('No revisions to pull.\nConflicting tags:\n    mytag\n', ''))
 
528
                         ('No revisions to pull.\nConflicting tags:\n    mytag\n', ''))
526
529
 
527
530
    def test_pull_tag_notification(self):
528
531
        """pulling tags with conflicts will change the exit code"""
529
532
        # create a branch, see that --show-base fails
530
533
        from_tree = self.make_branch_and_tree('from')
531
 
        from_tree.branch.tags.set_tag("mytag", "somerevid")
 
534
        from_tree.branch.tags.set_tag("mytag", b"somerevid")
532
535
        to_tree = self.make_branch_and_tree('to')
533
536
        out = self.run_bzr(['pull', '-d', 'to', 'from'])
534
537
        self.assertEqual(out,
535
 
            ('1 tag(s) updated.\n', ''))
 
538
                         ('1 tag(s) updated.\n', ''))
536
539
 
537
540
    def test_overwrite_tags(self):
538
541
        """--overwrite-tags only overwrites tags, not revisions."""
539
542
        from_tree = self.make_branch_and_tree('from')
540
 
        from_tree.branch.tags.set_tag("mytag", "somerevid")
 
543
        from_tree.branch.tags.set_tag("mytag", b"somerevid")
541
544
        to_tree = self.make_branch_and_tree('to')
542
 
        to_tree.branch.tags.set_tag("mytag", "anotherrevid")
 
545
        to_tree.branch.tags.set_tag("mytag", b"anotherrevid")
543
546
        revid1 = to_tree.commit('my commit')
544
547
        out = self.run_bzr(['pull', '-d', 'to', 'from'], retcode=1)
545
548
        self.assertEqual(out,
546
 
            ('No revisions to pull.\nConflicting tags:\n    mytag\n', ''))
 
549
                         ('No revisions to pull.\nConflicting tags:\n    mytag\n', ''))
547
550
        out = self.run_bzr(['pull', '-d', 'to', '--overwrite-tags', 'from'])
548
551
        self.assertEqual(out, ('1 tag(s) updated.\n', ''))
549
552
 
550
553
        self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
551
 
                          'somerevid')
 
554
                         b'somerevid')
552
555
        self.assertEqual(to_tree.branch.last_revision(), revid1)
553
556
 
554
557
    def test_pull_tag_overwrite(self):
555
558
        """pulling tags with --overwrite only reports changed tags."""
556
559
        # create a branch, see that --show-base fails
557
560
        from_tree = self.make_branch_and_tree('from')
558
 
        from_tree.branch.tags.set_tag("mytag", "somerevid")
 
561
        from_tree.branch.tags.set_tag("mytag", b"somerevid")
559
562
        to_tree = self.make_branch_and_tree('to')
560
 
        to_tree.branch.tags.set_tag("mytag", "somerevid")
 
563
        to_tree.branch.tags.set_tag("mytag", b"somerevid")
561
564
        out = self.run_bzr(['pull', '--overwrite', '-d', 'to', 'from'])
562
565
        self.assertEqual(out,
563
 
            ('No revisions or tags to pull.\n', ''))
 
566
                         ('No revisions or tags to pull.\n', ''))
564
567
 
565
568
 
566
569
class TestPullOutput(script.TestCaseWithTransportAndScript):