Rev 4475: Add a check for tree/branch sync and tweak help. in file:///home/vila/src/bzr/bugs/206577-send-strict/

Vincent Ladeuil v.ladeuil+lp at free.fr
Wed Jul 1 08:20:36 BST 2009


At file:///home/vila/src/bzr/bugs/206577-send-strict/

------------------------------------------------------------
revno: 4475
revision-id: v.ladeuil+lp at free.fr-20090701072036-z0v9p3wk5hwsu480
parent: v.ladeuil+lp at free.fr-20090630123722-i45tp7meu0320sb8
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 206577-send-strict
timestamp: Wed 2009-07-01 09:20:36 +0200
message:
  Add a check for tree/branch sync and tweak help.
  
  * bzrlib/tests/blackbox/test_send.py:
  (load_tests): One more changes type.
  (TestSendStrictMixin): More default values.
  (TestSendStrictMixin.assertSendFails,
  TestSendStrictMixin.assertSendSucceeds): More default values used.
  (TestSendStrictWithChanges._out_of_sync_trees): Setup a new
  context and change the default values.
  
  * bzrlib/send.py:
  (send): Add an additional check that the tree is still in sync
  with its branch before sending.
  
  * bzrlib/builtins.py:
  (cmd_push, cmd_send, cmd_bundle_revisions): Mention --no-strict in
  the option help so users get an hint.
-------------- next part --------------
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2009-06-30 12:35:25 +0000
+++ b/bzrlib/builtins.py	2009-07-01 07:20:36 +0000
@@ -1030,7 +1030,7 @@
             type=unicode),
         Option('strict',
                help='Refuse to push if there are uncommitted changes in'
-               ' the working tree.'),
+               ' the working tree, --no-strict disables the check.'),
         ]
     takes_args = ['location?']
     encoding_type = 'replace'
@@ -4902,7 +4902,7 @@
                type=unicode),
         Option('strict',
                help='Refuse to send if there are uncommitted changes in'
-               ' the working tree.'),
+               ' the working tree, --no-strict disables the check.'),
         Option('mail-to', help='Mail the request to this address.',
                type=unicode),
         'revision',
