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

Proposed by Vincent Ladeuil on 2009-06-30
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 2009-06-30 Approve on 2009-06-30
bzr-core 2009-06-30 Pending
Review via email: mp+8056@code.launchpad.net
To post a comment you must log in.
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.

John A Meinel (jameinel) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/builtins.py'
2--- bzrlib/builtins.py 2009-06-30 17:00:26 +0000
3+++ bzrlib/builtins.py 2009-06-30 20:35:19 +0000
4@@ -1117,7 +1117,14 @@
5 and (strict is None or strict)): # Default to True:
6 changes = tree.changes_from(tree.basis_tree())
7 if changes.has_changed() or len(tree.get_parent_ids()) > 1:
8- raise errors.UncommittedChanges(tree)
9+ raise errors.UncommittedChanges(
10+ tree, more='Use --no-strict to force the push.')
11+ if tree.last_revision() != tree.branch.last_revision():
12+ # The tree has lost sync with its branch, there is little
13+ # chance that the user is aware of it but he can still force
14+ # the push with --no-strict
15+ raise errors.OutOfDateTree(
16+ tree, more='Use --no-strict to force the push.')
17
18 # Get the stacked_on branch, if any
19 if stacked_on is not None:
20
21=== modified file 'bzrlib/errors.py'
22--- bzrlib/errors.py 2009-06-30 08:06:35 +0000
23+++ bzrlib/errors.py 2009-06-30 20:35:19 +0000
24@@ -2093,11 +2093,16 @@
25
26 class OutOfDateTree(BzrError):
27
28- _fmt = "Working tree is out of date, please run 'bzr update'."
29+ _fmt = "Working tree is out of date, please run 'bzr update'.%(more)s"
30
31- def __init__(self, tree):
32+ def __init__(self, tree, more=None):
33+ if more is None:
34+ more = ''
35+ else:
36+ more = ' ' + more
37 BzrError.__init__(self)
38 self.tree = tree
39+ self.more = more
40
41
42 class PublicBranchOutOfDate(BzrError):
43@@ -2779,13 +2784,17 @@
44 class UncommittedChanges(BzrError):
45
46 _fmt = ('Working tree "%(display_url)s" has uncommitted changes'
47- ' (See bzr status).')
48+ ' (See bzr status).%(more)s')
49
50- def __init__(self, tree):
51+ def __init__(self, tree, more=None):
52+ if more is None:
53+ more = ''
54+ else:
55+ more = ' ' + more
56 import bzrlib.urlutils as urlutils
57 display_url = urlutils.unescape_for_display(
58 tree.bzrdir.root_transport.base, 'ascii')
59- BzrError.__init__(self, tree=tree, display_url=display_url)
60+ BzrError.__init__(self, tree=tree, display_url=display_url, more=more)
61
62
63 class MissingTemplateVariable(BzrError):
64
65=== modified file 'bzrlib/tests/blackbox/test_push.py'
66--- bzrlib/tests/blackbox/test_push.py 2009-06-30 09:19:06 +0000
67+++ bzrlib/tests/blackbox/test_push.py 2009-06-30 20:35:19 +0000
68@@ -47,8 +47,10 @@
69 changes_scenarios = [
70 ('uncommitted',
71 dict(_changes_type= '_uncommitted_changes')),
72- ('pending_merges',
73+ ('pending-merges',
74 dict(_changes_type= '_pending_merges')),
75+ ('out-of-sync-trees',
76+ dict(_changes_type= '_out_of_sync_trees')),
77 ]
78 tests.multiply_tests(changes_tests, changes_scenarios, result)
79 # No parametrization for the remaining tests
80@@ -588,7 +590,7 @@
81 self.assertEqual('', out)
82
83
84-class TestPushStrict(tests.TestCaseWithTransport):
85+class TestPushStrictMixin(object):
86
87 def make_local_branch_and_tree(self):
88 self.tree = self.make_branch_and_tree('local')
89@@ -604,17 +606,21 @@
90 conf = self.tree.branch.get_config()
91 conf.set_user_option('push_strict', value)
92
93+ _default_command = ['push', '../to']
94+ _default_wd = 'local'
95+ _default_errors = ['Working tree ".*/local/" has uncommitted '
96+ 'changes \(See bzr status\)\.',]
97+ _default_pushed_revid = 'modified'
98+
99 def assertPushFails(self, args):
100- self.run_bzr_error(['Working tree ".*/local/"'
101- ' has uncommitted changes \(See bzr status\)\.',],
102- ['push', '../to'] + args,
103- working_dir='local', retcode=3)
104+ self.run_bzr_error(self._default_errors, self._default_command + args,
105+ working_dir=self._default_wd, retcode=3)
106
107 def assertPushSucceeds(self, args, pushed_revid=None):
108- self.run_bzr(['push', '../to'] + args,
109- working_dir='local')
110+ self.run_bzr(self._default_command + args,
111+ working_dir=self._default_wd)
112 if pushed_revid is None:
113- pushed_revid = 'modified'
114+ pushed_revid = self._default_pushed_revid
115 tree_to = workingtree.WorkingTree.open('to')
116 repo_to = tree_to.branch.repository
117 self.assertTrue(repo_to.has_revision(pushed_revid))
118@@ -622,7 +628,8 @@
119
120
121
122-class TestPushStrictWithoutChanges(TestPushStrict):
123+class TestPushStrictWithoutChanges(tests.TestCaseWithTransport,
124+ TestPushStrictMixin):
125
126 def setUp(self):
127 super(TestPushStrictWithoutChanges, self).setUp()
128@@ -646,7 +653,8 @@
129 self.assertPushSucceeds([])
130
131
132-class TestPushStrictWithChanges(TestPushStrict):
133+class TestPushStrictWithChanges(tests.TestCaseWithTransport,
134+ TestPushStrictMixin):
135
136 _changes_type = None # Set by load_tests
137
138@@ -671,6 +679,18 @@
139 self.tree.merge_from_branch(other_tree.branch)
140 self.tree.revert(filenames=['other-file'], backups=False)
141
142+ def _out_of_sync_trees(self):
143+ self.make_local_branch_and_tree()
144+ self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
145+ # Make a change and commit it
146+ self.build_tree_contents([('local/file', 'modified in local')])
147+ self.tree.commit('modify file', rev_id='modified-in-local')
148+ # Exercise commands from the checkout directory
149+ self._default_wd = 'checkout'
150+ self._default_errors = ["Working tree is out of date, please run"
151+ " 'bzr update'\.",]
152+ self._default_pushed_revid = 'modified-in-local'
153+
154 def test_push_default(self):
155 self.assertPushFails([])
156