Rev 4422: Fix bug #284038 by adding a --strict option to push. in file:///home/vila/src/bzr/bugs/284038-push-strict/

Vincent Ladeuil v.ladeuil+lp at free.fr
Wed Jun 10 13:38:51 BST 2009


At file:///home/vila/src/bzr/bugs/284038-push-strict/

------------------------------------------------------------
revno: 4422
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.
-------------- next part --------------
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2009-06-02 09:18:26 +0000
+++ b/bzrlib/builtins.py	2009-06-10 12:38:51 +0000
@@ -1021,6 +1021,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'
@@ -1028,13 +1031,20 @@
     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:
+            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/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py	2009-06-09 14:29:25 +0000
+++ b/bzrlib/tests/blackbox/test_push.py	2009-06-10 12:38:51 +0000
@@ -530,3 +530,68 @@
              % 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 assertTreePushed(self, relpath):
+        tree_to = workingtree.WorkingTree.open(relpath)
+        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()
+        # Make some changes
+        self.build_tree_contents([('local/file', 'modified')])
+        # Push with some uncommitted changes works
+        self.run_bzr(['push', '../to'], working_dir='local')
+        self.assertTreePushed('to')
+
+    def test_push_strict_with_changes(self):
+        tree = self.make_local_branch_and_tree()
+        # Make some changes
+        self.build_tree_contents([('local/file', 'modified')])
+        # Push with some uncommitted changes fails
+        self.run_bzr_error(['Working tree ".*/local/"'
+                            ' has uncommitted changes.$',],
+                           ['push', '--strict', '../to'],
+                           working_dir='local', retcode=3)
+
+    def test_push_strict_without_changes(self):
+        tree = self.make_local_branch_and_tree()
+        self.run_bzr(['push', '--strict', '../to'], working_dir='local')
+        self.assertTreePushed('to')
+
+    def test_push_respect_config_var(self):
+        tree = self.make_local_branch_and_tree()
+        # Make some changes
+        self.build_tree_contents([('local/file', 'modified')])
+        # set config var (any of bazaar.conf, locations.conf, branch.conf
+        # should do)
+        conf = tree.branch.get_config()
+        conf.set_user_option('push_strict', 'true')
+        # Push --strict (inherited from config) with some uncommitted changes
+        # fails
+        self.run_bzr_error(['Working tree ".*/local/"'
+                            ' has uncommitted changes.$',],
+                           ['push', '../to'],
+                           working_dir='local', retcode=3)
+
+    def test_push_command_line_override_config(self):
+        tree = self.make_local_branch_and_tree()
+        # Make some changes
+        self.build_tree_contents([('local/file', 'modified')])
+        # set config var (any of bazaar.conf, locations.conf, branch.conf
+        # should do)
+        conf = tree.branch.get_config()
+        conf.set_user_option('push_strict', 'true')
+        self.run_bzr(['push', '--no-strict', '../to'], working_dir='local')
+        self.assertTreePushed('to')

=== modified file 'bzrlib/tests/branch_implementations/test_push.py'
--- a/bzrlib/tests/branch_implementations/test_push.py	2009-05-23 04:55:52 +0000
+++ b/bzrlib/tests/branch_implementations/test_push.py	2009-06-10 12:38:51 +0000
@@ -427,8 +427,8 @@
         cmd = builtins.cmd_push()
         cmd.outf = tests.StringIOWrapper()
         cmd.run(
-            directory=self.get_url() + 'empty',
-            location=self.smart_server.get_url() + 'target')
+            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,
         # Branch.get_stacked_on_url, get, get, Branch.lock_write,



More information about the bazaar-commits mailing list