Merge lp:~vila/bzr/206577-send-strict into lp:~bzr/bzr/trunk-old

Proposed by Vincent Ladeuil
Status: Superseded
Proposed branch: lp:~vila/bzr/206577-send-strict
Merge into: lp:~bzr/bzr/trunk-old
Diff against target: 397 lines
To merge this branch: bzr merge lp:~vila/bzr/206577-send-strict

This proposal supersedes a proposal from 2009-06-29.

This proposal has been superseded by a proposal from 2009-07-01.

To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote : Posted in a previous version of this proposal

This fixes bug #206577 by introducing a --strict boolean option for 'send' and
'bundle-revisions' and aborting when uncommitted changes are found in the working tree.

As for bug #284038 (see https://code.edge.launchpad.net/~vila/bzr/284038-push-strict/+merge/8005),
I plan to introduce a way to query config files for a bool option and a new method on working tree
for checking changes, in a later submission.

Revision history for this message
Vincent Ladeuil (vila) wrote :

Hmm, resubmit doesn't allow me to type a comment so here is the cover letter.

This new submission takes into account the remarks made during
the reviews of bug #284038:
- the help and error messages have been updated,
- a new check has been added to ensure that the tree is not out of
  sync with its branch

I still plan to introduce a way to query config files for a bool option
and a new method on working tree for checking changes, in a later submission.

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

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vincent Ladeuil wrote:
> Vincent Ladeuil has proposed merging lp:~vila/bzr/206577-send-strict into lp:bzr.
>
> Hmm, resubmit doesn't allow me to type a comment so here is the cover letter.
>
> This new submission takes into account the remarks made during
> the reviews of bug #284038:
> - the help and error messages have been updated,
> - a new check has been added to ensure that the tree is not out of
> sync with its branch
>
> I still plan to introduce a way to query config files for a bool option
> and a new method on working tree for checking changes, in a later submission.
>
>
>

