68
69
# If there is no parent location set, :parent isn't mentioned.
69
70
out = self.run_bzr('push', working_dir='a', retcode=3)
70
71
self.assertEqual(out,
71
('', 'brz: ERROR: No push location known or specified.\n'))
72
('', 'brz: ERROR: No push location known or specified.\n'))
73
74
# If there is a parent location set, the error suggests :parent.
74
75
tree_a.branch.set_parent(tree_b.branch.base)
75
76
out = self.run_bzr('push', working_dir='a', retcode=3)
76
77
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')))
78
('', 'brz: ERROR: No push location known or specified. '
79
'To push to the parent branch '
80
'(at %s), use \'brz push :parent\'.\n' %
81
urlutils.unescape_for_display(tree_b.branch.base, 'utf-8')))
82
83
def test_push_remember(self):
83
84
"""Push changes from one branch to another and test push location."""
103
104
# test push for failure without push location set
104
105
out = self.run_bzr('push', working_dir='branch_a', retcode=3)
105
106
self.assertEqual(out,
106
('', 'brz: ERROR: No push location known or specified.\n'))
107
('', 'brz: ERROR: No push location known or specified.\n'))
108
109
# test not remembered if cannot actually push
109
110
self.run_bzr('push path/which/doesnt/exist',
110
111
working_dir='branch_a', retcode=3)
111
112
out = self.run_bzr('push', working_dir='branch_a', retcode=3)
112
113
self.assertEqual(
113
('', 'brz: ERROR: No push location known or specified.\n'),
114
('', 'brz: ERROR: No push location known or specified.\n'),
116
117
# test implicit --remember when no push location set, push fails
117
118
out = self.run_bzr('push ../branch_b',
118
119
working_dir='branch_a', retcode=3)
119
120
self.assertEqual(out,
120
('', 'brz: ERROR: These branches have diverged. '
121
'See "brz help diverged-branches" for more information.\n'))
121
('', 'brz: ERROR: These branches have diverged. '
122
'See "brz help diverged-branches" for more information.\n'))
122
123
# Refresh the branch as 'push' modified it
123
124
branch_a = branch_a.controldir.open_branch()
124
125
self.assertEqual(osutils.abspath(branch_a.get_push_location()),
125
osutils.abspath(branch_b.controldir.root_transport.base))
126
osutils.abspath(branch_b.controldir.root_transport.base))
127
128
# test implicit --remember after resolving previous failure
128
129
uncommit.uncommit(branch=branch_b, tree=tree_b)
143
144
# Refresh the branch as 'push' modified it
144
145
branch_a = branch_a.controldir.open_branch()
145
146
self.assertEqual(branch_a.get_push_location(),
146
branch_c.controldir.root_transport.base)
147
branch_c.controldir.root_transport.base)
148
149
def test_push_without_tree(self):
149
150
# brz push from a branch that does not have a checkout should work.
242
243
def test_push_dash_d(self):
243
244
t = self.make_branch_and_tree('from')
244
245
t.commit(allow_pointless=True,
245
message='first commit')
246
message='first commit')
246
247
self.run_bzr('push -d from to-one')
247
248
self.assertPathExists('to-one')
248
249
self.run_bzr('push -d %s %s'
249
% tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
250
% tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
250
251
self.assertPathExists('to-two')
252
253
def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
264
265
self.addCleanup(target_repo.lock_read().unlock)
265
266
# We should have pushed 'C', but not 'B', since it isn't in the
267
self.assertEqual([(b'A',), (b'C',)], sorted(target_repo.revisions.keys()))
268
self.assertEqual([(b'A',), (b'C',)], sorted(
269
target_repo.revisions.keys()))
269
271
def test_push_smart_non_stacked_streaming_acceptance(self):
270
272
self.setup_smart_server_with_call_log()
289
291
local.commit(message='local commit')
290
292
self.reset_smart_call_log()
291
293
self.run_bzr(['push', '--stacked', '--stacked-on', '../parent',
292
self.get_url('public')], working_dir='local')
294
self.get_url('public')], working_dir='local')
293
295
# This figure represent the amount of work to perform this use case. It
294
296
# is entirely ok to reduce this number if a test fails due to rpc_count
295
297
# being too low. If rpc_count increases, more network roundtrips have
391
393
self.run_bzr_error(['Target directory ../target already exists',
392
394
'Supply --use-existing-dir',
394
396
'push ../target', working_dir='tree')
396
398
self.run_bzr('push --use-existing-dir ../target',
466
468
def create_trunk_and_feature_branch(self):
467
469
# We have a mainline
468
470
trunk_tree = self.make_branch_and_tree('target',
470
472
trunk_tree.commit('mainline')
471
473
# and a branch from it
472
474
branch_tree = self.make_branch_and_tree('branch',
474
476
branch_tree.pull(trunk_tree.branch)
475
477
branch_tree.branch.set_parent(trunk_tree.branch.base)
476
478
# with some work on it
490
492
trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
491
493
# we publish branch_tree with a reference to the mainline.
492
494
out, err = self.run_bzr(['push', '--stacked-on', trunk_tree.branch.base,
493
self.get_url('published')], working_dir='branch')
494
self.assertEqual('', out)
495
self.assertEqual('Created new stacked branch referring to %s.\n' %
496
trunk_tree.branch.base, err)
497
self.assertPublished(branch_tree.last_revision(),
498
trunk_tree.branch.base)
495
self.get_url('published')], working_dir='branch')
496
self.assertEqual('', out)
497
self.assertEqual('Created new stacked branch referring to %s.\n' %
498
trunk_tree.branch.base, err)
499
self.assertPublished(branch_tree.last_revision(),
500
trunk_tree.branch.base)
502
def test_push_new_branch_stacked_on(self):
503
"""Pushing a new branch with --stacked-on can use directory URLs."""
504
trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
505
class FooDirectory(object):
506
def look_up(self, name, url, purpose=None):
508
return trunk_tree.branch.base
510
directory_service.directories.register('foo:', FooDirectory, 'Foo directory')
511
self.addCleanup(directory_service.directories.remove, 'foo:')
512
# we publish branch_tree with a reference to the mainline.
513
out, err = self.run_bzr(['push', '--stacked-on', 'foo:',
514
self.get_url('published')], working_dir='branch')
515
self.assertEqual('', out)
516
self.assertEqual('Created new stacked branch referring to %s.\n' %
517
trunk_tree.branch.base, err)
518
self.assertPublished(branch_tree.last_revision(),
519
trunk_tree.branch.base)
500
521
def test_push_new_branch_stacked_uses_parent_when_no_public_url(self):
501
522
"""When the parent has no public url the parent is used as-is."""
503
524
# now we do a stacked push, which should determine the public location
505
526
out, err = self.run_bzr(['push', '--stacked',
506
self.get_url('published')], working_dir='branch')
527
self.get_url('published')], working_dir='branch')
507
528
self.assertEqual('', out)
508
529
self.assertEqual('Created new stacked branch referring to %s.\n' %
509
trunk_tree.branch.base, err)
530
trunk_tree.branch.base, err)
510
531
self.assertPublished(branch_tree.last_revision(),
511
532
trunk_tree.branch.base)
523
544
# now we do a stacked push, which should determine the public location
525
546
out, err = self.run_bzr(['push', '--stacked',
526
self.get_url('published')], working_dir='branch')
547
self.get_url('published')], working_dir='branch')
527
548
self.assertEqual('', out)
528
549
self.assertEqual('Created new stacked branch referring to %s.\n' %
529
trunk_public_url, err)
550
trunk_public_url, err)
530
551
self.assertPublished(branch_tree.last_revision(), trunk_public_url)
532
553
def test_push_new_branch_stacked_no_parent(self):
536
557
# cannot be determined.
537
558
out, err = self.run_bzr_error(
538
559
['Could not determine branch to refer to\\.'], ['push', '--stacked',
539
self.get_url('published')], working_dir='branch')
560
self.get_url('published')], working_dir='branch')
540
561
self.assertEqual('', out)
541
562
self.assertFalse(self.get_transport('published').has('.'))
581
602
revision_id=b'rev-1')
582
603
builder.build_snapshot([b'rev-1'], [], revision_id=b'rev-2')
583
604
builder.build_snapshot([b'rev-2'],
584
[('modify', ('filename', b'new-content\n'))],
585
revision_id=b'rev-3')
605
[('modify', ('filename', b'new-content\n'))],
606
revision_id=b'rev-3')
586
607
builder.finish_series()
587
608
branch = builder.get_branch()
588
609
# Push rev-1 to "trunk", so that we can stack on it.
629
650
revid1 = to_tree.commit('my commit')
630
651
out = self.run_bzr(['push', '-d', 'from', 'to'])
631
652
self.assertEqual(out,
632
('Conflicting tags:\n mytag\n', 'No new revisions to push.\n'))
653
('Conflicting tags:\n mytag\n', 'No new revisions to push.\n'))
633
654
out = self.run_bzr(['push', '-d', 'from', '--overwrite-tags', 'to'])
634
655
self.assertEqual(out, ('', '1 tag updated.\n'))
635
656
self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
637
658
self.assertEqual(to_tree.branch.last_revision(), revid1)
740
761
_default_command = ['push', '../to']
741
762
_default_wd = 'local'
742
763
_default_errors = ['Working tree ".*/local/" has uncommitted '
743
'changes \\(See brz status\\)\\.',]
764
'changes \\(See brz status\\)\\.', ]
744
765
_default_additional_error = 'Use --no-strict to force the push.\n'
745
766
_default_additional_warning = 'Uncommitted changes will not be pushed.'
748
768
def assertPushFails(self, args):
749
769
out, err = self.run_bzr_error(self._default_errors,
750
770
self._default_command + args,
800
820
strict_push_change_scenarios = [
802
dict(_changes_type= '_uncommitted_changes')),
822
dict(_changes_type='_uncommitted_changes')),
803
823
('pending-merges',
804
dict(_changes_type= '_pending_merges')),
824
dict(_changes_type='_pending_merges')),
805
825
('out-of-sync-trees',
806
dict(_changes_type= '_out_of_sync_trees')),
826
dict(_changes_type='_out_of_sync_trees')),
810
830
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
811
831
TestPushStrictMixin):
813
scenarios = strict_push_change_scenarios
814
_changes_type = None # Set by load_tests
833
scenarios = strict_push_change_scenarios
834
_changes_type = None # Set by load_tests
817
837
super(TestPushStrictWithChanges, self).setUp()
845
865
# Exercise commands from the checkout directory
846
866
self._default_wd = 'checkout'
847
867
self._default_errors = ["Working tree is out of date, please run"
868
" 'brz update'\\.", ]
850
870
def test_push_default(self):
851
871
self.assertPushSucceeds([], with_warning=True)
888
908
builder = self.make_branch_builder(
889
909
relpath, format=test_foreign.DummyForeignVcsDirFormat())
890
910
builder.build_snapshot(None,
891
[('add', ('', b'TREE_ROOT', 'directory', None)),
892
('add', ('foo', b'fooid', 'file', b'bar'))],
893
revision_id=b'revid')
911
[('add', ('', b'TREE_ROOT', 'directory', None)),
912
('add', ('foo', b'fooid', 'file', b'bar'))],
913
revision_id=b'revid')
896
916
def test_no_roundtripping(self):
898
918
source_tree = self.make_branch_and_tree("dc")
899
919
output, error = self.run_bzr("push -d dc dp", retcode=3)
900
920
self.assertEqual("", output)
901
self.assertEqual(error, "brz: ERROR: It is not possible to losslessly"
902
" push to dummy. You may want to use dpush instead.\n")
923
"brz: ERROR: It is not possible to losslessly"
924
" push to dummy. You may want to use --lossy.\n")
905
927
class TestPushOutput(script.TestCaseWithTransportAndScript):