244
237
remote = branch.Branch.open('public')
245
238
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
247
def test_push_smart_tags_streaming_acceptance(self):
248
self.setup_smart_server_with_call_log()
249
t = self.make_branch_and_tree('from')
250
rev_id = t.commit(allow_pointless=True, message='first commit')
251
t.branch.tags.set_tag('new-tag', rev_id)
252
self.reset_smart_call_log()
253
self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
254
# This figure represent the amount of work to perform this use case. It
255
# is entirely ok to reduce this number if a test fails due to rpc_count
256
# being too low. If rpc_count increases, more network roundtrips have
257
# become necessary for this use case. Please do not adjust this number
258
# upwards without agreement from bzr's network support maintainers.
259
self.assertLength(11, self.hpss_calls)
261
def test_push_smart_incremental_acceptance(self):
262
self.setup_smart_server_with_call_log()
263
t = self.make_branch_and_tree('from')
264
rev_id1 = t.commit(allow_pointless=True, message='first commit')
265
rev_id2 = t.commit(allow_pointless=True, message='second commit')
267
['push', self.get_url('to-one'), '-r1'], working_dir='from')
268
self.reset_smart_call_log()
269
self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
270
# This figure represent the amount of work to perform this use case. It
271
# is entirely ok to reduce this number if a test fails due to rpc_count
272
# being too low. If rpc_count increases, more network roundtrips have
273
# become necessary for this use case. Please do not adjust this number
274
# upwards without agreement from bzr's network support maintainers.
275
self.assertLength(11, self.hpss_calls)
277
240
def test_push_smart_with_default_stacking_url_path_segment(self):
278
241
# If the default stacked-on location is a path element then branches
279
242
# we push there over the smart server are stacked and their
340
303
# The push should have created target/a
341
304
self.failUnlessExists('target/a')
343
def test_push_use_existing_into_empty_bzrdir(self):
344
"""'bzr push --use-existing-dir' into a dir with an empty .bzr dir
347
tree = self.create_simple_tree()
348
self.build_tree(['target/', 'target/.bzr/'])
350
['Target directory ../target already contains a .bzr directory, '
351
'but it is not valid.'],
352
'push ../target --use-existing-dir', working_dir='tree')
354
306
def test_push_onto_repo(self):
355
307
"""We should be able to 'bzr push' into an existing bzrdir."""
356
308
tree = self.create_simple_tree()
558
510
class RedirectingMemoryTransport(memory.MemoryTransport):
560
512
def mkdir(self, relpath, mode=None):
513
from bzrlib.trace import mutter
561
514
if self._cwd == '/source/':
562
515
raise errors.RedirectRequested(self.abspath(relpath),
563
516
self.abspath('../target'),
570
523
return super(RedirectingMemoryTransport, self).mkdir(
573
def get(self, relpath):
574
if self.clone(relpath)._cwd == '/infinite-loop/':
575
raise errors.RedirectRequested(self.abspath(relpath),
576
self.abspath('../infinite-loop'),
579
return super(RedirectingMemoryTransport, self).get(relpath)
581
526
def _redirected_to(self, source, target):
582
527
# We do accept redirections
583
528
return transport.get_transport(target)
609
554
tests.TestCaseWithTransport.setUp(self)
610
555
self.memory_server = RedirectingMemoryServer()
611
self.start_server(self.memory_server)
556
self.memory_server.setUp()
557
self.addCleanup(self.memory_server.tearDown)
612
559
# Make the branch and tree that we'll be pushing.
613
560
t = self.make_branch_and_tree('tree')
614
561
self.build_tree(['tree/file'])
657
604
conf = self.tree.branch.get_config()
658
605
conf.set_user_option('push_strict', value)
660
_default_command = ['push', '../to']
661
_default_wd = 'local'
662
_default_errors = ['Working tree ".*/local/" has uncommitted '
663
'changes \(See bzr status\)\.',]
664
_default_additional_error = 'Use --no-strict to force the push.\n'
665
_default_additional_warning = 'Uncommitted changes will not be pushed.'
668
607
def assertPushFails(self, args):
669
out, err = self.run_bzr_error(self._default_errors,
670
self._default_command + args,
671
working_dir=self._default_wd, retcode=3)
672
self.assertContainsRe(err, self._default_additional_error)
674
def assertPushSucceeds(self, args, with_warning=False, revid_to_push=None):
676
error_regexes = self._default_errors
679
out, err = self.run_bzr(self._default_command + args,
680
working_dir=self._default_wd,
681
error_regexes=error_regexes)
683
self.assertContainsRe(err, self._default_additional_warning)
685
self.assertNotContainsRe(err, self._default_additional_warning)
686
branch_from = branch.Branch.open(self._default_wd)
687
if revid_to_push is None:
688
revid_to_push = branch_from.last_revision()
689
branch_to = branch.Branch.open('to')
690
repo_to = branch_to.repository
691
self.assertTrue(repo_to.has_revision(revid_to_push))
692
self.assertEqual(revid_to_push, branch_to.last_revision())
696
class TestPushStrictWithoutChanges(tests.TestCaseWithTransport,
697
TestPushStrictMixin):
608
self.run_bzr_error(['Working tree ".*/local/"'
609
' has uncommitted changes \(See bzr status\)\.',],
610
['push', '../to'] + args,
611
working_dir='local', retcode=3)
613
def assertPushSucceeds(self, args, pushed_revid=None):
614
self.run_bzr(['push', '../to'] + args,
616
if pushed_revid is None:
617
pushed_revid = 'modified'
618
tree_to = workingtree.WorkingTree.open('to')
619
repo_to = tree_to.branch.repository
620
self.assertTrue(repo_to.has_revision(pushed_revid))
621
self.assertEqual(tree_to.branch.last_revision_info()[1], pushed_revid)
625
class TestPushStrictWithoutChanges(TestPushStrict):
700
628
super(TestPushStrictWithoutChanges, self).setUp()
718
646
self.assertPushSucceeds([])
721
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
722
TestPushStrictMixin):
649
class TestPushStrictWithChanges(TestPushStrict):
724
651
_changes_type = None # Set by load_tests
727
654
super(TestPushStrictWithChanges, self).setUp()
728
# Apply the changes defined in load_tests: one of _uncommitted_changes,
729
# _pending_merges or _out_of_sync_trees
730
655
getattr(self, self._changes_type)()
732
657
def _uncommitted_changes(self):
746
671
self.tree.merge_from_branch(other_tree.branch)
747
672
self.tree.revert(filenames=['other-file'], backups=False)
749
def _out_of_sync_trees(self):
750
self.make_local_branch_and_tree()
751
self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
752
# Make a change and commit it
753
self.build_tree_contents([('local/file', 'modified in local')])
754
self.tree.commit('modify file', rev_id='modified-in-local')
755
# Exercise commands from the checkout directory
756
self._default_wd = 'checkout'
757
self._default_errors = ["Working tree is out of date, please run"
760
674
def test_push_default(self):
761
self.assertPushSucceeds([], with_warning=True)
675
self.assertPushFails([])
763
677
def test_push_with_revision(self):
764
self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
678
self.assertPushSucceeds(['-r', 'revid:added'], pushed_revid='added')
766
680
def test_push_no_strict(self):
767
681
self.assertPushSucceeds(['--no-strict'])
786
700
self.set_config_push_strict('oFF')
787
701
self.assertPushFails(['--strict'])
788
702
self.assertPushSucceeds([])
791
class TestPushForeign(blackbox.ExternalBase):
794
super(TestPushForeign, self).setUp()
795
test_foreign.register_dummy_foreign_for_test(self)
797
def make_dummy_builder(self, relpath):
798
builder = self.make_branch_builder(
799
relpath, format=test_foreign.DummyForeignVcsDirFormat())
800
builder.build_snapshot('revid', None,
801
[('add', ('', 'TREE_ROOT', 'directory', None)),
802
('add', ('foo', 'fooid', 'file', 'bar'))])
805
def test_no_roundtripping(self):
806
target_branch = self.make_dummy_builder('dp').get_branch()
807
source_tree = self.make_branch_and_tree("dc")
808
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"
811
" push to dummy. You may want to use dpush instead.\n")