Rev 4453: (vila) Add a --strict option to push in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Jun 17 10:07:39 BST 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4453
revision-id: pqm at pqm.ubuntu.com-20090617090735-796uiadbn7zulvlu
parent: pqm at pqm.ubuntu.com-20090617055321-5t6v2ugwdrjvnrgv
parent: v.ladeuil+lp at free.fr-20090617080836-vzh5a51wbf2l3lgc
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2009-06-17 10:07:35 +0100
message:
(vila) Add a --strict option to push
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/config.py config.py-20051011043216-070c74f4e9e338e8
bzrlib/help_topics/en/configuration.txt configuration.txt-20060314161707-868350809502af01
bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
bzrlib/tests/branch_implementations/test_push.py test_push.py-20070130153159-fhfap8uoifevg30j-1
------------------------------------------------------------
revno: 4452.1.1
revision-id: v.ladeuil+lp at free.fr-20090617080836-vzh5a51wbf2l3lgc
parent: pqm at pqm.ubuntu.com-20090617055321-5t6v2ugwdrjvnrgv
parent: v.ladeuil+lp at free.fr-20090611073405-t9rypu9b1d0r0zcx
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: integration
timestamp: Wed 2009-06-17 10:08:36 +0200
message:
Add a --strict option to push
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/config.py config.py-20051011043216-070c74f4e9e338e8
bzrlib/help_topics/en/configuration.txt configuration.txt-20060314161707-868350809502af01
bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
bzrlib/tests/branch_implementations/test_push.py test_push.py-20070130153159-fhfap8uoifevg30j-1
------------------------------------------------------------
revno: 4420.1.6
revision-id: v.ladeuil+lp at free.fr-20090611073405-t9rypu9b1d0r0zcx
parent: v.ladeuil+lp at free.fr-20090611064921-on9wxymrzgkxi2a0
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 284038-push-strict
timestamp: Thu 2009-06-11 09:34:05 +0200
message:
Fixed as per John's review feedback.
* bzrlib/tests/blackbox/test_push.py:
(TestPushStrict): Add more tests and use various values for the
push_strcit config variable.
* bzrlib/builtins.py:
(cmd_push.run): Not all values are valid for the push_strict
config variable.
modified:
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
------------------------------------------------------------
revno: 4420.1.5
revision-id: v.ladeuil+lp at free.fr-20090611064921-on9wxymrzgkxi2a0
parent: v.ladeuil+lp at free.fr-20090610132352-9b5dlk3kbz62gm3p
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 284038-push-strict
timestamp: Thu 2009-06-11 08:49:21 +0200
message:
Start implementing jam's review feedback.
* bzrlib/tests/blackbox/test_push.py:
(TestPushStrict): Refactor and some tests.
* bzrlib/config.py:
(TreeConfig.get_option): Delete dead code.
modified:
bzrlib/config.py config.py-20051011043216-070c74f4e9e338e8
bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
------------------------------------------------------------
revno: 4420.1.4
revision-id: v.ladeuil+lp at free.fr-20090610132352-9b5dlk3kbz62gm3p
parent: v.ladeuil+lp at free.fr-20090610131848-wd4l83stob7jjsv9
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 284038-push-strict
timestamp: Wed 2009-06-10 15:23:52 +0200
message:
Cleanup.
* tests/branch_implementations/test_push.py:
(EmptyPushSmartEffortTests.test_empty_branch_command): Remove
spurious change.
modified:
bzrlib/tests/branch_implementations/test_push.py test_push.py-20070130153159-fhfap8uoifevg30j-1
------------------------------------------------------------
revno: 4420.1.3
revision-id: v.ladeuil+lp at free.fr-20090610131848-wd4l83stob7jjsv9
parent: v.ladeuil+lp at free.fr-20090610123851-ftix8vy3p054jlwn
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 284038-push-strict
timestamp: Wed 2009-06-10 15:18:48 +0200
message:
Add NEWS entry and update doc.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/help_topics/en/configuration.txt configuration.txt-20060314161707-868350809502af01
------------------------------------------------------------
revno: 4420.1.2
revision-id: v.ladeuil+lp at free.fr-20090610123851-ftix8vy3p054jlwn
parent: v.ladeuil+lp at free.fr-20090609142925-yj0o8c3vam9b5ogn
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 284038-push-strict
timestamp: Wed 2009-06-10 14:38:51 +0200
message:
Fix bug #284038 by adding a --strict option to push.
* tests/branch_implementations/test_push.py:
(EmptyPushSmartEffortTests.test_empty_branch_command): Fix
semi-unrelated get_url() misuse.
* tests/blackbox/test_push.py:
(TestPushRedirect.test_push_gracefully_handles_too_many_redirects):
Test push command behavior with respect to uncommitted changes and
--strict option.
* builtins.py:
(cmd_push): Add a '--strict' option to check uncommitted changes.
modified:
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
bzrlib/tests/branch_implementations/test_push.py test_push.py-20070130153159-fhfap8uoifevg30j-1
=== modified file 'NEWS'
--- a/NEWS 2009-06-17 02:02:44 +0000
+++ b/NEWS 2009-06-17 08:08:36 +0000
@@ -9,6 +9,14 @@
In Development
##############
+New Features
+************
+
+* ``bzr push`` now checks if uncommitted changes are present in the working
+ tree if the ``--strict`` option is used.
+ (Vincent Ladeuil, #284038)
+
+
Bug Fixes
*********
@@ -105,7 +113,6 @@
* mail_client=claws now supports --body (and message body hooks). Also uses
configured from address. (Barry Warsaw)
-
Improvements
************
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2009-06-17 02:02:44 +0000
+++ b/bzrlib/builtins.py 2009-06-17 08:08:36 +0000
@@ -1028,6 +1028,9 @@
'for the commit history. Only the work not present in the '
'referenced branch is included in the branch created.',
type=unicode),
+ Option('strict',
+ help='Refuse to push if there are uncommitted changes in'
+ ' the working tree.'),
]
takes_args = ['location?']
encoding_type = 'replace'
@@ -1035,13 +1038,29 @@
def run(self, location=None, remember=False, overwrite=False,
create_prefix=False, verbose=False, revision=None,
use_existing_dir=False, directory=None, stacked_on=None,
- stacked=False):
+ stacked=False, strict=None):
from bzrlib.push import _show_push_branch
- # Get the source branch and revision_id
if directory is None:
directory = '.'
- br_from = Branch.open_containing(directory)[0]
+ # Get the source branch
+ tree, br_from = bzrdir.BzrDir.open_tree_or_branch(directory)
+ if strict is None:
+ strict = br_from.get_config().get_user_option('push_strict')
+ if strict is not None:
+ # FIXME: This should be better supported by config
+ # -- vila 20090611
+ bools = dict(yes=True, no=False, on=True, off=False,
+ true=True, false=False)
+ try:
+ strict = bools[strict.lower()]
+ except KeyError:
+ strict = None
+ if strict:
+ changes = tree.changes_from(tree.basis_tree())
+ if changes.has_changed():
+ raise errors.UncommittedChanges(tree)
+ # Get the tip's revision_id
revision = _get_one_revision('push', revision)
if revision is not None:
revision_id = revision.in_history(br_from).rev_id
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2009-04-27 16:10:10 +0000
+++ b/bzrlib/config.py 2009-06-11 06:49:21 +0000
@@ -930,7 +930,6 @@
return self._config.get_option(name, section, default)
finally:
self.branch.unlock()
- return result
def set_option(self, value, name, section=None):
"""Set a per-branch configuration option"""
=== modified file 'bzrlib/help_topics/en/configuration.txt'
--- a/bzrlib/help_topics/en/configuration.txt 2009-03-06 05:51:20 +0000
+++ b/bzrlib/help_topics/en/configuration.txt 2009-06-10 13:18:48 +0000
@@ -404,6 +404,12 @@
If present, the location of the default branch for push. This option
is normally set by ``push --remember``.
+push_strict
+~~~~~~~~~~~
+
+If present, defines the ``--strict`` option default value for checking
+uncommitted changes before pushing.
+
bound_location
~~~~~~~~~~~~~~
=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py 2009-06-15 15:20:24 +0000
+++ b/bzrlib/tests/blackbox/test_push.py 2009-06-17 08:08:36 +0000
@@ -555,3 +555,77 @@
% re.escape(destination_url)],
['push', '-d', 'tree', destination_url], retcode=3)
self.assertEqual('', out)
+
+
+class TestPushStrict(tests.TestCaseWithTransport):
+
+ def make_local_branch_and_tree(self):
+ tree = self.make_branch_and_tree('local')
+ self.build_tree_contents([('local/file', 'initial')])
+ tree.add('file')
+ tree.commit('adding file', rev_id='from-1')
+ return tree
+
+ def make_local_branch_and_tree_with_changes(self):
+ tree = self.make_local_branch_and_tree()
+ # Make some changes
+ self.build_tree_contents([('local/file', 'modified')])
+ return tree
+
+ def set_config_push_strict(self, tree, value):
+ # set config var (any of bazaar.conf, locations.conf, branch.conf
+ # should do)
+ conf = tree.branch.get_config()
+ conf.set_user_option('push_strict', value)
+
+ def assertPushFails(self, location, *args):
+ self.run_bzr_error(['Working tree ".*/local/"'
+ ' has uncommitted changes.$',],
+ ['push', '../' + location] + list(args),
+ working_dir='local', retcode=3)
+
+ def assertPushSucceeds(self, location, *args):
+ self.run_bzr(['push', '../' + location] + list(args),
+ working_dir='local')
+ tree_to = workingtree.WorkingTree.open(location)
+ repo_to = tree_to.branch.repository
+ self.assertTrue(repo_to.has_revision('from-1'))
+ self.assertEqual(tree_to.branch.last_revision_info()[1], 'from-1')
+
+ def test_push_default(self):
+ tree = self.make_local_branch_and_tree_with_changes()
+ self.assertPushSucceeds('to')
+
+ def test_push_no_strict_with_changes(self):
+ tree = self.make_local_branch_and_tree_with_changes()
+ self.assertPushSucceeds('to', '--no-strict')
+
+ def test_push_strict_with_changes(self):
+ tree = self.make_local_branch_and_tree_with_changes()
+ self.assertPushFails('to', '--strict')
+
+ def test_push_strict_without_changes(self):
+ tree = self.make_local_branch_and_tree()
+ self.assertPushSucceeds('to', '--strict')
+
+ def test_push_respect_config_var_strict(self):
+ tree = self.make_local_branch_and_tree_with_changes()
+ self.set_config_push_strict(tree, 'true')
+ self.assertPushFails('to')
+
+ def test_push_bogus_config_var_ignored(self):
+ tree = self.make_local_branch_and_tree_with_changes()
+ self.set_config_push_strict(tree, "I don't want you to be strict")
+ self.assertPushSucceeds('to')
+
+ def test_push_no_strict_command_line_override_config(self):
+ tree = self.make_local_branch_and_tree_with_changes()
+ self.set_config_push_strict(tree, 'yES')
+ self.assertPushFails('to')
+ self.assertPushSucceeds('to', '--no-strict')
+
+ def test_push_strict_command_line_override_config(self):
+ tree = self.make_local_branch_and_tree_with_changes()
+ self.set_config_push_strict(tree, 'oFF')
+ self.assertPushFails('to', '--strict')
+ self.assertPushSucceeds('to')
=== modified file 'bzrlib/tests/branch_implementations/test_push.py'
--- a/bzrlib/tests/branch_implementations/test_push.py 2009-06-10 03:56:49 +0000
+++ b/bzrlib/tests/branch_implementations/test_push.py 2009-06-17 08:08:36 +0000
@@ -427,7 +427,7 @@
cmd = builtins.cmd_push()
cmd.outf = tests.StringIOWrapper()
cmd.run(
- directory=self.get_url() + 'empty',
+ directory=self.get_url('empty'),
location=self.smart_server.get_url() + 'target')
# HPSS calls as of 2008/09/22:
# [BzrDir.open, BzrDir.open_branch, BzrDir.find_repositoryV2,
More information about the bazaar-commits
mailing list