/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: 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:
22
22
from breezy import (
23
23
    branch,
24
24
    controldir,
25
 
    directory_service,
26
25
    errors,
27
26
    osutils,
28
27
    tests,
41
40
    script,
42
41
    test_foreign,
43
42
    )
 
43
from breezy.tests.matchers import ContainsNoVfsCalls
44
44
from breezy.transport import memory
45
45
 
46
46
 
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.
208
208
        tree_a = make_shared_tree('a')
209
209
        self.build_tree(['repo/a/file'])
210
210
        tree_a.add('file')
211
 
        tree_a.commit('commit a-1', rev_id=b'a-1')
 
211
        tree_a.commit('commit a-1', rev_id='a-1')
212
212
        f = open('repo/a/file', 'ab')
213
 
        f.write(b'more stuff\n')
 
213
        f.write('more stuff\n')
214
214
        f.close()
215
 
        tree_a.commit('commit a-2', rev_id=b'a-2')
 
215
        tree_a.commit('commit a-2', rev_id='a-2')
216
216
 
217
217
        tree_b = make_shared_tree('b')
218
218
        self.build_tree(['repo/b/file'])
219
219
        tree_b.add('file')
220
 
        tree_b.commit('commit b-1', rev_id=b'b-1')
 
220
        tree_b.commit('commit b-1', rev_id='b-1')
221
221
 
222
 
        self.assertTrue(shared_repo.has_revision(b'a-1'))
223
 
        self.assertTrue(shared_repo.has_revision(b'a-2'))
224
 
        self.assertTrue(shared_repo.has_revision(b'b-1'))
 
222
        self.assertTrue(shared_repo.has_revision('a-1'))
 
223
        self.assertTrue(shared_repo.has_revision('a-2'))
 
224
        self.assertTrue(shared_repo.has_revision('b-1'))
225
225
 
226
226
        # Now that we have a repository with shared files, make sure
227
227
        # that things aren't copied out by a 'push'
228
228
        self.run_bzr('push ../../push-b', working_dir='repo/b')
229
229
        pushed_tree = workingtree.WorkingTree.open('push-b')
230
230
        pushed_repo = pushed_tree.branch.repository
231
 
        self.assertFalse(pushed_repo.has_revision(b'a-1'))
232
 
        self.assertFalse(pushed_repo.has_revision(b'a-2'))
233
 
        self.assertTrue(pushed_repo.has_revision(b'b-1'))
 
231
        self.assertFalse(pushed_repo.has_revision('a-1'))
 
232
        self.assertFalse(pushed_repo.has_revision('a-2'))
 
233
        self.assertTrue(pushed_repo.has_revision('b-1'))
234
234
 
235
235
    def test_push_funky_id(self):
236
236
        t = self.make_branch_and_tree('tree')
237
237
        self.build_tree(['tree/filename'])
238
 
        t.add('filename', b'funky-chars<>%&;"\'')
 
238
        t.add('filename', 'funky-chars<>%&;"\'')
239
239
        t.commit('commit filename')
240
240
        self.run_bzr('push -d tree new-tree')
241
241
 
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):
254
254
        target_repo = self.make_repository('target')
255
255
        source = self.make_branch_builder('source')
256
256
        source.start_series()
257
 
        source.build_snapshot(None, [
258
 
            ('add', ('', b'root-id', 'directory', None))],
259
 
            revision_id=b'A')
260
 
        source.build_snapshot([b'A'], [], revision_id=b'B')
261
 
        source.build_snapshot([b'A'], [], revision_id=b'C')
 
257
        source.build_snapshot('A', None, [
 
258
            ('add', ('', 'root-id', 'directory', None))])
 
259
        source.build_snapshot('B', ['A'], [])
 
260
        source.build_snapshot('C', ['A'], [])
262
261
        source.finish_series()
263
262
        self.run_bzr('push target -d source')
264
263
        self.addCleanup(target_repo.lock_read().unlock)
265
264
        # We should have pushed 'C', but not 'B', since it isn't in the
266
265
        # ancestry
267
 
        self.assertEqual([(b'A',), (b'C',)], sorted(
268
 
            target_repo.revisions.keys()))
 