@@ -4973,8 +4973,8 @@
         Option('output', short_name='o', help='Write directive to this file.',
                type=unicode),
         Option('strict',
-               help='Refuse to bundle revisions if there are'
-               ' uncommitted changes in the working tree.'),
+               help='Refuse to bundle revisions if there are uncommitted'
+               ' changes in the working tree, --no-strict disables the check.'),
         'revision',
         RegistryOption('format',
                        help='Use the specified output format.',

=== modified file 'bzrlib/send.py'
--- a/bzrlib/send.py	2009-06-26 18:13:41 +0000
+++ b/bzrlib/send.py	2009-07-01 07:20:36 +0000
@@ -118,17 +118,23 @@
                         strict = bools[strict.lower()]
                     except KeyError:
                         strict = None
-            if strict is None or strict: # Default to True
+            if tree is not None and (strict is None or strict):
                 changes = tree.changes_from(tree.basis_tree())
                 if changes.has_changed() or len(tree.get_parent_ids()) > 1:
                     raise errors.UncommittedChanges(tree)
+                if tree.last_revision() != tree.branch.last_revision():
+                    # The tree has lost sync with its branch, there is little
+                    # chance that the user is aware of it but he can still force
+                    # the push with --no-strict
+                    raise errors.OutOfDateTree(tree)
+#                        tree, more='Use --no-strict to force the push.',)
             revision_id = branch.last_revision()
         if revision_id == NULL_REVISION:
             raise errors.BzrCommandError('No revisions to submit.')
         if format is None:
             # TODO: Query submit branch for its preferred format
             format = format_registry.get()
-        directive = format(branch, revision_id, submit_branch, 
+        directive = format(branch, revision_id, submit_branch,
             public_branch, no_patch, no_bundle, message, base_revision_id)
         if output is None:
             directive.compose_merge_request(mail_client, mail_to, body,

=== modified file 'bzrlib/tests/blackbox/test_send.py'
--- a/bzrlib/tests/blackbox/test_send.py	2009-06-30 12:37:22 +0000
+++ b/bzrlib/tests/blackbox/test_send.py	2009-07-01 07:20:36 +0000
@@ -42,6 +42,8 @@
          dict(_changes_type= '_uncommitted_changes')),
         ('pending_merges',
          dict(_changes_type= '_pending_merges')),
+        ('out-of-sync-trees',
+         dict(_changes_type= '_out_of_sync_trees')),
         ]
     tests.multiply_tests(changes_tests, changes_scenarios, result)
     # No parametrization for the remaining tests
@@ -289,9 +291,6 @@
 
 class TestSendStrictMixin(TestSendMixin):
 
-    _default_command = ['send', '-o-', '../parent']
-    _default_wd = 'local'
-
     def make_parent_and_local_branches(self):
         # Create a 'parent' branch as the base
         self.parent_tree = bzrdir.BzrDir.create_standalone_workingtree('parent')
@@ -304,6 +303,12 @@
         self.build_tree_contents([('local/file', 'local')])
         self.local_tree.commit('second commit', rev_id='local')
 
+    _default_command = ['send', '-o-', '../parent']
+    _default_wd = 'local'
+    _default_sent_revs = ['local']
+    _default_errors = ['Working tree ".*/local/" has uncommitted '
+                       'changes \(See bzr status\)\.',]
+
     def set_config_send_strict(self, value):
         # set config var (any of bazaar.conf, locations.conf, branch.conf
         # should do)
@@ -311,13 +316,14 @@
         conf.set_user_option('send_strict', value)
 
     def assertSendFails(self, args):
-        self.run_send(args, rc=3,
-                      err_re=['Working tree ".*/local/" has uncommitted changes'
-                              ' \(See bzr status\)\.',])
+        self.run_send(args, rc=3, err_re=self._default_errors)
 
-    def assertSendSucceeds(self, revs, args):
+    def assertSendSucceeds(self, args, revs=None):
+        if revs is None:
+            revs = self._default_sent_revs
         out, err = self.run_send(args)
-        self.assertEquals('Bundling 1 revision(s).\n', err)
+        self.assertEquals(
+            'Bundling %d revision(s).\n' % len(revs), err)
         md = merge_directive.MergeDirective.from_lines(
                 StringIO(out).readlines())
         self.assertEqual('parent', md.base_revision_id)
@@ -333,21 +339,21 @@
         self.make_parent_and_local_branches()
 
     def test_send_default(self):
-        self.assertSendSucceeds(['local'], [])
+        self.assertSendSucceeds([])
 
     def test_send_strict(self):
-        self.assertSendSucceeds(['local'], ['--strict'])
+        self.assertSendSucceeds(['--strict'])
 
     def test_send_no_strict(self):
-        self.assertSendSucceeds(['local'], ['--no-strict'])
+        self.assertSendSucceeds(['--no-strict'])
 
     def test_send_config_var_strict(self):
         self.set_config_send_strict('true')
-        self.assertSendSucceeds(['local'], [])
+        self.assertSendSucceeds([])
 
     def test_send_config_var_no_strict(self):
         self.set_config_send_strict('false')
-        self.assertSendSucceeds(['local'], [])
+        self.assertSendSucceeds([])
 
 
 class TestSendStrictWithChanges(tests.TestCaseWithTransport,
@@ -376,14 +382,26 @@
         self.local_tree.merge_from_branch(other_tree.branch)
         self.local_tree.revert(filenames=['other-file'], backups=False)
 
+    def _out_of_sync_trees(self):
+        self.make_parent_and_local_branches()
+        self.run_bzr(['checkout', '--lightweight', 'local', 'checkout'])
+        # Make a change and commit it
+        self.build_tree_contents([('local/file', 'modified in local')])
+        self.local_tree.commit('modify file', rev_id='modified-in-local')
+        # Exercise commands from the checkout directory
+        self._default_wd = 'checkout'
+        self._default_errors = ["Working tree is out of date, please run"
+                                " 'bzr update'\.",]
+        self._default_sent_revs = ['modified-in-local', 'local']
+
     def test_send_default(self):
         self.assertSendFails([])
 
     def test_send_with_revision(self):
-        self.assertSendSucceeds(['local'], ['-r', 'revid:local'])
+        self.assertSendSucceeds(['-r', 'revid:local'], revs=['local'])
 
     def test_send_no_strict(self):
-        self.assertSendSucceeds(['local'], ['--no-strict'])
+        self.assertSendSucceeds(['--no-strict'])
 
     def test_send_strict_with_changes(self):
         self.assertSendFails(['--strict'])
@@ -391,7 +409,7 @@
     def test_send_respect_config_var_strict(self):
         self.set_config_send_strict('true')
         self.assertSendFails([])
-        self.assertSendSucceeds(['local'], ['--no-strict'])
+        self.assertSendSucceeds(['--no-strict'])
 
 
     def test_send_bogus_config_var_ignored(self):
@@ -402,11 +420,11 @@
     def test_send_no_strict_command_line_override_config(self):
         self.set_config_send_strict('true')
         self.assertSendFails([])
-        self.assertSendSucceeds(['local'], ['--no-strict'])
+        self.assertSendSucceeds(['--no-strict'])
 
     def test_push_strict_command_line_override_config(self):
         self.set_config_send_strict('false')
-        self.assertSendSucceeds(['local'], [])
+        self.assertSendSucceeds([])
         self.assertSendFails(['--strict'])
 
 



More information about the bazaar-commits mailing list