33
from bzrlib.repofmt import knitrepo
34
from bzrlib.tests import (
34
from breezy.repofmt import knitrepo
35
from breezy.tests import (
40
from bzrlib.transport import memory
43
def load_tests(standard_tests, module, loader):
44
"""Multiply tests for the push command."""
45
result = loader.suiteClass()
47
# one for each king of change
48
changes_tests, remaining_tests = tests.split_suite_by_condition(
49
standard_tests, tests.condition_isinstance((
50
TestPushStrictWithChanges,
54
dict(_changes_type= '_uncommitted_changes')),
56
dict(_changes_type= '_pending_merges')),
58
dict(_changes_type= '_out_of_sync_trees')),
60
tests.multiply_tests(changes_tests, changes_scenarios, result)
61
# No parametrization for the remaining tests
62
result.addTests(remaining_tests)
41
from breezy.tests.matchers import ContainsNoVfsCalls
42
from breezy.transport import memory
45
load_tests = scenarios.load_tests_apply_scenarios
67
48
class TestPush(tests.TestCaseWithTransport):
76
57
['push', public_url],
77
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
('','brz: 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
('','brz: ERROR: No push location known or specified. '
76
'To push to the parent branch '
77
'(at %s), use \'brz push :parent\'.\n' %
78
urlutils.unescape_for_display(tree_b.branch.base, 'utf-8')))
79
80
def test_push_remember(self):
80
81
"""Push changes from one branch to another and test push location."""
81
82
transport = self.get_transport()
100
101
# test push for failure without push location set
101
102
out = self.run_bzr('push', working_dir='branch_a', retcode=3)
102
self.assertEquals(out,
103
('','bzr: ERROR: No push location known or specified.\n'))
103
self.assertEqual(out,
104
('','brz: ERROR: No push location known or specified.\n'))
105
106
# test not remembered if cannot actually push
106
107
self.run_bzr('push path/which/doesnt/exist',
107
108
working_dir='branch_a', retcode=3)
108
109
out = self.run_bzr('push', working_dir='branch_a', retcode=3)
110
('', 'bzr: ERROR: No push location known or specified.\n'),
111
('', 'brz: ERROR: No push location known or specified.\n'),
113
114
# test implicit --remember when no push location set, push fails
114
115
out = self.run_bzr('push ../branch_b',
115
116
working_dir='branch_a', retcode=3)
116
self.assertEquals(out,
117
('','bzr: ERROR: These branches have diverged. '
118
'See "bzr help diverged-branches" for more information.\n'))
119
self.assertEquals(osutils.abspath(branch_a.get_push_location()),
120
osutils.abspath(branch_b.bzrdir.root_transport.base))
117
self.assertEqual(out,
118
('','brz: ERROR: These branches have diverged. '
119
'See "brz help diverged-branches" for more information.\n'))
120
# Refresh the branch as 'push' modified it
121
branch_a = branch_a.controldir.open_branch()
122
self.assertEqual(osutils.abspath(branch_a.get_push_location()),
123
osutils.abspath(branch_b.controldir.root_transport.base))
122
125
# test implicit --remember after resolving previous failure
123
126
uncommit.uncommit(branch=branch_b, tree=tree_b)
124
127
transport.delete('branch_b/c')
125
128
out, err = self.run_bzr('push', working_dir='branch_a')
129
# Refresh the branch as 'push' modified it
130
branch_a = branch_a.controldir.open_branch()
126
131
path = branch_a.get_push_location()
127
self.assertEquals(out,
128
'Using saved push location: %s\n'
129
% urlutils.local_path_from_url(path))
130
132
self.assertEqual(err,
133
'Using saved push location: %s\n'
131
134
'All changes applied successfully.\n'
132
'Pushed up to revision 2.\n')
135
'Pushed up to revision 2.\n'
136
% urlutils.local_path_from_url(path))
133
137
self.assertEqual(path,
134
branch_b.bzrdir.root_transport.base)
138
branch_b.controldir.root_transport.base)
135
139
# test explicit --remember
136
140
self.run_bzr('push ../branch_c --remember', working_dir='branch_a')
137
self.assertEquals(branch_a.get_push_location(),
138
branch_c.bzrdir.root_transport.base)
141
# Refresh the branch as 'push' modified it
142
branch_a = branch_a.controldir.open_branch()
143
self.assertEqual(branch_a.get_push_location(),
144
branch_c.controldir.root_transport.base)
140
146
def test_push_without_tree(self):
141
# bzr push from a branch that does not have a checkout should work.
147
# brz push from a branch that does not have a checkout should work.
142
148
b = self.make_branch('.')
143
149
out, err = self.run_bzr('push pushed-location')
144
150
self.assertEqual('', out)
146
152
b2 = branch.Branch.open('pushed-location')
147
153
self.assertEndsWith(b2.base, 'pushed-location/')
155
def test_push_no_tree(self):
156
# brz push --no-tree of a branch with working trees
157
b = self.make_branch_and_tree('push-from')
158
self.build_tree(['push-from/file'])
161
out, err = self.run_bzr('push --no-tree -d push-from push-to')
162
self.assertEqual('', out)
163
self.assertEqual('Created new branch.\n', err)
164
self.assertPathDoesNotExist('push-to/file')
149
166
def test_push_new_branch_revision_count(self):
150
# bzr push of a branch with revisions to a new location
167
# brz push of a branch with revisions to a new location
151
168
# should print the number of revisions equal to the length of the
153
170
t = self.make_branch_and_tree('tree')
158
175
self.assertEqual('', out)
159
176
self.assertEqual('Created new branch.\n', err)
178
def test_push_quiet(self):
179
# test that using -q makes output quiet
180
t = self.make_branch_and_tree('tree')
181
self.build_tree(['tree/file'])
184
self.run_bzr('push -d tree pushed-to')
185
# Refresh the branch as 'push' modified it and get the push location
186
push_loc = t.branch.controldir.open_branch().get_push_location()
187
out, err = self.run_bzr('push', working_dir="tree")
188
self.assertEqual('Using saved push location: %s\n'
189
'No new revisions or tags to push.\n' %
190
urlutils.local_path_from_url(push_loc), err)
191
out, err = self.run_bzr('push -q', working_dir="tree")
192
self.assertEqual('', out)
193
self.assertEqual('', err)
161
195
def test_push_only_pushes_history(self):
162
196
# Knit branches should only push the history for the current revision.
163
197
format = bzrdir.BzrDirMetaFormat1()
208
242
t.commit(allow_pointless=True,
209
243
message='first commit')
210
244
self.run_bzr('push -d from to-one')
211
self.failUnlessExists('to-one')
245
self.assertPathExists('to-one')
212
246
self.run_bzr('push -d %s %s'
213
247
% tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
214
self.failUnlessExists('to-two')
248
self.assertPathExists('to-two')
250
def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
251
# See https://bugs.launchpad.net/bzr/+bug/465517
252
target_repo = self.make_repository('target')
253
source = self.make_branch_builder('source')
254
source.start_series()
255
source.build_snapshot('A', None, [
256
('add', ('', 'root-id', 'directory', None))])
257
source.build_snapshot('B', ['A'], [])
258
source.build_snapshot('C', ['A'], [])
259
source.finish_series()
260
self.run_bzr('push target -d source')
261
self.addCleanup(target_repo.lock_read().unlock)
262
# We should have pushed 'C', but not 'B', since it isn't in the
264
self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
216
266
def test_push_smart_non_stacked_streaming_acceptance(self):
217
267
self.setup_smart_server_with_call_log()
225
275
# become necessary for this use case. Please do not adjust this number
226
276
# upwards without agreement from bzr's network support maintainers.
227
277
self.assertLength(9, self.hpss_calls)
278
self.assertLength(1, self.hpss_connections)
279
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
229
281
def test_push_smart_stacked_streaming_acceptance(self):
230
282
self.setup_smart_server_with_call_log()
231
283
parent = self.make_branch_and_tree('parent', format='1.9')
232
284
parent.commit(message='first commit')
233
local = parent.bzrdir.sprout('local').open_workingtree()
285
local = parent.controldir.sprout('local').open_workingtree()
234
286
local.commit(message='local commit')
235
287
self.reset_smart_call_log()
236
288
self.run_bzr(['push', '--stacked', '--stacked-on', '../parent',
240
292
# being too low. If rpc_count increases, more network roundtrips have
241
293
# become necessary for this use case. Please do not adjust this number
242
294
# upwards without agreement from bzr's network support maintainers.
243
self.assertLength(14, self.hpss_calls)
295
self.assertLength(15, self.hpss_calls)
296
self.assertLength(1, self.hpss_connections)
297
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
244
298
remote = branch.Branch.open('public')
245
299
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
280
338
# stacked_on_url is that exact path segment. Added to nail bug 385132.
281
339
self.setup_smart_server_with_call_log()
282
340
self.make_branch('stack-on', format='1.9')
283
self.make_bzrdir('.').get_config().set_default_stack_on(
341
self.make_controldir('.').get_config().set_default_stack_on(
285
343
self.make_branch('from', format='1.9')
286
344
out, err = self.run_bzr(['push', '-d', 'from', self.get_url('to')])
293
351
# stacked_on_url is a relative path. Added to nail bug 385132.
294
352
self.setup_smart_server_with_call_log()
295
353
self.make_branch('stack-on', format='1.9')
296
self.make_bzrdir('.').get_config().set_default_stack_on('stack-on')
354
self.make_controldir('.').get_config().set_default_stack_on('stack-on')
297
355
self.make_branch('from', format='1.9')
298
356
out, err = self.run_bzr(['push', '-d', 'from', self.get_url('to')])
299
357
b = branch.Branch.open(self.get_url('to'))
317
375
working_dir='tree')
318
376
new_tree = workingtree.WorkingTree.open('new/tree')
319
377
self.assertEqual(tree.last_revision(), new_tree.last_revision())
320
self.failUnlessExists('new/tree/a')
378
self.assertPathExists('new/tree/a')
322
380
def test_push_use_existing(self):
323
"""'bzr push --use-existing-dir' can push into an existing dir.
381
"""'brz push --use-existing-dir' can push into an existing dir.
325
By default, 'bzr push' will not use an existing, non-versioned dir.
383
By default, 'brz push' will not use an existing, non-versioned dir.
327
385
tree = self.create_simple_tree()
328
386
self.build_tree(['target/'])
554
615
self.assertEqual('', out)
555
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)
558
635
class RedirectingMemoryTransport(memory.MemoryTransport):
652
729
self.tree.commit('modify file', rev_id='modified')
654
731
def set_config_push_strict(self, value):
655
# set config var (any of bazaar.conf, locations.conf, branch.conf
657
conf = self.tree.branch.get_config()
658
conf.set_user_option('push_strict', value)
732
br = branch.Branch.open('local')
733
br.get_config_stack().set('push_strict', value)
660
735
_default_command = ['push', '../to']
661
736
_default_wd = 'local'
662
737
_default_errors = ['Working tree ".*/local/" has uncommitted '
663
'changes \(See bzr status\)\.',]
738
'changes \(See brz status\)\.',]
664
739
_default_additional_error = 'Use --no-strict to force the push.\n'
665
740
_default_additional_warning = 'Uncommitted changes will not be pushed.'
806
892
target_branch = self.make_dummy_builder('dp').get_branch()
807
893
source_tree = self.make_branch_and_tree("dc")
808
894
output, error = self.run_bzr("push -d dc dp", retcode=3)
809
self.assertEquals("", output)
810
self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
895
self.assertEqual("", output)
896
self.assertEqual(error, "brz: ERROR: It is not possible to losslessly"
811
897
" push to dummy. You may want to use dpush instead.\n")
900
class TestPushOutput(script.TestCaseWithTransportAndScript):
902
def test_push_log_format(self):
905
Created a standalone tree (format: 2a)
910
$ brz commit -m 'we need some foo'
911
2>Committing to:...trunk/
913
2>Committed revision 1.
914
$ brz init ../feature
915
Created a standalone tree (format: 2a)
916
$ brz push -v ../feature -Olog_format=line
918
1: jrandom@example.com ...we need some foo
919
2>All changes applied successfully.
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
$ brz commit -m 'first rev' --unchanged
934
2>Committing to:...trunk/
935
2>Committed revision 1.
939
$ brz commit -m 'we need some foo'
940
2>Committing to:...trunk/
942
2>Committed revision 2.
943
$ brz push -r 1 ../other
944
2>Created new branch.
945
$ brz st ../other # checking that file is not created (#484516)