33
33
from bzrlib.repofmt import knitrepo
34
from bzrlib.tests import (
34
from bzrlib.tests import http_server
41
35
from bzrlib.transport import memory
44
load_tests = scenarios.load_tests_apply_scenarios
38
def load_tests(standard_tests, module, loader):
39
"""Multiply tests for the push command."""
40
result = loader.suiteClass()
42
# one for each king of change
43
changes_tests, remaining_tests = tests.split_suite_by_condition(
44
standard_tests, tests.condition_isinstance((
45
TestPushStrictWithChanges,
49
dict(_changes_type= '_uncommitted_changes')),
51
dict(_changes_type= '_pending_merges')),
53
dict(_changes_type= '_out_of_sync_trees')),
55
tests.multiply_tests(changes_tests, changes_scenarios, result)
56
# No parametrization for the remaining tests
57
result.addTests(remaining_tests)
47
62
class TestPush(tests.TestCaseWithTransport):
104
119
transport.delete('branch_b/c')
105
120
out, err = self.run_bzr('push', working_dir='branch_a')
106
121
path = branch_a.get_push_location()
122
self.assertEquals(out,
123
'Using saved push location: %s\n'
124
% urlutils.local_path_from_url(path))
107
125
self.assertEqual(err,
108
'Using saved push location: %s\n'
109
126
'All changes applied successfully.\n'
110
'Pushed up to revision 2.\n'
111
% urlutils.local_path_from_url(path))
127
'Pushed up to revision 2.\n')
112
128
self.assertEqual(path,
113
129
branch_b.bzrdir.root_transport.base)
114
130
# test explicit --remember
125
141
b2 = branch.Branch.open('pushed-location')
126
142
self.assertEndsWith(b2.base, 'pushed-location/')
128
def test_push_no_tree(self):
129
# bzr push --no-tree of a branch with working trees
130
b = self.make_branch_and_tree('push-from')
131
self.build_tree(['push-from/file'])
134
out, err = self.run_bzr('push --no-tree -d push-from push-to')
135
self.assertEqual('', out)
136
self.assertEqual('Created new branch.\n', err)
137
self.assertPathDoesNotExist('push-to/file')
139
144
def test_push_new_branch_revision_count(self):
140
145
# bzr push of a branch with revisions to a new location
141
146
# should print the number of revisions equal to the length of the
148
153
self.assertEqual('', out)
149
154
self.assertEqual('Created new branch.\n', err)
151
def test_push_quiet(self):
152
# test that using -q makes output quiet
153
t = self.make_branch_and_tree('tree')
154
self.build_tree(['tree/file'])
157
self.run_bzr('push -d tree pushed-to')
158
path = t.branch.get_push_location()
159
out, err = self.run_bzr('push', working_dir="tree")
160
self.assertEqual('Using saved push location: %s\nNo new revisions to push.\n' % urlutils.local_path_from_url(path), err)
161
out, err = self.run_bzr('push -q', working_dir="tree")
162
self.assertEqual('', out)
163
self.assertEqual('', err)
165
156
def test_push_only_pushes_history(self):
166
157
# Knit branches should only push the history for the current revision.
167
158
format = bzrdir.BzrDirMetaFormat1()
212
203
t.commit(allow_pointless=True,
213
204
message='first commit')
214
205
self.run_bzr('push -d from to-one')
215
self.assertPathExists('to-one')
206
self.failUnlessExists('to-one')
216
207
self.run_bzr('push -d %s %s'
217
208
% tuple(map(urlutils.local_path_to_url, ['from', 'to-two'])))
218
self.assertPathExists('to-two')
220
def test_push_repository_no_branch_doesnt_fetch_all_revs(self):
221
# See https://bugs.launchpad.net/bzr/+bug/465517
222
target_repo = self.make_repository('target')
223
source = self.make_branch_builder('source')
224
source.start_series()
225
source.build_snapshot('A', None, [
226
('add', ('', 'root-id', 'directory', None))])
227
source.build_snapshot('B', ['A'], [])
228
source.build_snapshot('C', ['A'], [])
229
source.finish_series()
230
self.run_bzr('push target -d source')
231
self.addCleanup(target_repo.lock_read().unlock)
232
# We should have pushed 'C', but not 'B', since it isn't in the
234
self.assertEqual([('A',), ('C',)], sorted(target_repo.revisions.keys()))
209
self.failUnlessExists('to-two')
236
211
def test_push_smart_non_stacked_streaming_acceptance(self):
237
212
self.setup_smart_server_with_call_log()
260
235
# being too low. If rpc_count increases, more network roundtrips have
261
236
# become necessary for this use case. Please do not adjust this number
262
237
# upwards without agreement from bzr's network support maintainers.
263
self.assertLength(13, self.hpss_calls)
238
self.assertLength(14, self.hpss_calls)
264
239
remote = branch.Branch.open('public')
265
240
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
267
def test_push_smart_tags_streaming_acceptance(self):
268
self.setup_smart_server_with_call_log()
269
t = self.make_branch_and_tree('from')
270
rev_id = t.commit(allow_pointless=True, message='first commit')
271
t.branch.tags.set_tag('new-tag', rev_id)
272
self.reset_smart_call_log()
273
self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
274
# This figure represent the amount of work to perform this use case. It
275
# is entirely ok to reduce this number if a test fails due to rpc_count
276
# being too low. If rpc_count increases, more network roundtrips have
277
# become necessary for this use case. Please do not adjust this number
278
# upwards without agreement from bzr's network support maintainers.
279
self.assertLength(11, self.hpss_calls)
281
def test_push_smart_incremental_acceptance(self):
282
self.setup_smart_server_with_call_log()
283
t = self.make_branch_and_tree('from')
284
rev_id1 = t.commit(allow_pointless=True, message='first commit')
285
rev_id2 = t.commit(allow_pointless=True, message='second commit')
287
['push', self.get_url('to-one'), '-r1'], working_dir='from')
288
self.reset_smart_call_log()
289
self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
290
# This figure represent the amount of work to perform this use case. It
291
# is entirely ok to reduce this number if a test fails due to rpc_count
292
# being too low. If rpc_count increases, more network roundtrips have
293
# become necessary for this use case. Please do not adjust this number
294
# upwards without agreement from bzr's network support maintainers.
295
self.assertLength(11, self.hpss_calls)
297
242
def test_push_smart_with_default_stacking_url_path_segment(self):
298
243
# If the default stacked-on location is a path element then branches
299
244
# we push there over the smart server are stacked and their
337
282
working_dir='tree')
338
283
new_tree = workingtree.WorkingTree.open('new/tree')
339
284
self.assertEqual(tree.last_revision(), new_tree.last_revision())
340
self.assertPathExists('new/tree/a')
285
self.failUnlessExists('new/tree/a')
342
287
def test_push_use_existing(self):
343
288
"""'bzr push --use-existing-dir' can push into an existing dir.
358
303
new_tree = workingtree.WorkingTree.open('target')
359
304
self.assertEqual(tree.last_revision(), new_tree.last_revision())
360
305
# The push should have created target/a
361
self.assertPathExists('target/a')
363
def test_push_use_existing_into_empty_bzrdir(self):
364
"""'bzr push --use-existing-dir' into a dir with an empty .bzr dir
367
tree = self.create_simple_tree()
368
self.build_tree(['target/', 'target/.bzr/'])
370
['Target directory ../target already contains a .bzr directory, '
371
'but it is not valid.'],
372
'push ../target --use-existing-dir', working_dir='tree')
306
self.failUnlessExists('target/a')
374
308
def test_push_onto_repo(self):
375
309
"""We should be able to 'bzr push' into an existing bzrdir."""
578
512
class RedirectingMemoryTransport(memory.MemoryTransport):
580
514
def mkdir(self, relpath, mode=None):
515
from bzrlib.trace import mutter
581
516
if self._cwd == '/source/':
582
517
raise errors.RedirectRequested(self.abspath(relpath),
583
518
self.abspath('../target'),
590
525
return super(RedirectingMemoryTransport, self).mkdir(
593
def get(self, relpath):
594
if self.clone(relpath)._cwd == '/infinite-loop/':
595
raise errors.RedirectRequested(self.abspath(relpath),
596
self.abspath('../infinite-loop'),
599
return super(RedirectingMemoryTransport, self).get(relpath)
601
528
def _redirected_to(self, source, target):
602
529
# We do accept redirections
603
530
return transport.get_transport(target)
629
556
tests.TestCaseWithTransport.setUp(self)
630
557
self.memory_server = RedirectingMemoryServer()
631
self.start_server(self.memory_server)
558
self.memory_server.setUp()
559
self.addCleanup(self.memory_server.tearDown)
632
561
# Make the branch and tree that we'll be pushing.
633
562
t = self.make_branch_and_tree('tree')
634
563
self.build_tree(['tree/file'])
681
610
_default_wd = 'local'
682
611
_default_errors = ['Working tree ".*/local/" has uncommitted '
683
612
'changes \(See bzr status\)\.',]
684
_default_additional_error = 'Use --no-strict to force the push.\n'
685
_default_additional_warning = 'Uncommitted changes will not be pushed.'
613
_default_pushed_revid = 'modified'
688
615
def assertPushFails(self, args):
689
out, err = self.run_bzr_error(self._default_errors,
690
self._default_command + args,
691
working_dir=self._default_wd, retcode=3)
692
self.assertContainsRe(err, self._default_additional_error)
616
self.run_bzr_error(self._default_errors, self._default_command + args,
617
working_dir=self._default_wd, retcode=3)
694
def assertPushSucceeds(self, args, with_warning=False, revid_to_push=None):
696
error_regexes = self._default_errors
699
out, err = self.run_bzr(self._default_command + args,
700
working_dir=self._default_wd,
701
error_regexes=error_regexes)
703
self.assertContainsRe(err, self._default_additional_warning)
705
self.assertNotContainsRe(err, self._default_additional_warning)
706
branch_from = branch.Branch.open(self._default_wd)
707
if revid_to_push is None:
708
revid_to_push = branch_from.last_revision()
709
branch_to = branch.Branch.open('to')
710
repo_to = branch_to.repository
711
self.assertTrue(repo_to.has_revision(revid_to_push))
712
self.assertEqual(revid_to_push, branch_to.last_revision())
619
def assertPushSucceeds(self, args, pushed_revid=None):
620
self.run_bzr(self._default_command + args,
621
working_dir=self._default_wd)
622
if pushed_revid is None:
623
pushed_revid = self._default_pushed_revid
624
tree_to = workingtree.WorkingTree.open('to')
625
repo_to = tree_to.branch.repository
626
self.assertTrue(repo_to.has_revision(pushed_revid))
627
self.assertEqual(tree_to.branch.last_revision_info()[1], pushed_revid)
738
653
self.assertPushSucceeds([])
741
strict_push_change_scenarios = [
743
dict(_changes_type= '_uncommitted_changes')),
745
dict(_changes_type= '_pending_merges')),
746
('out-of-sync-trees',
747
dict(_changes_type= '_out_of_sync_trees')),
751
656
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
752
657
TestPushStrictMixin):
754
scenarios = strict_push_change_scenarios
755
659
_changes_type = None # Set by load_tests
758
662
super(TestPushStrictWithChanges, self).setUp()
759
# Apply the changes defined in load_tests: one of _uncommitted_changes,
760
# _pending_merges or _out_of_sync_trees
761
663
getattr(self, self._changes_type)()
763
665
def _uncommitted_changes(self):
787
689
self._default_wd = 'checkout'
788
690
self._default_errors = ["Working tree is out of date, please run"
789
691
" 'bzr update'\.",]
692
self._default_pushed_revid = 'modified-in-local'
791
694
def test_push_default(self):
792
self.assertPushSucceeds([], with_warning=True)
695
self.assertPushFails([])
794
697
def test_push_with_revision(self):
795
self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
698
self.assertPushSucceeds(['-r', 'revid:added'], pushed_revid='added')
797
700
def test_push_no_strict(self):
798
701
self.assertPushSucceeds(['--no-strict'])
817
720
self.set_config_push_strict('oFF')
818
721
self.assertPushFails(['--strict'])
819
722
self.assertPushSucceeds([])
822
class TestPushForeign(tests.TestCaseWithTransport):
825
super(TestPushForeign, self).setUp()
826
test_foreign.register_dummy_foreign_for_test(self)
828
def make_dummy_builder(self, relpath):
829
builder = self.make_branch_builder(
830
relpath, format=test_foreign.DummyForeignVcsDirFormat())
831
builder.build_snapshot('revid', None,
832
[('add', ('', 'TREE_ROOT', 'directory', None)),
833
('add', ('foo', 'fooid', 'file', 'bar'))])
836
def test_no_roundtripping(self):
837
target_branch = self.make_dummy_builder('dp').get_branch()
838
source_tree = self.make_branch_and_tree("dc")
839
output, error = self.run_bzr("push -d dc dp", retcode=3)
840
self.assertEquals("", output)
841
self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
842
" push to dummy. You may want to use dpush instead.\n")