34
34
from bzrlib.tests import (
40
41
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)
44
load_tests = scenarios.load_tests_apply_scenarios
67
47
class TestPush(tests.TestCaseWithTransport):
146
126
b2 = branch.Branch.open('pushed-location')
147
127
self.assertEndsWith(b2.base, 'pushed-location/')
129
def test_push_no_tree(self):
130
# bzr push --no-tree of a branch with working trees
131
b = self.make_branch_and_tree('push-from')
132
self.build_tree(['push-from/file'])
135
out, err = self.run_bzr('push --no-tree -d push-from push-to')
136
self.assertEqual('', out)
137
self.assertEqual('Created new branch.\n', err)
138
self.assertPathDoesNotExist('push-to/file')
149
140
def test_push_new_branch_revision_count(self):
150
141
# bzr push of a branch with revisions to a new location
151
142
# should print the number of revisions equal to the length of the
208
199
t.commit(allow_pointless=True,
209
200
message='first commit')
210
201
self.run_bzr('push -d from to-one')
211
self.failUnlessExists('to-one')
202
self.assertPathExists('to-one')
212
203
self.run_bzr('push -d %s %s'
213
204
% tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
214
self.failUnlessExists('to-two')
205
self.assertPathExists('to-two')
207
def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
208
# See https://bugs.launchpad.net/bzr/+bug/465517
209
target_repo = self.make_repository('target')
210
source = self.make_branch_builder('source')
211
source.start_series()
212
source.build_snapshot('A', None, [
213
('add', ('', 'root-id', 'directory', None))])
214
source.build_snapshot('B', ['A'], [])
215
source.build_snapshot('C', ['A'], [])
216
source.finish_series()
217
self.run_bzr('push target -d source')
218
self.addCleanup(target_repo.lock_read().unlock)
219
# We should have pushed 'C', but not 'B', since it isn't in the
221
self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
216
223
def test_push_smart_non_stacked_streaming_acceptance(self):
217
224
self.setup_smart_server_with_call_log()
240
247
# being too low. If rpc_count increases, more network roundtrips have
241
248
# become necessary for this use case. Please do not adjust this number
242
249
# upwards without agreement from bzr's network support maintainers.
243
self.assertLength(14, self.hpss_calls)
250
self.assertLength(13, self.hpss_calls)
244
251
remote = branch.Branch.open('public')
245
252
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
317
324
working_dir='tree')
318
325
new_tree = workingtree.WorkingTree.open('new/tree')
319
326
self.assertEqual(tree.last_revision(), new_tree.last_revision())
320
self.failUnlessExists('new/tree/a')
327
self.assertPathExists('new/tree/a')
322
329
def test_push_use_existing(self):
323
330
"""'bzr push --use-existing-dir' can push into an existing dir.
338
345
new_tree = workingtree.WorkingTree.open('target')
339
346
self.assertEqual(tree.last_revision(), new_tree.last_revision())
340
347
# The push should have created target/a
341
self.failUnlessExists('target/a')
348
self.assertPathExists('target/a')
343
350
def test_push_use_existing_into_empty_bzrdir(self):
344
351
"""'bzr push --use-existing-dir' into a dir with an empty .bzr dir
661
668
_default_wd = 'local'
662
669
_default_errors = ['Working tree ".*/local/" has uncommitted '
663
670
'changes \(See bzr status\)\.',]
664
_default_pushed_revid = 'modified'
671
_default_additional_error = 'Use --no-strict to force the push.\n'
672
_default_additional_warning = 'Uncommitted changes will not be pushed.'
666
675
def assertPushFails(self, args):
667
self.run_bzr_error(self._default_errors, self._default_command + args,
668
working_dir=self._default_wd, retcode=3)
676
out, err = self.run_bzr_error(self._default_errors,
677
self._default_command + args,
678
working_dir=self._default_wd, retcode=3)
679
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)
681
def assertPushSucceeds(self, args, with_warning=False, revid_to_push=None):
683
error_regexes = self._default_errors
686
out, err = self.run_bzr(self._default_command + args,
687
working_dir=self._default_wd,
688
error_regexes=error_regexes)
690
self.assertContainsRe(err, self._default_additional_warning)
692
self.assertNotContainsRe(err, self._default_additional_warning)
693
branch_from = branch.Branch.open(self._default_wd)
694
if revid_to_push is None:
695
revid_to_push = branch_from.last_revision()
696
branch_to = branch.Branch.open('to')
697
repo_to = branch_to.repository
698
self.assertTrue(repo_to.has_revision(revid_to_push))
699
self.assertEqual(revid_to_push, branch_to.last_revision())
704
725
self.assertPushSucceeds([])
728
strict_push_change_scenarios = [
730
dict(_changes_type= '_uncommitted_changes')),
732
dict(_changes_type= '_pending_merges')),
733
('out-of-sync-trees',
734
dict(_changes_type= '_out_of_sync_trees')),
707
738
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
708
739
TestPushStrictMixin):
741
scenarios = strict_push_change_scenarios
710
742
_changes_type = None # Set by load_tests
742
774
self._default_wd = 'checkout'
743
775
self._default_errors = ["Working tree is out of date, please run"
744
776
" 'bzr update'\.",]
745
self._default_pushed_revid = 'modified-in-local'
747
778
def test_push_default(self):
748
self.assertPushFails([])
779
self.assertPushSucceeds([], with_warning=True)
750
781
def test_push_with_revision(self):
751
self.assertPushSucceeds(['-r', 'revid:added'], pushed_revid='added')
782
self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
753
784
def test_push_no_strict(self):
754
785
self.assertPushSucceeds(['--no-strict'])
763
794
def test_push_bogus_config_var_ignored(self):
764
795
self.set_config_push_strict("I don't want you to be strict")
765
self.assertPushFails([])
796
self.assertPushSucceeds([], with_warning=True)
767
798
def test_push_no_strict_command_line_override_config(self):
768
799
self.set_config_push_strict('yES')