Merge lp:~vila/bzr/284038-push-strict into lp:~bzr/bzr/trunk-old

Proposed by Vincent Ladeuil
Status: Merged
Merged at revision: not available
Proposed branch: lp:~vila/bzr/284038-push-strict
Merge into: lp:~bzr/bzr/trunk-old
Diff against target: 155 lines
To merge this branch: bzr merge lp:~vila/bzr/284038-push-strict
Reviewer Review Type Date Requested Status
John A Meinel Approve
bzr-core Pending
Review via email: mp+8056@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

Still related to 'push --strict', this patch addresses the concerns raised
in the previous review by:
- adding a check that the working tree is in sync with its branch,
- mentioning the --no-strict option in the error messages so that users
  are pointed in the right direction.

Revision history for this message
John A Meinel (jameinel) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bzrlib/builtins.py'
--- bzrlib/builtins.py 2009-06-30 17:00:26 +0000
+++ bzrlib/builtins.py 2009-06-30 20:35:19 +0000
@@ -1117,7 +1117,14 @@
1117 and (strict is None or strict)): # Default to True:1117 and (strict is None or strict)): # Default to True:
1118 changes = tree.changes_from(tree.basis_tree())1118 changes = tree.changes_from(tree.basis_tree())
1119 if changes.has_changed() or len(tree.get_parent_ids()) > 1:1119 if changes.has_changed() or len(tree.get_parent_ids()) > 1:
1120 raise errors.UncommittedChanges(tree)1120 raise errors.UncommittedChanges(
1121 tree, more='Use --no-strict to force the push.')
1122 if tree.last_revision() != tree.branch.last_revision():
1123 # The tree has lost sync with its branch, there is little
1124 # chance that the user is aware of it but he can still force
1125 # the push with --no-strict
1126 raise errors.OutOfDateTree(
1127 tree, more='Use --no-strict to force the push.')
11211128
1122 # Get the stacked_on branch, if any1129 # Get the stacked_on branch, if any
1123 if stacked_on is not None:1130 if stacked_on is not None:
11241131
=== modified file 'bzrlib/errors.py'
--- bzrlib/errors.py 2009-06-30 08:06:35 +0000
+++ bzrlib/errors.py 2009-06-30 20:35:19 +0000
@@ -2093,11 +2093,16 @@
20932093
2094class OutOfDateTree(BzrError):2094class OutOfDateTree(BzrError):
20952095
2096 _fmt = "Working tree is out of date, please run 'bzr update'."2096 _fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
20972097
2098 def __init__(self, tree):2098 def __init__(self, tree, more=None):
2099 if more is None:
2100 more = ''
2101 else:
2102 more = ' ' + more
2099 BzrError.__init__(self)2103 BzrError.__init__(self)
2100 self.tree = tree2104 self.tree = tree
2105 self.more = more
21012106
21022107
2103class PublicBranchOutOfDate(BzrError):2108class PublicBranchOutOfDate(BzrError):
@@ -2779,13 +2784,17 @@
2779class UncommittedChanges(BzrError):2784class UncommittedChanges(BzrError):
27802785
2781 _fmt = ('Working tree "%(display_url)s" has uncommitted changes'2786 _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
2782 ' (See bzr status).')2787 ' (See bzr status).%(more)s')
27832788
2784 def __init__(self, tree):2789 def __init__(self, tree, more=None):
2790 if more is None:
2791 more = ''
2792 else:
2793 more = ' ' + more
2785 import bzrlib.urlutils as urlutils2794 import bzrlib.urlutils as urlutils
2786 display_url = urlutils.unescape_for_display(2795 display_url = urlutils.unescape_for_display(
2787 tree.bzrdir.root_transport.base, 'ascii')2796 tree.bzrdir.root_transport.base, 'ascii')
2788 BzrError.__init__(self, tree=tree, display_url=display_url)2797 BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
27892798
27902799
2791class MissingTemplateVariable(BzrError):2800class MissingTemplateVariable(BzrError):
27922801
=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- bzrlib/tests/blackbox/test_push.py 2009-06-30 09:19:06 +0000
+++ bzrlib/tests/blackbox/test_push.py 2009-06-30 20:35:19 +0000
@@ -47,8 +47,10 @@
47 changes_scenarios = [47 changes_scenarios = [
48 ('uncommitted',48 ('uncommitted',
49 dict(_changes_type= '_uncommitted_changes')),49 dict(_changes_type= '_uncommitted_changes')),
50 ('pending_merges',50 ('pending-merges',
51 dict(_changes_type= '_pending_merges')),51 dict(_changes_type= '_pending_merges')),
52 ('out-of-sync-trees',
53 dict(_changes_type= '_out_of_sync_trees')),
52 ]54 ]
53 tests.multiply_tests(changes_tests, changes_scenarios, result)55 tests.multiply_tests(changes_tests, changes_scenarios, result)
54 # No parametrization for the remaining tests56 # No parametrization for the remaining tests
@@ -588,7 +590,7 @@
588 self.assertEqual('', out)590 self.assertEqual('', out)
589591
590592
591class TestPushStrict(tests.TestCaseWithTransport):593class TestPushStrictMixin(object):
592594
593 def make_local_branch_and_tree(self):595 def make_local_branch_and_tree(self):
594 self.tree = self.make_branch_and_tree('local')596 self.tree = self.make_branch_and_tree('local')
@@ -604,17 +606,21 @@
604 conf = self.tree.branch.get_config()606 conf = self.tree.branch.get_config()
605 conf.set_user_option('push_strict', value)607 conf.set_user_option('push_strict', value)
606608
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'
614
607 def assertPushFails(self, args):615 def assertPushFails(self, args):
608 self.run_bzr_error(['Working tree ".*/local/"'616 self.run_bzr_error(self._default_errors, self._default_command + args,
609 ' has uncommitted changes \(See bzr status\)\.',],617 working_dir=self._default_wd, retcode=3)
610 ['push', '../to'] + args,
611 working_dir='local', retcode=3)
612618
613 def assertPushSucceeds(self, args, pushed_revid=None):619 def assertPushSucceeds(self, args, pushed_revid=None):
614 self.run_bzr(['push', '../to'] + args,620 self.run_bzr(self._default_command + args,
615 working_dir='local')621 working_dir=self._default_wd)
616 if pushed_revid is None:622 if pushed_revid is None:
617 pushed_revid = 'modified'623 pushed_revid = self._default_pushed_revid
618 tree_to = workingtree.WorkingTree.open('to')624 tree_to = workingtree.WorkingTree.open('to')
619 repo_to = tree_to.branch.repository625 repo_to = tree_to.branch.repository
620 self.assertTrue(repo_to.has_revision(pushed_revid))626 self.assertTrue(repo_to.has_revision(pushed_revid))
@@ -622,7 +628,8 @@
622628
623629
624630
625class TestPushStrictWithoutChanges(TestPushStrict):631class TestPushStrictWithoutChanges(tests.TestCaseWithTransport,
632 TestPushStrictMixin):
626633
627 def setUp(self):634 def setUp(self):
628 super(TestPushStrictWithoutChanges, self).setUp()635 super(TestPushStrictWithoutChanges, self).setUp()
@@ -646,7 +653,8 @@
646 self.assertPushSucceeds([])653 self.assertPushSucceeds([])
647654
648655
649class TestPushStrictWithChanges(TestPushStrict):656class TestPushStrictWithChanges(tests.TestCaseWithTransport,
657 TestPushStrictMixin):
650658
651 _changes_type = None # Set by load_tests659 _changes_type = None # Set by load_tests
652660
@@ -671,6 +679,18 @@
671 self.tree.merge_from_branch(other_tree.branch)679 self.tree.merge_from_branch(other_tree.branch)
672 self.tree.revert(filenames=['other-file'], backups=False)680 self.tree.revert(filenames=['other-file'], backups=False)
673681
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"
691 " 'bzr update'\.",]
692 self._default_pushed_revid = 'modified-in-local'
693
674 def test_push_default(self):694 def test_push_default(self):
675 self.assertPushFails([])695 self.assertPushFails([])
676696