1
# Copyright (C) 2006-2011 Canonical Ltd
1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
58
57
['push', public_url],
59
58
working_dir='source')
60
def test_push_suggests_parent_alias(self):
61
"""Push suggests using :parent if there is a known parent branch."""
62
tree_a = self.make_branch_and_tree('a')
63
tree_a.commit('this is a commit')
64
tree_b = self.make_branch_and_tree('b')
66
# If there is no parent location set, :parent isn't mentioned.
67
out = self.run_bzr('push', working_dir='a', retcode=3)
69
('','bzr: ERROR: No push location known or specified.\n'))
71
# If there is a parent location set, the error suggests :parent.
72
tree_a.branch.set_parent(tree_b.branch.base)
73
out = self.run_bzr('push', working_dir='a', retcode=3)
75
('','bzr: ERROR: No push location known or specified. '
76
'To push to the parent branch '
77
'(at %s), use \'bzr push :parent\'.\n' %
78
urlutils.unescape_for_display(tree_b.branch.base, 'utf-8')))
61
80
def test_push_remember(self):
62
81
"""Push changes from one branch to another and test push location."""
63
82
transport = self.get_transport()
82
101
# test push for failure without push location set
83
102
out = self.run_bzr('push', working_dir='branch_a', retcode=3)
84
self.assertEquals(out,
103
self.assertEqual(out,
85
104
('','bzr: ERROR: No push location known or specified.\n'))
87
106
# test not remembered if cannot actually push
88
107
self.run_bzr('push path/which/doesnt/exist',
89
108
working_dir='branch_a', retcode=3)
90
109
out = self.run_bzr('push', working_dir='branch_a', retcode=3)
92
111
('', 'bzr: ERROR: No push location known or specified.\n'),
95
114
# test implicit --remember when no push location set, push fails
96
115
out = self.run_bzr('push ../branch_b',
97
116
working_dir='branch_a', retcode=3)
98
self.assertEquals(out,
117
self.assertEqual(out,
99
118
('','bzr: ERROR: These branches have diverged. '
100
119
'See "bzr help diverged-branches" for more information.\n'))
101
self.assertEquals(osutils.abspath(branch_a.get_push_location()),
120
# Refresh the branch as 'push' modified it
121
branch_a = branch_a.bzrdir.open_branch()
122
self.assertEqual(osutils.abspath(branch_a.get_push_location()),
102
123
osutils.abspath(branch_b.bzrdir.root_transport.base))
104
125
# test implicit --remember after resolving previous failure
105
126
uncommit.uncommit(branch=branch_b, tree=tree_b)
106
127
transport.delete('branch_b/c')
107
128
out, err = self.run_bzr('push', working_dir='branch_a')
129
# Refresh the branch as 'push' modified it
130
branch_a = branch_a.bzrdir.open_branch()
108
131
path = branch_a.get_push_location()
109
132
self.assertEqual(err,
110
133
'Using saved push location: %s\n'
115
138
branch_b.bzrdir.root_transport.base)
116
139
# test explicit --remember
117
140
self.run_bzr('push ../branch_c --remember', working_dir='branch_a')
118
self.assertEquals(branch_a.get_push_location(),
141
# Refresh the branch as 'push' modified it
142
branch_a = branch_a.bzrdir.open_branch()
143
self.assertEqual(branch_a.get_push_location(),
119
144
branch_c.bzrdir.root_transport.base)
121
146
def test_push_without_tree(self):
158
183
t.commit('commit 1')
159
184
self.run_bzr('push -d tree pushed-to')
160
path = t.branch.get_push_location()
185
# Refresh the branch as 'push' modified it and get the push location
186
push_loc = t.branch.bzrdir.open_branch().get_push_location()
161
187
out, err = self.run_bzr('push', working_dir="tree")
162
188
self.assertEqual('Using saved push location: %s\n'
163
189
'No new revisions or tags to push.\n' %
164
urlutils.local_path_from_url(path), err)
190
urlutils.local_path_from_url(push_loc), err)
165
191
out, err = self.run_bzr('push -q', working_dir="tree")
166
192
self.assertEqual('', out)
167
193
self.assertEqual('', err)
249
275
# become necessary for this use case. Please do not adjust this number
250
276
# upwards without agreement from bzr's network support maintainers.
251
277
self.assertLength(9, self.hpss_calls)
278
self.assertLength(1, self.hpss_connections)
279
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
253
281
def test_push_smart_stacked_streaming_acceptance(self):
254
282
self.setup_smart_server_with_call_log()
264
292
# being too low. If rpc_count increases, more network roundtrips have
265
293
# become necessary for this use case. Please do not adjust this number
266
294
# upwards without agreement from bzr's network support maintainers.
267
self.assertLength(13, self.hpss_calls)
295
self.assertLength(15, self.hpss_calls)
296
self.assertLength(1, self.hpss_connections)
297
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
268
298
remote = branch.Branch.open('public')
269
299
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
281
311
# become necessary for this use case. Please do not adjust this number
282
312
# upwards without agreement from bzr's network support maintainers.
283
313
self.assertLength(11, self.hpss_calls)
314
self.assertLength(1, self.hpss_connections)
315
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
285
317
def test_push_smart_incremental_acceptance(self):
286
318
self.setup_smart_server_with_call_log()
297
329
# become necessary for this use case. Please do not adjust this number
298
330
# upwards without agreement from bzr's network support maintainers.
299
331
self.assertLength(11, self.hpss_calls)
332
self.assertLength(1, self.hpss_connections)
333
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
301
335
def test_push_smart_with_default_stacking_url_path_segment(self):
302
336
# If the default stacked-on location is a path element then branches
418
452
self.assertTrue(repo_to.has_revision('from-1'))
419
453
self.assertFalse(repo_to.has_revision('from-2'))
420
454
self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
456
tree_to.changes_from(tree_to.basis_tree()).has_changed())
422
458
self.run_bzr_error(
423
459
['bzr: ERROR: bzr push --revision '
479
515
trunk_public = self.make_branch('public_trunk', format='1.9')
480
516
trunk_public.pull(trunk_tree.branch)
481
517
trunk_public_url = self.get_readonly_url('public_trunk')
482
trunk_tree.branch.set_public_branch(trunk_public_url)
518
br = trunk_tree.branch
519
br.set_public_branch(trunk_public_url)
483
520
# now we do a stacked push, which should determine the public location
485
522
out, err = self.run_bzr(['push', '--stacked',
578
615
self.assertEqual('', out)
579
616
self.assertEqual('Created new branch.\n', err)
618
def test_overwrite_tags(self):
619
"""--overwrite-tags only overwrites tags, not revisions."""
620
from_tree = self.make_branch_and_tree('from')
621
from_tree.branch.tags.set_tag("mytag", "somerevid")
622
to_tree = self.make_branch_and_tree('to')
623
to_tree.branch.tags.set_tag("mytag", "anotherrevid")
624
revid1 = to_tree.commit('my commit')
625
out = self.run_bzr(['push', '-d', 'from', 'to'])
626
self.assertEqual(out,
627
('Conflicting tags:\n mytag\n', 'No new revisions to push.\n'))
628
out = self.run_bzr(['push', '-d', 'from', '--overwrite-tags', 'to'])
629
self.assertEqual(out, ('', '1 tag updated.\n'))
630
self.assertEqual(to_tree.branch.tags.lookup_tag('mytag'),
632
self.assertEqual(to_tree.branch.last_revision(), revid1)
582
635
class RedirectingMemoryTransport(memory.MemoryTransport):
630
683
class TestPushRedirect(tests.TestCaseWithTransport):
633
tests.TestCaseWithTransport.setUp(self)
686
super(TestPushRedirect, self).setUp()
634
687
self.memory_server = RedirectingMemoryServer()
635
688
self.start_server(self.memory_server)
636
689
# Make the branch and tree that we'll be pushing.
676
729
self.tree.commit('modify file', rev_id='modified')
678
731
def set_config_push_strict(self, value):
679
# set config var (any of bazaar.conf, locations.conf, branch.conf
681
conf = self.tree.branch.get_config_stack()
682
conf.set('push_strict', value)
732
br = branch.Branch.open('local')
733
br.get_config_stack().set('push_strict', value)
684
735
_default_command = ['push', '../to']
685
736
_default_wd = 'local'
841
892
target_branch = self.make_dummy_builder('dp').get_branch()
842
893
source_tree = self.make_branch_and_tree("dc")
843
894
output, error = self.run_bzr("push -d dc dp", retcode=3)
844
self.assertEquals("", output)
845
self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
895
self.assertEqual("", output)
896
self.assertEqual(error, "bzr: ERROR: It is not possible to losslessly"
846
897
" push to dummy. You may want to use dpush instead.\n")
868
919
2>All changes applied successfully.
869
920
2>Pushed up to revision 1.
923
def test_push_with_revspec(self):
926
Shared repository with trees (format: 2a)
930
Created a repository tree (format: 2a)
931
Using shared repository...
933
$ bzr commit -m 'first rev' --unchanged
934
2>Committing to:...trunk/
935
2>Committed revision 1.
939
$ bzr commit -m 'we need some foo'
940
2>Committing to:...trunk/
942
2>Committed revision 2.
943
$ bzr push -r 1 ../other
944
2>Created new branch.
945
$ bzr st ../other # checking that file is not created (#484516)