266
        self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
 
267
 
 
268
    def test_push_smart_non_stacked_streaming_acceptance(self):
 
269
        self.setup_smart_server_with_call_log()
 
270
        t = self.make_branch_and_tree('from')
 
271
        t.commit(allow_pointless=True, message='first commit')
 
272
        self.reset_smart_call_log()
 
273
        self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
 
274
        # This figure represent the amount of work to perform this use case. It
 
275
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
276
        # being too low. If rpc_count increases, more network roundtrips have
 
277
        # become necessary for this use case. Please do not adjust this number
 
278
        # upwards without agreement from bzr's network support maintainers.
 
279
        self.assertLength(9, self.hpss_calls)
 
280
        self.assertLength(1, self.hpss_connections)
 
281
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
282
 
 
283
    def test_push_smart_stacked_streaming_acceptance(self):
 
284
        self.setup_smart_server_with_call_log()
 
285
        parent = self.make_branch_and_tree('parent', format='1.9')
 
286
        parent.commit(message='first commit')
 
287
        local = parent.controldir.sprout('local').open_workingtree()
 
288
        local.commit(message='local commit')
 
289
        self.reset_smart_call_log()
 
290
        self.run_bzr(['push', '--stacked', '--stacked-on', '../parent',
 
291
            self.get_url('public')], working_dir='local')
 
292
        # This figure represent the amount of work to perform this use case. It
 
293
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
294
        # being too low. If rpc_count increases, more network roundtrips have
 
295
        # become necessary for this use case. Please do not adjust this number
 
296
        # upwards without agreement from bzr's network support maintainers.
 
297
        self.assertLength(15, self.hpss_calls)
 
298
        self.assertLength(1, self.hpss_connections)
 
299
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
300
        remote = branch.Branch.open('public')
 
301
        self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
 
302
 
 
303
    def test_push_smart_tags_streaming_acceptance(self):
 
304
        self.setup_smart_server_with_call_log()
 
305
        t = self.make_branch_and_tree('from')
 
306
        rev_id = t.commit(allow_pointless=True, message='first commit')
 
307
        t.branch.tags.set_tag('new-tag', rev_id)
 
308
        self.reset_smart_call_log()
 
309
        self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
 
310
        # This figure represent the amount of work to perform this use case. It
 
311
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
312
        # being too low. If rpc_count increases, more network roundtrips have
 
313
        # become necessary for this use case. Please do not adjust this number
 
314
        # upwards without agreement from bzr's network support maintainers.
 
315
        self.assertLength(11, self.hpss_calls)
 
316
        self.assertLength(1, self.hpss_connections)
 
317
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
318
 
 
319
    def test_push_smart_incremental_acceptance(self):
 
320
        self.setup_smart_server_with_call_log()
 
321
        t = self.make_branch_and_tree('from')
 
322
        rev_id1 = t.commit(allow_pointless=True, message='first commit')
 
323
        rev_id2 = t.commit(allow_pointless=True, message='second commit')
 
324
        self.run_bzr(
 
325
            ['push', self.get_url('to-one'), '-r1'], working_dir='from')
 
326
        self.reset_smart_call_log()
 
327
        self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
 
328
        # This figure represent the amount of work to perform this use case. It
 
329
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
330
        # being too low. If rpc_count increases, more network roundtrips have
 
331
        # become necessary for this use case. Please do not adjust this number
 
332
        # upwards without agreement from bzr's network support maintainers.
 
333
        self.assertLength(11, self.hpss_calls)
 
334
        self.assertLength(1, self.hpss_connections)
 
335
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
269
336
 
270
337
    def test_push_smart_with_default_stacking_url_path_segment(self):
271
338
        # If the default stacked-on location is a path element then branches
295
362
    def create_simple_tree(self):
296
363
        tree = self.make_branch_and_tree('tree')
297
364
        self.build_tree(['tree/a'])
298
 
        tree.add(['a'], [b'a-id'])
299
 
        tree.commit('one', rev_id=b'r1')
 
365
        tree.add(['a'], ['a-id'])
 
366
        tree.commit('one', rev_id='r1')