Unfortunately, there is still some lp:mad bits of showing your previous
(and now merged) patch. So I'm going to mark Resubmit and hope it gives
me the correct diff.

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpLXb4ACgkQJdeBCYSNAAODFwCgujso+F0Ns1DV4w2BKSUVKEl3
1dYAoJMVQiGL+DKCb3UrM5zyG68TfHKb
=0yxU
-----END PGP SIGNATURE-----

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2009-06-30 17:00:26 +0000
3+++ NEWS 2009-07-01 09:35:10 +0000
4@@ -30,6 +30,12 @@
5 show revision info for the working tree instead of the branch.
6 (Matthew Fuller, John Arbash Meinel)
7
8+* ``bzr send`` now aborts if uncommitted changes (including pending merges)
9+ are present in the working tree and no revision is specified. The
10+ configuration option ``send_strict`` can be used to set the default for this
11+ behavior.
12+ (Vincent Ladeuil, #206577)
13+
14
15 Bug Fixes
16 *********
17
18=== modified file 'bzrlib/builtins.py'
19--- bzrlib/builtins.py 2009-07-01 07:29:00 +0000
20+++ bzrlib/builtins.py 2009-07-01 09:35:10 +0000
21@@ -1080,7 +1080,7 @@
22 type=unicode),
23 Option('strict',
24 help='Refuse to push if there are uncommitted changes in'
25- ' the working tree.'),
26+ ' the working tree, --no-strict disables the check.'),
27 ]
28 takes_args = ['location?']
29 encoding_type = 'replace'
30@@ -4957,24 +4957,29 @@
31 help='Write merge directive to this file; '
32 'use - for stdout.',
33 type=unicode),
34+ Option('strict',
35+ help='Refuse to send if there are uncommitted changes in'
36+ ' the working tree, --no-strict disables the check.'),
37 Option('mail-to', help='Mail the request to this address.',
38 type=unicode),
39 'revision',
40 'message',
41 Option('body', help='Body for the email.', type=unicode),
42 RegistryOption('format',
43- help='Use the specified output format.',
44- lazy_registry=('bzrlib.send', 'format_registry'))
45+ help='Use the specified output format.',
46+ lazy_registry=('bzrlib.send', 'format_registry')),
47 ]
48
49 def run(self, submit_branch=None, public_branch=None, no_bundle=False,
50 no_patch=False, revision=None, remember=False, output=None,
51- format=None, mail_to=None, message=None, body=None, **kwargs):
52+ format=None, mail_to=None, message=None, body=None,
53+ strict=None, **kwargs):
54 from bzrlib.send import send
55 return send(submit_branch, revision, public_branch, remember,
56- format, no_bundle, no_patch, output,
57- kwargs.get('from', '.'), mail_to, message, body,
58- self.outf)
59+ format, no_bundle, no_patch, output,
60+ kwargs.get('from', '.'), mail_to, message, body,
61+ self.outf,
62+ strict=strict)
63
64
65 class cmd_bundle_revisions(cmd_send):
66@@ -5024,6 +5029,9 @@
67 type=unicode),
68 Option('output', short_name='o', help='Write directive to this file.',
69 type=unicode),
70+ Option('strict',
71+ help='Refuse to bundle revisions if there are uncommitted'
72+ ' changes in the working tree, --no-strict disables the check.'),
73 'revision',
74 RegistryOption('format',
75 help='Use the specified output format.',
76@@ -5037,14 +5045,14 @@
77
78 def run(self, submit_branch=None, public_branch=None, no_bundle=False,
79 no_patch=False, revision=None, remember=False, output=None,
80- format=None, **kwargs):
81+ format=None, strict=None, **kwargs):
82 if output is None:
83 output = '-'
84 from bzrlib.send import send
85 return send(submit_branch, revision, public_branch, remember,
86 format, no_bundle, no_patch, output,
87 kwargs.get('from', '.'), None, None, None,
88- self.outf)
89+ self.outf, strict=strict)
90
91
92 class cmd_tag(Command):
93
94=== modified file 'bzrlib/help_topics/en/configuration.txt'
95--- bzrlib/help_topics/en/configuration.txt 2009-06-10 13:18:48 +0000
96+++ bzrlib/help_topics/en/configuration.txt 2009-07-01 09:35:10 +0000
97@@ -421,3 +421,10 @@
98
99 If set to "True", the branch should act as a checkout, and push each commit to
100 the bound_location. This option is normally set by ``bind``/``unbind``.
101+
102+send_strict
103+~~~~~~~~~~~
104+
105+If present, defines the ``--strict`` option default value for checking
106+uncommitted changes before sending a merge directive.
107+
108
109=== modified file 'bzrlib/send.py'
110--- bzrlib/send.py 2009-05-28 16:14:16 +0000
111+++ bzrlib/send.py 2009-07-01 09:35:10 +0000
112@@ -37,8 +37,8 @@
113
114
115 def send(submit_branch, revision, public_branch, remember, format,
116- no_bundle, no_patch, output, from_, mail_to, message, body,
117- to_file):
118+ no_bundle, no_patch, output, from_, mail_to, message, body,
119+ to_file, strict=None):
120 tree, branch = bzrdir.BzrDir.open_containing_tree_or_branch(from_)[:2]
121 # we may need to write data into branch's repository to calculate
122 # the data to send.
123@@ -107,13 +107,35 @@
124 if len(revision) == 2:
125 base_revision_id = revision[0].as_revision_id(branch)
126 if revision_id is None:
127+ if strict is None:
128+ strict = branch.get_config().get_user_option('send_strict')
129+ if strict is not None:
130+ # FIXME: This should be better supported by config
131+ # -- vila 20090626
132+ bools = dict(yes=True, no=False, on=True, off=False,
133+ true=True, false=False)
134+ try:
135+ strict = bools[strict.lower()]
136+ except KeyError:
137+ strict = None
138+ if tree is not None and (strict is None or strict):
139+ changes = tree.changes_from(tree.basis_tree())
140+ if changes.has_changed() or len(tree.get_parent_ids()) > 1:
141+ raise errors.UncommittedChanges(
142+ tree, more='Use --no-strict to force the push.')
143+ if tree.last_revision() != tree.branch.last_revision():
144+ # The tree has lost sync with its branch, there is little
145+ # chance that the user is aware of it but he can still force
146+ # the push with --no-strict
147+ raise errors.OutOfDateTree(
148+ tree, more='Use --no-strict to force the push.')
149 revision_id = branch.last_revision()
150 if revision_id == NULL_REVISION:
151 raise errors.BzrCommandError('No revisions to submit.')
152 if format is None:
153 # TODO: Query submit branch for its preferred format
154 format = format_registry.get()
155- directive = format(branch, revision_id, submit_branch,
156+ directive = format(branch, revision_id, submit_branch,
157 public_branch, no_patch, no_bundle, message, base_revision_id)
158 if output is None:
159 directive.compose_merge_request(mail_client, mail_to, body,
160
161=== modified file 'bzrlib/tests/blackbox/test_send.py'
162--- bzrlib/tests/blackbox/test_send.py 2009-06-26 08:20:13 +0000
163+++ bzrlib/tests/blackbox/test_send.py 2009-07-01 09:35:10 +0000
164@@ -28,12 +28,54 @@
165 from bzrlib.bundle import serializer
166
167
168-def read_bundle(fileobj):
169- md = merge_directive.MergeDirective.from_lines(fileobj.readlines())
170- return serializer.read_bundle(StringIO(md.get_raw_bundle()))
171-
172-
173-class TestSend(tests.TestCaseWithTransport):
174+def load_tests(standard_tests, module, loader):
175+ """Multiply tests for the send command."""
176+ result = loader.suiteClass()
177+
178+ # one for each king of change
179+ changes_tests, remaining_tests = tests.split_suite_by_condition(
180+ standard_tests, tests.condition_isinstance((
181+ TestSendStrictWithChanges,
182+ )))
183+ changes_scenarios = [
184+ ('uncommitted',
185+ dict(_changes_type= '_uncommitted_changes')),
186+ ('pending_merges',
187+ dict(_changes_type= '_pending_merges')),
188+ ('out-of-sync-trees',
189+ dict(_changes_type= '_out_of_sync_trees')),
190+ ]
191+ tests.multiply_tests(changes_tests, changes_scenarios, result)
192+ # No parametrization for the remaining tests
193+ result.addTests(remaining_tests)
194+
195+ return result
196+
197+
198+class TestSendMixin(object):
199+
200+ _default_command = ['send', '-o-']
201+ _default_wd = 'branch'
202+
203+ def run_send(self, args, cmd=None, rc=0, wd=None, err_re=None):
204+ if cmd is None: cmd = self._default_command
205+ if wd is None: wd = self._default_wd
206+ if err_re is None: err_re = []
207+ return self.run_bzr(cmd + args, retcode=rc,
208+ working_dir=wd,
209+ error_regexes=err_re)
210+
211+ def get_MD(self, args, cmd=None, wd='branch'):
212+ out = StringIO(self.run_send(args, cmd=cmd, wd=wd)[0])
213+ return merge_directive.MergeDirective.from_lines(out.readlines())
214+
215+ def assertBundleContains(self, revs, args, cmd=None, wd='branch'):
216+ md = self.get_MD(args, cmd=cmd, wd=wd)
217+ br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
218+ self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
219+
220+
221+class TestSend(tests.TestCaseWithTransport, TestSendMixin):
222
223 def setUp(self):
224 super(TestSend, self).setUp()
225@@ -51,24 +93,6 @@
226 self.build_tree_contents([('branch/file1', 'branch')])
227 branch_tree.commit('last commit', rev_id='rev3')
228
229- def run_send(self, args, cmd=None, rc=0, wd='branch'):
230- if cmd is None:
231- cmd = ['send', '-o-']
232- return self.run_bzr(cmd + args, retcode=rc, working_dir=wd)
233-
234- def get_MD(self, args, cmd=None, wd='branch'):
235- out = StringIO(self.run_send(args, cmd=cmd, wd=wd)[0])
236- return merge_directive.MergeDirective.from_lines(out.readlines())
237-
238- def get_bundle(self, args, cmd=None, wd='branch'):
239- md = self.get_MD(args, cmd=cmd, wd=wd)
240- return serializer.read_bundle(StringIO(md.get_raw_bundle()))
241-
242- def assertBundleContains(self, revs, args, cmd=None, wd='branch'):
243- out = self.run_send(args, cmd=cmd, wd=wd)[0]
244- br = read_bundle(StringIO(out))
245- self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
246-
247 def assertFormatIs(self, fmt_string, md):
248 self.assertEqual(fmt_string, md.get_raw_bundle().splitlines()[0])
249
250@@ -263,3 +287,147 @@
251 out, err = self.run_bzr(["send", "--from", location], retcode=3)
252 self.assertEqual(out, '')
253 self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
254+
255+
256+class TestSendStrictMixin(TestSendMixin):
257+
258+ def make_parent_and_local_branches(self):
259+ # Create a 'parent' branch as the base
260+ self.parent_tree = bzrdir.BzrDir.create_standalone_workingtree('parent')
261+ self.build_tree_contents([('parent/file', 'parent')])
262+ self.parent_tree.add('file')
263+ self.parent_tree.commit('first commit', rev_id='parent')
264+ # Branch 'local' from parent and do a change
265+ local_bzrdir = self.parent_tree.bzrdir.sprout('local')
266+ self.local_tree = local_bzrdir.open_workingtree()
267+ self.build_tree_contents([('local/file', 'local')])
268+ self.local_tree.commit('second commit', rev_id='local')
269+
270+ _default_command = ['send', '-o-', '../parent']
271+ _default_wd = 'local'
272+ _default_sent_revs = ['local']
273+ _default_errors = ['Working tree ".*/local/" has uncommitted '
274+ 'changes \(See bzr status\)\.',]
275+
276+ def set_config_send_strict(self, value):
277+ # set config var (any of bazaar.conf, locations.conf, branch.conf
278+ # should do)
279+ conf = self.local_tree.branch.get_config()
280+ conf.set_user_option('send_strict', value)
281+
282+ def assertSendFails(self, args):
283+ self.run_send(args, rc=3, err_re=self._default_errors)
284+
285+ def assertSendSucceeds(self, args, revs=None):
286+ if revs is None:
287+ revs = self._default_sent_revs
288+ out, err = self.run_send(args)
289+ self.assertEquals(
290+ 'Bundling %d revision(s).\n' % len(revs), err)
291+ md = merge_directive.MergeDirective.from_lines(
292+ StringIO(out).readlines())
293+ self.assertEqual('parent', md.base_revision_id)
294+ br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
295+ self.assertEqual(set(revs), set(r.revision_id for r in br.revisions))
296+
297+
298+class TestSendStrictWithoutChanges(tests.TestCaseWithTransport,
299+ TestSendStrictMixin):
300+
301+ def setUp(self):
302+ super(TestSendStrictWithoutChanges, self).setUp()
303+ self.make_parent_and_local_branches()
304+
305+ def test_send_default(self):
306+ self.assertSendSucceeds([])
307+
308+ def test_send_strict(self):
309+ self.assertSendSucceeds(['--strict'])
310+
311+ def test_send_no_strict(self):
312+ self.assertSendSucceeds(['--no-strict'])
313+
314+ def test_send_config_var_strict(self):
315+ self.set_config_send_strict('true')
316+ self.assertSendSucceeds([])
317+
318+ def test_send_config_var_no_strict(self):
319+ self.set_config_send_strict('false')
320+ self.assertSendSucceeds([])
321+
322+
323+class TestSendStrictWithChanges(tests.TestCaseWithTransport,
324+ TestSendStrictMixin):
325+
326+ _changes_type = None # Set by load_tests
327+
328+ def setUp(self):
329+ super(TestSendStrictWithChanges, self).setUp()
330+ getattr(self, self._changes_type)()
331+
332+ def _uncommitted_changes(self):
333+ self.make_parent_and_local_branches()
334+ # Make a change without committing it
335+ self.build_tree_contents([('local/file', 'modified')])
336+
337+ def _pending_merges(self):
338+ self.make_parent_and_local_branches()
339+ # Create 'other' branch containing a new file
340+ other_bzrdir = self.parent_tree.bzrdir.sprout('other')
341+ other_tree = other_bzrdir.open_workingtree()
342+ self.build_tree_contents([('other/other-file', 'other')])
343+ other_tree.add('other-file')
344+ other_tree.commit('other commit', rev_id='other')
345+ # Merge and revert, leaving a pending merge
346+ self.local_tree.merge_from_branch(other_tree.branch)
347+ self.local_tree.revert(filenames=['other-file'], backups=False)
348+
349+ def _out_of_sync_trees(self):
350+ self.make_parent_and_local_branches()
351+ self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
352+ # Make a change and commit it
353+ self.build_tree_contents([('local/file', 'modified in local')])
354+ self.local_tree.commit('modify file', rev_id='modified-in-local')
355+ # Exercise commands from the checkout directory
356+ self._default_wd = 'checkout'
357+ self._default_errors = ["Working tree is out of date, please run"
358+ " 'bzr update'\.",]
359+ self._default_sent_revs = ['modified-in-local', 'local']
360+
361+ def test_send_default(self):
362+ self.assertSendFails([])
363+
364+ def test_send_with_revision(self):
365+ self.assertSendSucceeds(['-r', 'revid:local'], revs=['local'])
366+
367+ def test_send_no_strict(self):
368+ self.assertSendSucceeds(['--no-strict'])
369+
370+ def test_send_strict_with_changes(self):
371+ self.assertSendFails(['--strict'])
372+
373+ def test_send_respect_config_var_strict(self):
374+ self.set_config_send_strict('true')
375+ self.assertSendFails([])
376+ self.assertSendSucceeds(['--no-strict'])
377+
378+
379+ def test_send_bogus_config_var_ignored(self):
380+ self.set_config_send_strict("I'm unsure")
381+ self.assertSendFails([])
382+
383+
384+ def test_send_no_strict_command_line_override_config(self):
385+ self.set_config_send_strict('true')
386+ self.assertSendFails([])
387+ self.assertSendSucceeds(['--no-strict'])
388+
389+ def test_push_strict_command_line_override_config(self):
390+ self.set_config_send_strict('false')
391+ self.assertSendSucceeds([])
392+ self.assertSendFails(['--strict'])
393+
394+
395+class TestBundleStrictWithoutChanges(TestSendStrictWithoutChanges):
396+
397+ _default_command = ['bundle-revisions', '../parent']