569
591
class TestPushStrict(tests.TestCaseWithTransport):
571
593
def make_local_branch_and_tree(self):
572
tree = self.make_branch_and_tree('local')
594
self.tree = self.make_branch_and_tree('local')
573
595
self.build_tree_contents([('local/file', 'initial')])
575
tree.commit('adding file', rev_id='from-1')
578
def make_local_branch_and_tree_with_changes(self):
579
tree = self.make_local_branch_and_tree()
596
self.tree.add('file')
597
self.tree.commit('adding file', rev_id='added')
581
598
self.build_tree_contents([('local/file', 'modified')])
599
self.tree.commit('modify file', rev_id='modified')
584
def set_config_push_strict(self, tree, value):
601
def set_config_push_strict(self, value):
585
602
# set config var (any of bazaar.conf, locations.conf, branch.conf
587
conf = tree.branch.get_config()
604
conf = self.tree.branch.get_config()
588
605
conf.set_user_option('push_strict', value)
590
def assertPushFails(self, location, *args):
607
def assertPushFails(self, args):
591
608
self.run_bzr_error(['Working tree ".*/local/"'
592
' has uncommitted changes.$',],
593
['push', '../' + location] + list(args),
609
' has uncommitted changes \(See bzr status\)\.',],
610
['push', '../to'] + args,
594
611
working_dir='local', retcode=3)
596
def assertPushSucceeds(self, location, *args):
597
self.run_bzr(['push', '../' + location] + list(args),
613
def assertPushSucceeds(self, args, pushed_revid=None):
614
self.run_bzr(['push', '../to'] + args,
598
615
working_dir='local')
599
tree_to = workingtree.WorkingTree.open(location)
616
if pushed_revid is None:
617
pushed_revid = 'modified'
618
tree_to = workingtree.WorkingTree.open('to')
600
619
repo_to = tree_to.branch.repository
601
self.assertTrue(repo_to.has_revision('from-1'))
602
self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
604
def test_push_default(self):
605
tree = self.make_local_branch_and_tree_with_changes()
606
self.assertPushSucceeds('to')
608
def test_push_no_strict_with_changes(self):
609
tree = self.make_local_branch_and_tree_with_changes()
610
self.assertPushSucceeds('to', '--no-strict')
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):
628
super(TestPushStrictWithoutChanges, self).setUp()
629
self.make_local_branch_and_tree()
631
def test_push_default(self):
632
self.assertPushSucceeds([])
634
def test_push_strict(self):
635
self.assertPushSucceeds(['--strict'])
637
def test_push_no_strict(self):
638
self.assertPushSucceeds(['--no-strict'])
640
def test_push_config_var_strict(self):
641
self.set_config_push_strict('true')
642
self.assertPushSucceeds([])
644
def test_push_config_var_no_strict(self):
645
self.set_config_push_strict('false')
646
self.assertPushSucceeds([])
649
class TestPushStrictWithChanges(TestPushStrict):
651
_changes_type = None # Set by load_tests
654
super(TestPushStrictWithChanges, self).setUp()
655
getattr(self, self._changes_type)()
657
def _uncommitted_changes(self):
658
self.make_local_branch_and_tree()
659
# Make a change without committing it
660
self.build_tree_contents([('local/file', 'in progress')])
662
def _pending_merges(self):
663
self.make_local_branch_and_tree()
664
# Create 'other' branch containing a new file
665
other_bzrdir = self.tree.bzrdir.sprout('other')
666
other_tree = other_bzrdir.open_workingtree()
667
self.build_tree_contents([('other/other-file', 'other')])
668
other_tree.add('other-file')
669
other_tree.commit('other commit', rev_id='other')
670
# Merge and revert, leaving a pending merge
671
self.tree.merge_from_branch(other_tree.branch)
672
self.tree.revert(filenames=['other-file'], backups=False)
674
def test_push_default(self):
675
self.assertPushFails([])
677
def test_push_with_revision(self):
678
self.assertPushSucceeds(['-r', 'revid:added'], pushed_revid='added')
680
def test_push_no_strict(self):
681
self.assertPushSucceeds(['--no-strict'])
612
683
def test_push_strict_with_changes(self):
613
tree = self.make_local_branch_and_tree_with_changes()
614
self.assertPushFails('to', '--strict')
616
def test_push_strict_without_changes(self):
617
tree = self.make_local_branch_and_tree()
618
self.assertPushSucceeds('to', '--strict')
684
self.assertPushFails(['--strict'])
620
686
def test_push_respect_config_var_strict(self):
621
tree = self.make_local_branch_and_tree_with_changes()
622
self.set_config_push_strict(tree, 'true')
623
self.assertPushFails('to')
687
self.set_config_push_strict('true')
688
self.assertPushFails([])
625
690
def test_push_bogus_config_var_ignored(self):
626
tree = self.make_local_branch_and_tree_with_changes()
627
self.set_config_push_strict(tree, "I don't want you to be strict")
628
self.assertPushSucceeds('to')
691
self.set_config_push_strict("I don't want you to be strict")
692
self.assertPushFails([])
630
694
def test_push_no_strict_command_line_override_config(self):
631
tree = self.make_local_branch_and_tree_with_changes()
632
self.set_config_push_strict(tree, 'yES')
633
self.assertPushFails('to')
634
self.assertPushSucceeds('to', '--no-strict')
695
self.set_config_push_strict('yES')
696
self.assertPushFails([])
697
self.assertPushSucceeds(['--no-strict'])
636
699
def test_push_strict_command_line_override_config(self):
637
tree = self.make_local_branch_and_tree_with_changes()
638
self.set_config_push_strict(tree, 'oFF')
639
self.assertPushFails('to', '--strict')
640
self.assertPushSucceeds('to')
700
self.set_config_push_strict('oFF')
701
self.assertPushFails(['--strict'])
702
self.assertPushSucceeds([])