300
367
        return tree
301
368
 
302
369
    def test_push_create_prefix(self):
322
389
 
323
390
        self.run_bzr_error(['Target directory ../target already exists',
324
391
                            'Supply --use-existing-dir',
325
 
                            ],
 
392
                           ],
326
393
                           'push ../target', working_dir='tree')
327
394
 
328
395
        self.run_bzr('push --use-existing-dir ../target',
371
438
        a_controldir = self.make_controldir('dir')
372
439
 
373
440
        self.run_bzr_error(['At ../dir you have a valid .bzr control'],
374
 
                           'push ../dir',
375
 
                           working_dir='tree')
 
441
                'push ../dir',
 
442
                working_dir='tree')
376
443
 
377
444
    def test_push_with_revisionspec(self):
378
445
        """We should be able to push a revision older than the tip."""
379
446
        tree_from = self.make_branch_and_tree('from')
380
 
        tree_from.commit("One.", rev_id=b"from-1")
381
 
        tree_from.commit("Two.", rev_id=b"from-2")
 
447
        tree_from.commit("One.", rev_id="from-1")
 
448
        tree_from.commit("Two.", rev_id="from-2")
382
449
 
383
450
        self.run_bzr('push -r1 ../to', working_dir='from')
384
451
 
385
452
        tree_to = workingtree.WorkingTree.open('to')
386
453
        repo_to = tree_to.branch.repository
387
 
        self.assertTrue(repo_to.has_revision(b'from-1'))
388
 
        self.assertFalse(repo_to.has_revision(b'from-2'))
389
 
        self.assertEqual(tree_to.branch.last_revision_info()[1], b'from-1')
 
454
        self.assertTrue(repo_to.has_revision('from-1'))
 
455
        self.assertFalse(repo_to.has_revision('from-2'))
 
456
        self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
390
457
        self.assertFalse(
391
458
            tree_to.changes_from(tree_to.basis_tree()).has_changed())
392
459
 
398
465
    def create_trunk_and_feature_branch(self):
399
466
        # We have a mainline
400
467
        trunk_tree = self.make_branch_and_tree('target',
401
 
                                               format='1.9')
 
468
            format='1.9')
402
469
        trunk_tree.commit('mainline')
403
470
        # and a branch from it
404
471
        branch_tree = self.make_branch_and_tree('branch',
405
 
                                                format='1.9')
 
472
            format='1.9')
406
473
        branch_tree.pull(trunk_tree.branch)
407
474
        branch_tree.branch.set_parent(trunk_tree.branch.base)
408
475
        # with some work on it
422
489
        trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
423
490
        # we publish branch_tree with a reference to the mainline.
424
491
        out, err = self.run_bzr(['push', '--stacked-on', trunk_tree.branch.base,
425
 
                                 self.get_url('published')], working_dir='branch')
426
 
        self.assertEqual('', out)
427
 
        self.assertEqual('Created new stacked branch referring to %s.\n' %
428
 
                         trunk_tree.branch.base, err)
429
 
        self.assertPublished(branch_tree.last_revision(),
430
 
                             trunk_tree.branch.base)
431
 
 
432
 
    def test_push_new_branch_stacked_on(self):
433
 
        """Pushing a new branch with --stacked-on can use directory URLs."""
434
 
        trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
435
 
        class FooDirectory(object):
436
 
            def look_up(self, name, url, purpose=None):
437
 
                if url == 'foo:':
438
 
                    return trunk_tree.branch.base
439
 
                return url
440
 
        directory_service.directories.register('foo:', FooDirectory, 'Foo directory')
441
 
        self.addCleanup(directory_service.directories.remove, 'foo:')
442
 
        # we publish branch_tree with a reference to the mainline.
443
 
        out, err = self.run_bzr(['push', '--stacked-on', 'foo:',
444
 
                                 self.get_url('published')], working_dir='branch')
445
 
        self.assertEqual('', out)
446
 
        self.assertEqual('Created new stacked branch referring to %s.\n' %
447
 
                         trunk_tree.branch.base, err)
