35
35
from bzrlib.transport import memory
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)
38
62
class TestPush(tests.TestCaseWithTransport):
40
64
def test_push_error_on_vfs_http(self):
555
588
% re.escape(destination_url)],
556
589
['push', '-d', 'tree', destination_url], retcode=3)
557
590
self.assertEqual('', out)
593
class TestPushStrictMixin(object):
595
def make_local_branch_and_tree(self):
596
self.tree = self.make_branch_and_tree('local')
597
self.build_tree_contents([('local/file', 'initial')])
598
self.tree.add('file')
599
self.tree.commit('adding file', rev_id='added')
600
self.build_tree_contents([('local/file', 'modified')])
601
self.tree.commit('modify file', rev_id='modified')
603
def set_config_push_strict(self, value):
604
# set config var (any of bazaar.conf, locations.conf, branch.conf
606
conf = self.tree.branch.get_config()
607
conf.set_user_option('push_strict', value)
609
_default_command = ['push', '../to']
610
_default_wd = 'local'
611
_default_errors = ['Working tree ".*/local/" has uncommitted '
612
'changes \(See bzr status\)\.',]
613
_default_pushed_revid = 'modified'
615
def assertPushFails(self, args):
616
self.run_bzr_error(self._default_errors, self._default_command + args,
617
working_dir=self._default_wd, retcode=3)
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)
631
class TestPushStrictWithoutChanges(tests.TestCaseWithTransport,
632
TestPushStrictMixin):
635
super(TestPushStrictWithoutChanges, self).setUp()
636
self.make_local_branch_and_tree()
638
def test_push_default(self):
639
self.assertPushSucceeds([])
641
def test_push_strict(self):
642
self.assertPushSucceeds(['--strict'])
644
def test_push_no_strict(self):
645
self.assertPushSucceeds(['--no-strict'])
647
def test_push_config_var_strict(self):
648
self.set_config_push_strict('true')
649
self.assertPushSucceeds([])
651
def test_push_config_var_no_strict(self):
652
self.set_config_push_strict('false')
653
self.assertPushSucceeds([])
656
class TestPushStrictWithChanges(tests.TestCaseWithTransport,
657
TestPushStrictMixin):
659
_changes_type = None # Set by load_tests
662
super(TestPushStrictWithChanges, self).setUp()
663
getattr(self, self._changes_type)()
665
def _uncommitted_changes(self):
666
self.make_local_branch_and_tree()
667
# Make a change without committing it
668
self.build_tree_contents([('local/file', 'in progress')])
670
def _pending_merges(self):
671
self.make_local_branch_and_tree()
672
# Create 'other' branch containing a new file
673
other_bzrdir = self.tree.bzrdir.sprout('other')
674
other_tree = other_bzrdir.open_workingtree()
675
self.build_tree_contents([('other/other-file', 'other')])
676
other_tree.add('other-file')
677
other_tree.commit('other commit', rev_id='other')
678
# Merge and revert, leaving a pending merge
679
self.tree.merge_from_branch(other_tree.branch)
680
self.tree.revert(filenames=['other-file'], backups=False)
682
def _out_of_sync_trees(self):
683
self.make_local_branch_and_tree()
684
self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
685
# Make a change and commit it
686
self.build_tree_contents([('local/file', 'modified in local')])
687
self.tree.commit('modify file', rev_id='modified-in-local')
688
# Exercise commands from the checkout directory
689
self._default_wd = 'checkout'
690
self._default_errors = ["Working tree is out of date, please run"
692
self._default_pushed_revid = 'modified-in-local'
694
def test_push_default(self):
695
self.assertPushFails([])
697
def test_push_with_revision(self):
698
self.assertPushSucceeds(['-r', 'revid:added'], pushed_revid='added')
700
def test_push_no_strict(self):
701
self.assertPushSucceeds(['--no-strict'])
703
def test_push_strict_with_changes(self):
704
self.assertPushFails(['--strict'])
706
def test_push_respect_config_var_strict(self):
707
self.set_config_push_strict('true')
708
self.assertPushFails([])
710
def test_push_bogus_config_var_ignored(self):
711
self.set_config_push_strict("I don't want you to be strict")
712
self.assertPushFails([])
714
def test_push_no_strict_command_line_override_config(self):
715
self.set_config_push_strict('yES')
716
self.assertPushFails([])
717
self.assertPushSucceeds(['--no-strict'])
719
def test_push_strict_command_line_override_config(self):
720
self.set_config_push_strict('oFF')
721
self.assertPushFails(['--strict'])
722
self.assertPushSucceeds([])