69
68
# If there is no parent location set, :parent isn't mentioned.
70
69
out = self.run_bzr('push', working_dir='a', retcode=3)
71
70
self.assertEqual(out,
72
('', 'brz: ERROR: No push location known or specified.\n'))
71
('', 'brz: ERROR: No push location known or specified.\n'))
74
73
# If there is a parent location set, the error suggests :parent.
75
74
tree_a.branch.set_parent(tree_b.branch.base)
76
75
out = self.run_bzr('push', working_dir='a', retcode=3)
77
76
self.assertEqual(out,
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')))
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')))
83
82
def test_push_remember(self):
84
83
"""Push changes from one branch to another and test push location."""
104
103
# test push for failure without push location set
105
104
out = self.run_bzr('push', working_dir='branch_a', retcode=3)
106
105
self.assertEqual(out,
107
('', 'brz: ERROR: No push location known or specified.\n'))
106
('', 'brz: ERROR: No push location known or specified.\n'))
109
108
# test not remembered if cannot actually push
110
109
self.run_bzr('push path/which/doesnt/exist',
111
110
working_dir='branch_a', retcode=3)
112
111
out = self.run_bzr('push', working_dir='branch_a', retcode=3)
113
112
self.assertEqual(
114
('', 'brz: ERROR: No push location known or specified.\n'),
113
('', 'brz: ERROR: No push location known or specified.\n'),
117
116
# test implicit --remember when no push location set, push fails
118
117
out = self.run_bzr('push ../branch_b',
119
118
working_dir='branch_a', retcode=3)
120
119
self.assertEqual(out,
121
('', 'brz: ERROR: These branches have diverged. '
122
'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'))
123
122
# Refresh the branch as 'push' modified it
124
123
branch_a = branch_a.controldir.open_branch()
125
124
self.assertEqual(osutils.abspath(branch_a.get_push_location()),
126
osutils.abspath(branch_b.controldir.root_transport.base))
125
osutils.abspath(branch_b.controldir.root_transport.base))
128
127
# test implicit --remember after resolving previous failure
129
128
uncommit.uncommit(branch=branch_b, tree=tree_b)
144
143
# Refresh the branch as 'push' modified it
145
144
branch_a = branch_a.controldir.open_branch()
146
145
self.assertEqual(branch_a.get_push_location(),
147
branch_c.controldir.root_transport.base)
146
branch_c.controldir.root_transport.base)
149
148
def test_push_without_tree(self):
150
149
# brz push from a branch that does not have a checkout should work.
220
219
tree_b.add('file')
221
220
tree_b.commit('commit b-1', rev_id=b'b-1')
223
self.assertTrue(shared_repo.has_revision(b'a-1'))
224
self.assertTrue(shared_repo.has_revision(b'a-2'))
225
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'))
227
226
# Now that we have a repository with shared files, make sure
228
227
# that things aren't copied out by a 'push'
229
228
self.run_bzr('push ../../push-b', working_dir='repo/b')
230
229
pushed_tree = workingtree.WorkingTree.open('push-b')
231
230
pushed_repo = pushed_tree.branch.repository
232
self.assertFalse(pushed_repo.has_revision(b'a-1'))
233
self.assertFalse(pushed_repo.has_revision(b'a-2'))
234
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'))
236
235
def test_push_funky_id(self):
237
236
t = self.make_branch_and_tree('tree')
238
237
self.build_tree(['tree/filename'])
239
t.add('filename', b'funky-chars<>%&;"\'')
238
t.add('filename', 'funky-chars<>%&;"\'')
240
239
t.commit('commit filename')
241
240
self.run_bzr('push -d tree new-tree')
243
242
def test_push_dash_d(self):
244
243
t = self.make_branch_and_tree('from')
245
244
t.commit(allow_pointless=True,
246
message='first commit')
245
message='first commit')
247
246
self.run_bzr('push -d from to-one')
248
247
self.assertPathExists('to-one')
249
248
self.run_bzr('push -d %s %s'
250
% tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
249
% tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
251
250
self.assertPathExists('to-two')
253
252
def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
256
255
source = self.make_branch_builder('source')
257
256
source.start_series()
258
257
source.build_snapshot(None, [
259
('add', ('', b'root-id', 'directory', None))],
258
('add', ('', 'root-id', 'directory', None))],
260
259
revision_id=b'A')
261
source.build_snapshot([b'A'], [], revision_id=b'B')
262
source.build_snapshot([b'A'], [], revision_id=b'C')
260
source.build_snapshot(['A'], [], revision_id=b'B')
261
source.build_snapshot(['A'], [], revision_id=b'C')
263
262
source.finish_series()
264
263
self.run_bzr('push target -d source')
265
264
self.addCleanup(target_repo.lock_read().unlock)
266
265
# We should have pushed 'C', but not 'B', since it isn't in the
268
self.assertEqual([(b'A',), (b'C',)], sorted(
269
target_repo.revisions.keys()))
267
self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
271
269
def test_push_smart_non_stacked_streaming_acceptance(self):
272
270
self.setup_smart_server_with_call_log()
291
289
local.commit(message='local commit')
292
290
self.reset_smart_call_log()
293
291
self.run_bzr(['push', '--stacked', '--stacked-on', '../parent',
294
self.get_url('public')], working_dir='local')
292
self.get_url('public')], working_dir='local')
295
293
# This figure represent the amount of work to perform this use case. It
296
294
# is entirely ok to reduce this number if a test fails due to rpc_count
297
295
# being too low. If rpc_count increases, more network roundtrips have
393
391
self.run_bzr_error(['Target directory ../target already exists',
394
392
'Supply --use-existing-dir',
396
394
'push ../target', working_dir='tree')
398
396
self.run_bzr('push --use-existing-dir ../target',
441
439
a_controldir = self.make_controldir('dir')
443
441
self.run_bzr_error(['At ../dir you have a valid .bzr control'],
447
445
def test_push_with_revisionspec(self):
448
446
"""We should be able to push a revision older than the tip."""
449
447
tree_from = self.make_branch_and_tree('from')
450
tree_from.commit("One.", rev_id=b"from-1")
451
tree_from.commit("Two.", rev_id=b"from-2")
448
tree_from.commit("One.", rev_id="from-1")
449
tree_from.commit("Two.", rev_id="from-2")
453
451
self.run_bzr('push -r1 ../to', working_dir='from')
455
453
tree_to = workingtree.WorkingTree.open('to')
456
454
repo_to = tree_to.branch.repository
457
self.assertTrue(repo_to.has_revision(b'from-1'))
458
self.assertFalse(repo_to.has_revision(b'from-2'))
459
self.assertEqual(tree_to.branch.last_revision_info()[1], b'from-1')
455
self.assertTrue(repo_to.has_revision('from-1'))
456
self.assertFalse(repo_to.has_revision('from-2'))
457
self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
460
458
self.assertFalse(
461
459
tree_to.changes_from(tree_to.basis_tree()).has_changed())
468
466
def create_trunk_and_feature_branch(self):
469
467
# We have a mainline
470
468
trunk_tree = self.make_branch_and_tree('target',
472
470
trunk_tree.commit('mainline')
473
471
# and a branch from it
474
472
branch_tree = self.make_branch_and_tree('branch',
476
474
branch_tree.pull(trunk_tree.branch)
477
475
branch_tree.branch.set_parent(trunk_tree.branch.base)
478
476
# with some work on it
492
490
trunk_tree, branch_tree = self.create_trunk_and_feature_branch()
493
491
# we publish branch_tree with a reference to the mainline.
494
492
out, err = self.run_bzr(['push', '--stacked-on', 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)
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)
521
500
def test_push_new_branch_stacked_uses_parent_when_no_public_url(self):
522
501
"""When the parent has no public url the parent is used as-is."""
524
503
# now we do a stacked push, which should determine the public location
526
505
out, err = self.run_bzr(['push', '--stacked',
527
self.get_url('published')], working_dir='branch')
506
self.get_url('published')], working_dir='branch')
528
507
self.assertEqual('', out)
529
508
self.assertEqual('Created new stacked branch referring to %s.\n' %
530
trunk_tree.branch.base, err)
509
trunk_tree.branch.base, err)
531
510
self.assertPublished(branch_tree.last_revision(),
532
511
trunk_tree.branch.base)
544
523
# now we do a stacked push, which should determine the public location
546
525
out, err = self.run_bzr(['push', '--stacked',
547
self.get_url('published')], working_dir='branch')
526
self.get_url('published')], working_dir='branch')
548
527
self.assertEqual('', out)
549
528
self.assertEqual('Created new stacked branch referring to %s.\n' %
550
trunk_public_url, err)
529
trunk_public_url, err)
551
530
self.assertPublished(branch_tree.last_revision(), trunk_public_url)
553
532
def test_push_new_branch_stacked_no_parent(self):
557
536
# cannot be determined.
558
537
out, err = self.run_bzr_error(
559
538
['Could not determine branch to refer to\\.'], ['push', '--stacked',
560
self.get_url('published')], working_dir='branch')
539
self.get_url('published')], working_dir='branch')
561
540
self.assertEqual('', out)
562
541
self.assertFalse(self.get_transport('published').has('.'))
597
576
builder = self.make_branch_builder('repo/local', format='pack-0.92')
598
577
builder.start_series()
599
578
builder.build_snapshot(None, [
600
('add', ('', b'root-id', 'directory', '')),
601
('add', ('filename', b'f-id', 'file', b'content\n'))],
579
('add', ('', 'root-id', 'directory', '')),
580
('add', ('filename', 'f-id', 'file', 'content\n'))],
602
581
revision_id=b'rev-1')
603
582
builder.build_snapshot([b'rev-1'], [], revision_id=b'rev-2')
604
583
builder.build_snapshot([b'rev-2'],
605
[('modify', ('filename', b'new-content\n'))],
606
revision_id=b'rev-3')
584
[('modify', ('filename', b'new-content\n'))],
585
revision_id=b'rev-3')
607
586
builder.finish_series()
608
587
branch = builder.get_branch()
609
588
# Push rev-1 to "trunk", so that we can stack on it.
635
614
def test_push_from_subdir(self):
636
615
t = self.make_branch_and_tree('tree')
637
616
self.build_tree(['tree/dir/', 'tree/dir/file'])
638
t.add(['dir', 'dir/file'])
617
t.add('dir', 'dir/file')
640
619
out, err = self.run_bzr('push ../../pushloc', working_dir='tree/dir')
641
620
self.assertEqual('', out)
644
623
def test_overwrite_tags(self):
645
624
"""--overwrite-tags only overwrites tags, not revisions."""
646
625
from_tree = self.make_branch_and_tree('from')
647
from_tree.branch.tags.set_tag("mytag", b"somerevid")
626
from_tree.branch.tags.set_tag("mytag", "somerevid")
648
627
to_tree = self.make_branch_and_tree('to')
649
to_tree.branch.tags.set_tag("mytag", b"anotherrevid")
628
to_tree.branch.tags.set_tag("mytag", "anotherrevid")
650
629
revid1 = to_tree.commit('my commit')
651
630
out = self.run_bzr(['push', '-d', 'from', 'to'])
652
631
self.assertEqual(out,
653
('Conflicting tags:\n mytag\n', 'No new revisions to push.\n'))
632
('Conflicting tags:\n mytag\n', 'No new revisions to push.\n'))
654
633
out = self.run_bzr(['push', '-d', 'from', '--overwrite-tags', 'to'])
655
634
self.assertEqual(out, ('', '1 tag updated.\n'))
656
635
self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
658
637
self.assertEqual(to_tree.branch.last_revision(), revid1)
761
740
_default_command = ['push', '../to']
762
741
_default_wd = 'local'
763
742
_default_errors = ['Working tree ".*/local/" has uncommitted '
764
'changes \\(See brz status\\)\\.', ]
743
'changes \\(See brz status\\)\\.',]
765
744
_default_additional_error = 'Use --no-strict to force the push.\n'
766
745
_default_additional_warning = 'Uncommitted changes will not be pushed.'
768
748
def assertPushFails(self, args):
769
749
out, err = self.run_bzr_error(self._default_errors,
770
750
self._default_command + args,
820
801
strict_push_change_scenarios = [
822
dict(_changes_type='_uncommitted_changes')),
803
dict(_changes_type= '_uncommitted_changes')),
823
804
('pending-merges',
824
dict(_changes_type='_pending_merges')),
805
dict(_changes_type= '_pending_merges')),
825
806
('out-of-sync-trees',
826
dict(_changes_type='_out_of_sync_trees')),
807
dict(_changes_type= '_out_of_sync_trees')),
830
811
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
831
812
TestPushStrictMixin):
833
scenarios = strict_push_change_scenarios
834
_changes_type = None # Set by load_tests
814
scenarios = strict_push_change_scenarios
815
_changes_type = None # Set by load_tests
837
818
super(TestPushStrictWithChanges, self).setUp()
865
846
# Exercise commands from the checkout directory
866
847
self._default_wd = 'checkout'
867
848
self._default_errors = ["Working tree is out of date, please run"
868
" 'brz update'\\.", ]
870
851
def test_push_default(self):
871
852
self.assertPushSucceeds([], with_warning=True)
873
854
def test_push_with_revision(self):
874
self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push=b'added')
855
self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
876
857
def test_push_no_strict(self):
877
858
self.assertPushSucceeds(['--no-strict'])
908
889
builder = self.make_branch_builder(
909
890
relpath, format=test_foreign.DummyForeignVcsDirFormat())
910
891
builder.build_snapshot(None,
911
[('add', ('', b'TREE_ROOT', 'directory', None)),
912
('add', ('foo', b'fooid', 'file', b'bar'))],
913
revision_id=b'revid')
892
[('add', ('', b'TREE_ROOT', 'directory', None)),
893
('add', ('foo', b'fooid', 'file', 'bar'))],
894
revision_id=b'revid')
916
897
def test_no_roundtripping(self):
918
899
source_tree = self.make_branch_and_tree("dc")
919
900
output, error = self.run_bzr("push -d dc dp", retcode=3)
920
901
self.assertEqual("", output)
923
"brz: ERROR: It is not possible to losslessly"
924
" push to dummy. You may want to use --lossy.\n")
902
self.assertEqual(error, "brz: ERROR: It is not possible to losslessly"
903
" push to dummy. You may want to use dpush instead.\n")
927
906
class TestPushOutput(script.TestCaseWithTransportAndScript):