448
 
        self.assertPublished(branch_tree.last_revision(),
449
 
                             trunk_tree.branch.base)
 
492
            self.get_url('published')], working_dir='branch')
 
493
        self.assertEqual('', out)
 
494
        self.assertEqual('Created new stacked branch referring to %s.\n' %
 
495
            trunk_tree.branch.base, err)
 
496
        self.assertPublished(branch_tree.last_revision(),
 
497
            trunk_tree.branch.base)
450
498
 
451
499
    def test_push_new_branch_stacked_uses_parent_when_no_public_url(self):
452
500
        """When the parent has no public url the parent is used as-is."""
454
502
        # now we do a stacked push, which should determine the public location
455
503
        # for us.
456
504
        out, err = self.run_bzr(['push', '--stacked',
457
 
                                 self.get_url('published')], working_dir='branch')
 
505
            self.get_url('published')], working_dir='branch')
458
506
        self.assertEqual('', out)
459
507
        self.assertEqual('Created new stacked branch referring to %s.\n' %
460
 
                         trunk_tree.branch.base, err)
 
508
            trunk_tree.branch.base, err)
461
509
        self.assertPublished(branch_tree.last_revision(),
462
510
                             trunk_tree.branch.base)
463
511
 
474
522
        # now we do a stacked push, which should determine the public location
475
523
        # for us.
476
524
        out, err = self.run_bzr(['push', '--stacked',
477
 
                                 self.get_url('published')], working_dir='branch')
 
525
            self.get_url('published')], working_dir='branch')
478
526
        self.assertEqual('', out)
479
527
        self.assertEqual('Created new stacked branch referring to %s.\n' %
480
 
                         trunk_public_url, err)
 
528
            trunk_public_url, err)
481
529
        self.assertPublished(branch_tree.last_revision(), trunk_public_url)
482
530
 
483
531
    def test_push_new_branch_stacked_no_parent(self):
487
535
        # cannot be determined.
488
536
        out, err = self.run_bzr_error(
489
537
            ['Could not determine branch to refer to\\.'], ['push', '--stacked',
490
 
                                                            self.get_url('published')], working_dir='branch')
 
538
            self.get_url('published')], working_dir='branch')
491
539
        self.assertEqual('', out)
492
540
        self.assertFalse(self.get_transport('published').has('.'))
493
541
 
513
561
        self.make_branch('from', format='pack-0.92')
514
562
        out, err = self.run_bzr('push -d from to')
515
563
        b = branch.Branch.open('to')
516
 
        self.assertRaises(branch.UnstackableBranchFormat, b.get_stacked_on_url)
 
564
        self.assertRaises(errors.UnstackableBranchFormat, b.get_stacked_on_url)
517
565
 
518
566
    def test_push_doesnt_create_broken_branch(self):
