34
35
from bzrlib.tests import (
40
43
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)
46
load_tests = scenarios.load_tests_apply_scenarios
67
49
class TestPush(tests.TestCaseWithTransport):
124
106
transport.delete('branch_b/c')
125
107
out, err = self.run_bzr('push', working_dir='branch_a')
126
108
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
109
self.assertEqual(err,
110
'Using saved push location: %s\n'
131
111
'All changes applied successfully.\n'
132
'Pushed up to revision 2.\n')
112
'Pushed up to revision 2.\n'
113
% urlutils.local_path_from_url(path))
133
114
self.assertEqual(path,
134
115
branch_b.bzrdir.root_transport.base)
135
116
# test explicit --remember
146
127
b2 = branch.Branch.open('pushed-location')
147
128
self.assertEndsWith(b2.base, 'pushed-location/')
130
def test_push_no_tree(self):
131
# bzr push --no-tree of a branch with working trees
132
b = self.make_branch_and_tree('push-from')
133
self.build_tree(['push-from/file'])
136
out, err = self.run_bzr('push --no-tree -d push-from push-to')
137
self.assertEqual('', out)
138
self.assertEqual('Created new branch.\n', err)
139
self.assertPathDoesNotExist('push-to/file')
149
141
def test_push_new_branch_revision_count(self):
150
142
# bzr push of a branch with revisions to a new location
151
143
# should print the number of revisions equal to the length of the
158
150
self.assertEqual('', out)
159
151
self.assertEqual('Created new branch.\n', err)
153
def test_push_quiet(self):
154
# test that using -q makes output quiet
155
t = self.make_branch_and_tree('tree')
156
self.build_tree(['tree/file'])
159
self.run_bzr('push -d tree pushed-to')
160
path = t.branch.get_push_location()
161
out, err = self.run_bzr('push', working_dir="tree")
162
self.assertEqual('Using saved push location: %s\n'
163
'No new revisions or tags to push.\n' %
164
urlutils.local_path_from_url(path), err)
165
out, err = self.run_bzr('push -q', working_dir="tree")
166
self.assertEqual('', out)
167
self.assertEqual('', err)
161
169
def test_push_only_pushes_history(self):
162
170
# Knit branches should only push the history for the current revision.
163
171
format = bzrdir.BzrDirMetaFormat1()
208
216
t.commit(allow_pointless=True,
209
217
message='first commit')
210
218
self.run_bzr('push -d from to-one')
211
self.failUnlessExists('to-one')
219
self.assertPathExists('to-one')
212
220
self.run_bzr('push -d %s %s'
213
221
% tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
214
self.failUnlessExists('to-two')
222
self.assertPathExists('to-two')
224
def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
225
# See https://bugs.launchpad.net/bzr/+bug/465517
226
target_repo = self.make_repository('target')
227
source = self.make_branch_builder('source')
228
source.start_series()
229
source.build_snapshot('A', None, [
230
('add', ('', 'root-id', 'directory', None))])
231
source.build_snapshot('B', ['A'], [])
232
source.build_snapshot('C', ['A'], [])
233
source.finish_series()
234
self.run_bzr('push target -d source')
235
self.addCleanup(target_repo.lock_read().unlock)
236
# We should have pushed 'C', but not 'B', since it isn't in the
238
self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
216
240
def test_push_smart_non_stacked_streaming_acceptance(self):
217
241
self.setup_smart_server_with_call_log()
240
264
# being too low. If rpc_count increases, more network roundtrips have
241
265
# become necessary for this use case. Please do not adjust this number
242
266
# upwards without agreement from bzr's network support maintainers.
243
self.assertLength(14, self.hpss_calls)
267
self.assertLength(13, self.hpss_calls)
244
268
remote = branch.Branch.open('public')
245
269
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
338
362
new_tree = workingtree.WorkingTree.open('target')
339
363
self.assertEqual(tree.last_revision(), new_tree.last_revision())
340
364
# The push should have created target/a
341
self.failUnlessExists('target/a')
365
self.assertPathExists('target/a')
343
367
def test_push_use_existing_into_empty_bzrdir(self):
344
368
"""'bzr push --use-existing-dir' into a dir with an empty .bzr dir
654
678
def set_config_push_strict(self, value):
655
679
# 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)
681
conf = self.tree.branch.get_config_stack()
682
conf.set('push_strict', value)
660
684
_default_command = ['push', '../to']
661
685
_default_wd = 'local'
662
686
_default_errors = ['Working tree ".*/local/" has uncommitted '
663
687
'changes \(See bzr status\)\.',]
664
_default_pushed_revid = 'modified'
688
_default_additional_error = 'Use --no-strict to force the push.\n'
689
_default_additional_warning = 'Uncommitted changes will not be pushed.'
666
692
def assertPushFails(self, args):
667
self.run_bzr_error(self._default_errors, self._default_command + args,
668
working_dir=self._default_wd, retcode=3)
693
out, err = self.run_bzr_error(self._default_errors,
694
self._default_command + args,
695
working_dir=self._default_wd, retcode=3)
696
self.assertContainsRe(err, self._default_additional_error)
670
def assertPushSucceeds(self, args, pushed_revid=None):
671
self.run_bzr(self._default_command + args,
672
working_dir=self._default_wd)
673
if pushed_revid is None:
674
pushed_revid = self._default_pushed_revid
675
tree_to = workingtree.WorkingTree.open('to')
676
repo_to = tree_to.branch.repository
677
self.assertTrue(repo_to.has_revision(pushed_revid))
678
self.assertEqual(tree_to.branch.last_revision_info()[1], pushed_revid)
698
def assertPushSucceeds(self, args, with_warning=False, revid_to_push=None):
700
error_regexes = self._default_errors
703
out, err = self.run_bzr(self._default_command + args,
704
working_dir=self._default_wd,
705
error_regexes=error_regexes)
707
self.assertContainsRe(err, self._default_additional_warning)
709
self.assertNotContainsRe(err, self._default_additional_warning)
710
branch_from = branch.Branch.open(self._default_wd)
711
if revid_to_push is None:
712
revid_to_push = branch_from.last_revision()
713
branch_to = branch.Branch.open('to')
714
repo_to = branch_to.repository
715
self.assertTrue(repo_to.has_revision(revid_to_push))
716
self.assertEqual(revid_to_push, branch_to.last_revision())
704
742
self.assertPushSucceeds([])
745
strict_push_change_scenarios = [
747
dict(_changes_type= '_uncommitted_changes')),
749
dict(_changes_type= '_pending_merges')),
750
('out-of-sync-trees',
751
dict(_changes_type= '_out_of_sync_trees')),
707
755
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
708
756
TestPushStrictMixin):
758
scenarios = strict_push_change_scenarios
710
759
_changes_type = None # Set by load_tests
742
791
self._default_wd = 'checkout'
743
792
self._default_errors = ["Working tree is out of date, please run"
744
793
" 'bzr update'\.",]
745
self._default_pushed_revid = 'modified-in-local'
747
795
def test_push_default(self):
748
self.assertPushFails([])
796
self.assertPushSucceeds([], with_warning=True)
750
798
def test_push_with_revision(self):
751
self.assertPushSucceeds(['-r', 'revid:added'], pushed_revid='added')
799
self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
753
801
def test_push_no_strict(self):
754
802
self.assertPushSucceeds(['--no-strict'])
796
844
self.assertEquals("", output)
797
845
self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
798
846
" push to dummy. You may want to use dpush instead.\n")
849
class TestPushOutput(script.TestCaseWithTransportAndScript):
851
def test_push_log_format(self):
854
Created a standalone tree (format: 2a)
859
$ bzr commit -m 'we need some foo'
860
2>Committing to:...trunk/
862
2>Committed revision 1.
863
$ bzr init ../feature
864
Created a standalone tree (format: 2a)
865
$ bzr push -v ../feature -Olog_format=line
867
1: jrandom@example.com ...we need some foo
868
2>All changes applied successfully.
869
2>Pushed up to revision 1.