33
34
from bzrlib.repofmt import knitrepo
34
35
from bzrlib.tests import (
41
from bzrlib.tests.matchers import ContainsNoVfsCalls
39
42
from bzrlib.transport import memory
42
def load_tests(standard_tests, module, loader):
43
"""Multiply tests for the push command."""
44
result = loader.suiteClass()
46
# one for each king of change
47
changes_tests, remaining_tests = tests.split_suite_by_condition(
48
standard_tests, tests.condition_isinstance((
49
TestPushStrictWithChanges,
53
dict(_changes_type= '_uncommitted_changes')),
55
dict(_changes_type= '_pending_merges')),
57
dict(_changes_type= '_out_of_sync_trees')),
59
tests.multiply_tests(changes_tests, changes_scenarios, result)
60
# No parametrization for the remaining tests
61
result.addTests(remaining_tests)
45
load_tests = scenarios.load_tests_apply_scenarios
66
48
class TestPush(tests.TestCaseWithTransport):
75
57
['push', public_url],
76
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)
68
self.assertEquals(out,
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)
74
self.assertEquals(out,
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')))
78
80
def test_push_remember(self):
79
81
"""Push changes from one branch to another and test push location."""
80
82
transport = self.get_transport()
122
126
uncommit.uncommit(branch=branch_b, tree=tree_b)
123
127
transport.delete('branch_b/c')
124
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()
125
131
path = branch_a.get_push_location()
126
self.assertEquals(out,
127
'Using saved push location: %s\n'
128
% urlutils.local_path_from_url(path))
129
132
self.assertEqual(err,
133
'Using saved push location: %s\n'
130
134
'All changes applied successfully.\n'
131
'Pushed up to revision 2.\n')
135
'Pushed up to revision 2.\n'
136
% urlutils.local_path_from_url(path))
132
137
self.assertEqual(path,
133
138
branch_b.bzrdir.root_transport.base)
134
139
# test explicit --remember
135
140
self.run_bzr('push ../branch_c --remember', working_dir='branch_a')
141
# Refresh the branch as 'push' modified it
142
branch_a = branch_a.bzrdir.open_branch()
136
143
self.assertEquals(branch_a.get_push_location(),
137
144
branch_c.bzrdir.root_transport.base)
145
152
b2 = branch.Branch.open('pushed-location')
146
153
self.assertEndsWith(b2.base, 'pushed-location/')
155
def test_push_no_tree(self):
156
# bzr 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')
148
166
def test_push_new_branch_revision_count(self):
149
167
# bzr push of a branch with revisions to a new location
150
168
# should print the number of revisions equal to the length of the
157
175
self.assertEqual('', out)
158
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.bzrdir.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)
160
195
def test_push_only_pushes_history(self):
161
196
# Knit branches should only push the history for the current revision.
162
197
format = bzrdir.BzrDirMetaFormat1()
207
242
t.commit(allow_pointless=True,
208
243
message='first commit')
209
244
self.run_bzr('push -d from to-one')
210
self.failUnlessExists('to-one')
245
self.assertPathExists('to-one')
211
246
self.run_bzr('push -d %s %s'
212
247
% tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
213
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()))
215
266
def test_push_smart_non_stacked_streaming_acceptance(self):
216
267
self.setup_smart_server_with_call_log()
224
275
# become necessary for this use case. Please do not adjust this number
225
276
# upwards without agreement from bzr's network support maintainers.
226
277
self.assertLength(9, self.hpss_calls)
278
self.assertLength(1, self.hpss_connections)
279
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
228
281
def test_push_smart_stacked_streaming_acceptance(self):
229
282
self.setup_smart_server_with_call_log()
239
292
# being too low. If rpc_count increases, more network roundtrips have
240
293
# become necessary for this use case. Please do not adjust this number
241
294
# upwards without agreement from bzr's network support maintainers.
242
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)
243
298
remote = branch.Branch.open('public')
244
299
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
256
311
# become necessary for this use case. Please do not adjust this number
257
312
# upwards without agreement from bzr's network support maintainers.
258
313
self.assertLength(11, self.hpss_calls)
314
self.assertLength(1, self.hpss_connections)
315
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
260
317
def test_push_smart_incremental_acceptance(self):
261
318
self.setup_smart_server_with_call_log()
272
329
# become necessary for this use case. Please do not adjust this number
273
330
# upwards without agreement from bzr's network support maintainers.
274
331
self.assertLength(11, self.hpss_calls)
332
self.assertLength(1, self.hpss_connections)
333
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
276
335
def test_push_smart_with_default_stacking_url_path_segment(self):
277
336
# If the default stacked-on location is a path element then branches
454
513
trunk_public = self.make_branch('public_trunk', format='1.9')
455
514
trunk_public.pull(trunk_tree.branch)
456
515
trunk_public_url = self.get_readonly_url('public_trunk')
457
trunk_tree.branch.set_public_branch(trunk_public_url)
516
br = trunk_tree.branch
517
br.set_public_branch(trunk_public_url)
458
518
# now we do a stacked push, which should determine the public location
460
520
out, err = self.run_bzr(['push', '--stacked',
651
711
self.tree.commit('modify file', rev_id='modified')
653
713
def set_config_push_strict(self, value):
654
# set config var (any of bazaar.conf, locations.conf, branch.conf
656
conf = self.tree.branch.get_config()
657
conf.set_user_option('push_strict', value)
714
br = branch.Branch.open('local')
715
br.get_config_stack().set('push_strict', value)
659
717
_default_command = ['push', '../to']
660
718
_default_wd = 'local'
661
719
_default_errors = ['Working tree ".*/local/" has uncommitted '
662
720
'changes \(See bzr status\)\.',]
663
_default_pushed_revid = 'modified'
721
_default_additional_error = 'Use --no-strict to force the push.\n'
722
_default_additional_warning = 'Uncommitted changes will not be pushed.'
665
725
def assertPushFails(self, args):
666
self.run_bzr_error(self._default_errors, self._default_command + args,
667
working_dir=self._default_wd, retcode=3)
726
out, err = self.run_bzr_error(self._default_errors,
727
self._default_command + args,
728
working_dir=self._default_wd, retcode=3)
729
self.assertContainsRe(err, self._default_additional_error)
669
def assertPushSucceeds(self, args, pushed_revid=None):
670
self.run_bzr(self._default_command + args,
671
working_dir=self._default_wd)
672
if pushed_revid is None:
673
pushed_revid = self._default_pushed_revid
674
tree_to = workingtree.WorkingTree.open('to')
675
repo_to = tree_to.branch.repository
676
self.assertTrue(repo_to.has_revision(pushed_revid))
677
self.assertEqual(tree_to.branch.last_revision_info()[1], pushed_revid)
731
def assertPushSucceeds(self, args, with_warning=False, revid_to_push=None):
733
error_regexes = self._default_errors
736
out, err = self.run_bzr(self._default_command + args,
737
working_dir=self._default_wd,
738
error_regexes=error_regexes)
740
self.assertContainsRe(err, self._default_additional_warning)
742
self.assertNotContainsRe(err, self._default_additional_warning)
743
branch_from = branch.Branch.open(self._default_wd)
744
if revid_to_push is None:
745
revid_to_push = branch_from.last_revision()
746
branch_to = branch.Branch.open('to')
747
repo_to = branch_to.repository
748
self.assertTrue(repo_to.has_revision(revid_to_push))
749
self.assertEqual(revid_to_push, branch_to.last_revision())
703
775
self.assertPushSucceeds([])
778
strict_push_change_scenarios = [
780
dict(_changes_type= '_uncommitted_changes')),
782
dict(_changes_type= '_pending_merges')),
783
('out-of-sync-trees',
784
dict(_changes_type= '_out_of_sync_trees')),
706
788
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
707
789
TestPushStrictMixin):
791
scenarios = strict_push_change_scenarios
709
792
_changes_type = None # Set by load_tests
741
824
self._default_wd = 'checkout'
742
825
self._default_errors = ["Working tree is out of date, please run"
743
826
" 'bzr update'\.",]
744
self._default_pushed_revid = 'modified-in-local'
746
828
def test_push_default(self):
747
self.assertPushFails([])
829
self.assertPushSucceeds([], with_warning=True)
749
831
def test_push_with_revision(self):
750
self.assertPushSucceeds(['-r', 'revid:added'], pushed_revid='added')
832
self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
752
834
def test_push_no_strict(self):
753
835
self.assertPushSucceeds(['--no-strict'])
795
877
self.assertEquals("", output)
796
878
self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
797
879
" push to dummy. You may want to use dpush instead.\n")
882
class TestPushOutput(script.TestCaseWithTransportAndScript):
884
def test_push_log_format(self):
887
Created a standalone tree (format: 2a)
892
$ bzr commit -m 'we need some foo'
893
2>Committing to:...trunk/
895
2>Committed revision 1.
896
$ bzr init ../feature
897
Created a standalone tree (format: 2a)
898
$ bzr push -v ../feature -Olog_format=line
900
1: jrandom@example.com ...we need some foo
901
2>All changes applied successfully.
902
2>Pushed up to revision 1.