519
567
        """Pushing a new standalone branch works even when there's a default
526
574
        self.make_repository('repo', shared=True, format='1.6')
527
575
        builder = self.make_branch_builder('repo/local', format='pack-0.92')
528
576
        builder.start_series()
529
 
        builder.build_snapshot(None, [
530
 
            ('add', ('', b'root-id', 'directory', '')),
531
 
            ('add', ('filename', b'f-id', 'file', b'content\n'))],
532
 
            revision_id=b'rev-1')
533
 
        builder.build_snapshot([b'rev-1'], [], revision_id=b'rev-2')
534
 
        builder.build_snapshot([b'rev-2'],
535
 
                               [('modify', ('filename', b'new-content\n'))],
536
 
                               revision_id=b'rev-3')
 
577
        builder.build_snapshot('rev-1', None, [
 
578
            ('add', ('', 'root-id', 'directory', '')),
 
579
            ('add', ('filename', 'f-id', 'file', 'content\n'))])
 
580
        builder.build_snapshot('rev-2', ['rev-1'], [])
 
581
        builder.build_snapshot('rev-3', ['rev-2'],
 
582
            [('modify', ('f-id', 'new-content\n'))])
537
583
        builder.finish_series()
538
584
        branch = builder.get_branch()
539
585
        # Push rev-1 to "trunk", so that we can stack on it.
565
611
    def test_push_from_subdir(self):
566
612
        t = self.make_branch_and_tree('tree')
567
613
        self.build_tree(['tree/dir/', 'tree/dir/file'])
568
 
        t.add(['dir', 'dir/file'])
 
614
        t.add('dir', 'dir/file')
569
615
        t.commit('r1')
570
616
        out, err = self.run_bzr('push ../../pushloc', working_dir='tree/dir')
571
617
        self.assertEqual('', out)
574
620
    def test_overwrite_tags(self):
575
621
        """--overwrite-tags only overwrites tags, not revisions."""
576
622
        from_tree = self.make_branch_and_tree('from')
577
 
        from_tree.branch.tags.set_tag("mytag", b"somerevid")
 
623
        from_tree.branch.tags.set_tag("mytag", "somerevid")
578
624
        to_tree = self.make_branch_and_tree('to')
579
 
        to_tree.branch.tags.set_tag("mytag", b"anotherrevid")
 
625
        to_tree.branch.tags.set_tag("mytag", "anotherrevid")
580
626
        revid1 = to_tree.commit('my commit')
581
627
        out = self.run_bzr(['push', '-d', 'from', 'to'])
582
628
        self.assertEqual(out,
583
 
                         ('Conflicting tags:\n    mytag\n', 'No new revisions to push.\n'))
 
629
            ('Conflicting tags:\n    mytag\n', 'No new revisions to push.\n'))
584
630
        out = self.run_bzr(['push', '-d', 'from', '--overwrite-tags', 'to'])
585
631
        self.assertEqual(out, ('', '1 tag updated.\n'))
586
632
        self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
587
 
                         b'somerevid')
 
633
                          'somerevid')
588
634
        self.assertEqual(to_tree.branch.last_revision(), revid1)
589
635
 
590
636
 
678
724
 
679
725
    def make_local_branch_and_tree(self):
680
726
        self.tree = self.make_branch_and_tree('local')
681
 
        self.build_tree_contents([('local/file', b'initial')])
 
727
        self.build_tree_contents([('local/file', 'initial')])
682
728
        self.tree.add('file')
683
 
        self.tree.commit('adding file', rev_id=b'added')
684
 
        self.build_tree_contents([('local/file', b'modified')])
685
 
        self.tree.commit('modify file', rev_id=b'modified')
 
729
        self.tree.commit('adding file', rev_id='added')
 
730
        self.build_tree_contents([('local/file', 'modified')])
 
731
        self.tree.commit('modify file', rev_id='modified')
686
732
 
687
733
    def set_config_push_strict(self, value):
688
734
        br = branch.Branch.open('local')
691
737
    _default_command = ['push', '../to']
692
738
    _default_wd = 'local'
693
739
    _default_errors = ['Working tree ".*/local/" has uncommitted '
694
 
                       'changes \\(See brz status\\)\\.', ]
 
740
                       'changes \(See brz status\)\.',]
695
741
    _default_additional_error = 'Use --no-strict to force the push.\n'
696
742
    _default_additional_warning = 'Uncommitted changes will not be pushed.'
697
743
 
 
744
 
698
745
    def assertPushFails(self, args):
699
746
        out, err = self.run_bzr_error(self._default_errors,
700
747
                                      self._default_command + args,
722
769
        self.assertEqual(revid_to_push, branch_to.last_revision())
723
770
 
724
771
 
 
772
 
725
773
class TestPushStrictWithoutChanges(tests.TestCaseWithTransport,
726
774
                                   TestPushStrictMixin):
727
775
 
749
797
 
750
798
strict_push_change_scenarios = [
751
799
    ('uncommitted',
752
 
        dict(_changes_type='_uncommitted_changes')),
 
800
        dict(_changes_type= '_uncommitted_changes')),
753
801
    ('pending-merges',
754
 
        dict(_changes_type='_pending_merges')),
 
802
        dict(_changes_type= '_pending_merges')),
755
803
    ('out-of-sync-trees',
756
 
        dict(_changes_type='_out_of_sync_trees')),
 
804
        dict(_changes_type= '_out_of_sync_trees')),
757
805
    ]
758
806
 
759
807
 
760
808
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
761
809
                                TestPushStrictMixin):
762
810
 
763
 
    scenarios = strict_push_change_scenarios
764
 
    _changes_type = None  # Set by load_tests
 
811
    scenarios = strict_push_change_scenarios 
 
812
    _changes_type = None # Set by load_tests
765
813
 
766
814
    def setUp(self):
767
815
        super(TestPushStrictWithChanges, self).setUp()
772
820
    def _uncommitted_changes(self):
773
821
        self.make_local_branch_and_tree()
774
822
        # Make a change without committing it
775
 
        self.build_tree_contents([('local/file', b'in progress')])
 
823
        self.build_tree_contents([('local/file', 'in progress')])
776
824
 
777
825
    def _pending_merges(self):
778
826
        self.make_local_branch_and_tree()
779
827
        # Create 'other' branch containing a new file
780
828
        other_bzrdir = self.tree.controldir.sprout('other')
781
829
        other_tree = other_bzrdir.open_workingtree()
782
 
        self.build_tree_contents([('other/other-file', b'other')])
 
830
        self.build_tree_contents([('other/other-file', 'other')])
783
831
        other_tree.add('other-file')
784
 
        other_tree.commit('other commit', rev_id=b'other')
 
832
        other_tree.commit('other commit', rev_id='other')
785
833
        # Merge and revert, leaving a pending merge
786
834
        self.tree.merge_from_branch(other_tree.branch)
787
835
        self.tree.revert(filenames=['other-file'], backups=False)
790
838
        self.make_local_branch_and_tree()
791
839
        self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
792
840
        # Make a change and commit it
793
 
        self.build_tree_contents([('local/file', b'modified in local')])
794
 
        self.tree.commit('modify file', rev_id=b'modified-in-local')
 
841
        self.build_tree_contents([('local/file', 'modified in local')])
 
842
        self.tree.commit('modify file', rev_id='modified-in-local')
795
843
        # Exercise commands from the checkout directory
796
844
        self._default_wd = 'checkout'
797
845
        self._default_errors = ["Working tree is out of date, please run"
798
 
                                " 'brz update'\\.", ]
 
846
                                " 'brz update'\.",]
799
847
 
800
848
    def test_push_default(self):
801
849
        self.assertPushSucceeds([], with_warning=True)
802
850
 
803
851
    def test_push_with_revision(self):
804
 
        self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push=b'added')
 
852
        self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
805
853
 
806
854
    def test_push_no_strict(self):
807
855
        self.assertPushSucceeds(['--no-strict'])
837
885
    def make_dummy_builder(self, relpath):
838
886
        builder = self.make_branch_builder(
839
887
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
840
 
        builder.build_snapshot(None,
841
 
                               [('add', ('', b'TREE_ROOT', 'directory', None)),
842
 
                                ('add', ('foo', b'fooid', 'file', b'bar'))],
843
 
                               revision_id=b'revid')
 
888
        builder.build_snapshot('revid', None,
 
889
            [('add', ('', 'TREE_ROOT', 'directory', None)),
 
890
             ('add', ('foo', 'fooid', 'file', 'bar'))])
844
891
        return builder
845
892
 
846
893
    def test_no_roundtripping(self):
848
895
        source_tree = self.make_branch_and_tree("dc")
849
896
        output, error = self.run_bzr("push -d dc dp", retcode=3)
850
897
        self.assertEqual("", output)
851
 
        self.assertEqual(
852
 
            error,
853
 
            "brz: ERROR: It is not possible to losslessly"
854
 
            " push to dummy. You may want to use --lossy.\n")
 
898
        self.assertEqual(error, "brz: ERROR: It is not possible to losslessly"
 
899
            " push to dummy. You may want to use dpush instead.\n")
855
900
 
856
901
 
857
902
class TestPushOutput(script.TestCaseWithTransportAndScript):
879
924
 
880
925
    def test_push_with_revspec(self):
881
926
        self.run_script("""
882
 
            $ brz init-shared-repo .
 
927
            $ brz init-repo .
883
928
            Shared repository with trees (format: 2a)
884
929
            Location:
885
930
              shared repository: .