Rev 5151: Warn when the working tree is dirty instead of failing for dpush, in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Tue Apr 13 10:19:55 BST 2010
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5151 [merge]
revision-id: pqm at pqm.ubuntu.com-20100413091953-ow6ds0g52xn734v5
parent: pqm at pqm.ubuntu.com-20100413080445-hkhc3li89jzhp5eq
parent: v.ladeuil+lp at free.fr-20100413064720-h6440mk5e7ahkork
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2010-04-13 10:19:53 +0100
message:
Warn when the working tree is dirty instead of failing for dpush,
push and send
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/foreign.py foreign.py-20081112170002-olsxmandkk8qyfuq-1
bzrlib/mutabletree.py mutabletree.py-20060906023413-4wlkalbdpsxi2r4y-2
bzrlib/send.py send.py-20090521192735-j7cdb33ykmtmzx4w-1
bzrlib/tests/blackbox/test_dpush.py test_dpush.py-20090108125928-st1td6le59g0vyv2-1
bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
bzrlib/tests/blackbox/test_send.py test_bundle.py-20060616222707-c21c8b7ea5ef57b1
=== modified file 'NEWS'
--- a/NEWS 2010-04-13 08:04:45 +0000
+++ b/NEWS 2010-04-13 09:19:53 +0000
@@ -22,6 +22,12 @@
Bug Fixes
*********
+* ``bzr dpush``, ``bzr push`` and ``bzr send`` will now issue a warning
+ instead of failing when dirty trees are involved. The corresponding
+ ``dpush_strict``, ``push_strict`` and ``send_strict`` should be set to
+ True explicitly to get the previous behaviour.
+ (Vincent Ladeuil, #519319)
+
* ``bzrlib.mutabletree.MutableTree.commit`` will now support a passed in
config as in previous versions of bzrlib. (Robert Collins)
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2010-04-13 02:19:59 +0000
+++ b/bzrlib/builtins.py 2010-04-13 09:19:53 +0000
@@ -1127,26 +1127,15 @@
# Get the source branch
(tree, br_from,
_unused) = bzrdir.BzrDir.open_containing_tree_or_branch(directory)
- if strict is None:
- strict = br_from.get_config().get_user_option_as_bool('push_strict')
- if strict is None: strict = True # default value
# 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
else:
revision_id = None
- if strict and tree is not None and revision_id is None:
- if (tree.has_changes()):
- raise errors.UncommittedChanges(
- tree, more='Use --no-strict to force the push.')
- 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, more='Use --no-strict to force the push.')
-
+ if tree is not None and revision_id is None:
+ tree.warn_if_changed_or_out_of_date(
+ strict, 'push_strict', 'Use --no-strict to force the push.')
# Get the stacked_on branch, if any
if stacked_on is not None:
stacked_on = urlutils.normalize_url(stacked_on)
=== modified file 'bzrlib/foreign.py'
--- a/bzrlib/foreign.py 2010-02-23 07:43:11 +0000
+++ b/bzrlib/foreign.py 2010-04-12 16:54:35 +0000
@@ -296,20 +296,9 @@
except NoWorkingTree:
source_branch = Branch.open(directory)
source_wt = None
- if strict is None:
- strict = source_branch.get_config(
- ).get_user_option_as_bool('dpush_strict')
- if strict is None: strict = True # default value
- if strict and source_wt is not None:
- if (source_wt.has_changes()):
- raise errors.UncommittedChanges(
- source_wt, more='Use --no-strict to force the push.')
- if source_wt.last_revision() != source_wt.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(
- source_wt, more='Use --no-strict to force the push.')
+ if source_wt is not None:
+ source_wt.warn_if_changed_or_out_of_date(
+ strict, 'dpush_strict', 'Use --no-strict to force the push.')
stored_loc = source_branch.get_push_location()
if location is None:
if stored_loc is None:
=== modified file 'bzrlib/mutabletree.py'
--- a/bzrlib/mutabletree.py 2010-02-10 16:41:09 +0000
+++ b/bzrlib/mutabletree.py 2010-04-12 16:54:35 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2006, 2007 Canonical Ltd
+# Copyright (C) 2006-2010 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -258,6 +258,39 @@
return False
@needs_read_lock
+ def warn_if_changed_or_out_of_date(self, strict, opt_name, more_msg):
+ """Check the tree for uncommitted changes and branch synchronization.
+
+ If strict is None and not set in the config files, a warning is issued.
+ If strict is True, an error is raised.
+ If strict is False, no checks are done and no warning is issued.
+
+ :param strict: True, False or None, searched in branch config if None.
+
+ :param opt_name: strict option name to search in config file.
+
+ :param more_msg: Details about how to avoid the warnings.
+ """
+ if strict is None:
+ strict = self.branch.get_config().get_user_option_as_bool(opt_name)
+ if strict is not False:
+ err = None
+ if (self.has_changes()):
+ err = errors.UncommittedChanges(self, more=more_msg)
+ elif self.last_revision() != self.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 action with --no-strict
+ err = errors.OutOfDateTree(self, more=more_msg)
+ if err is not None:
+ if strict is None:
+ # We don't want to interrupt the user if he expressed no
+ # preference about strict.
+ trace.warning('%s', (err._format(),))
+ else:
+ raise err
+
+ @needs_read_lock
def last_revision(self):
"""Return the revision id of the last commit performed in this tree.
=== modified file 'bzrlib/send.py'
--- a/bzrlib/send.py 2010-03-13 02:49:14 +0000
+++ b/bzrlib/send.py 2010-04-12 16:54:35 +0000
@@ -110,20 +110,9 @@
if len(revision) == 2:
base_revision_id = revision[0].as_revision_id(branch)
if revision_id is None:
- if strict is None:
- strict = branch.get_config(
- ).get_user_option_as_bool('send_strict')
- if strict is None: strict = True # default value
- if strict and tree is not None:
- if (tree.has_changes()):
- raise errors.UncommittedChanges(
- tree, more='Use --no-strict to force the send.')
- 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 send with --no-strict
- raise errors.OutOfDateTree(
- tree, more='Use --no-strict to force the send.')
+ if tree is not None:
+ tree.warn_if_changed_or_out_of_date(
+ strict, 'send_strict', 'Use --no-strict to force the send.')
revision_id = branch.last_revision()
if revision_id == NULL_REVISION:
raise errors.BzrCommandError('No revisions to submit.')
=== modified file 'bzrlib/tests/blackbox/test_dpush.py'
--- a/bzrlib/tests/blackbox/test_dpush.py 2009-10-02 14:35:30 +0000
+++ b/bzrlib/tests/blackbox/test_dpush.py 2010-04-13 06:42:19 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2007, 2008, 2009 Canonical Ltd
+# Copyright (C) 2009, 2010 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -155,9 +155,13 @@
_default_command = ['dpush', '../to']
_default_pushed_revid = False # Doesn't aplly for dpush
- def assertPushSucceeds(self, args, pushed_revid=None):
+ def assertPushSucceeds(self, args, pushed_revid=None, with_warning=False):
+ if with_warning:
+ error_regexes = self._default_errors
+ else:
+ error_regexes = []
self.run_bzr(self._default_command + args,
- working_dir=self._default_wd)
+ working_dir=self._default_wd, error_regexes=error_regexes)
if pushed_revid is None:
# dpush change the revids, so we need to get back to it
branch_from = branch.Branch.open(self._default_wd)
=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py 2010-02-23 07:43:11 +0000
+++ b/bzrlib/tests/blackbox/test_push.py 2010-04-12 16:41:03 +0000
@@ -664,12 +664,17 @@
_default_pushed_revid = 'modified'
def assertPushFails(self, args):
- self.run_bzr_error(self._default_errors, self._default_command + args,
- working_dir=self._default_wd, retcode=3)
+ ret = self.run_bzr_error(self._default_errors,
+ self._default_command + args,
+ working_dir=self._default_wd, retcode=3)
- def assertPushSucceeds(self, args, pushed_revid=None):
+ def assertPushSucceeds(self, args, pushed_revid=None, with_warning=False):
+ if with_warning:
+ error_regexes = self._default_errors
+ else:
+ error_regexes = []
self.run_bzr(self._default_command + args,
- working_dir=self._default_wd)
+ working_dir=self._default_wd, error_regexes=error_regexes)
if pushed_revid is None:
pushed_revid = self._default_pushed_revid
tree_to = workingtree.WorkingTree.open('to')
@@ -745,7 +750,7 @@
self._default_pushed_revid = 'modified-in-local'
def test_push_default(self):
- self.assertPushFails([])
+ self.assertPushSucceeds([], with_warning=True)
def test_push_with_revision(self):
self.assertPushSucceeds(['-r', 'revid:added'], pushed_revid='added')
@@ -762,7 +767,7 @@
def test_push_bogus_config_var_ignored(self):
self.set_config_push_strict("I don't want you to be strict")
- self.assertPushFails([])
+ self.assertPushSucceeds([], with_warning=True)
def test_push_no_strict_command_line_override_config(self):
self.set_config_push_strict('yES')
=== modified file 'bzrlib/tests/blackbox/test_send.py'
--- a/bzrlib/tests/blackbox/test_send.py 2010-02-23 07:43:11 +0000
+++ b/bzrlib/tests/blackbox/test_send.py 2010-04-12 16:41:03 +0000
@@ -317,12 +317,19 @@
def assertSendFails(self, args):
self.run_send(args, rc=3, err_re=self._default_errors)
- def assertSendSucceeds(self, args, revs=None):
+ def assertSendSucceeds(self, args, revs=None, with_warning=False):
+ if with_warning:
+ err_re = self._default_errors
+ else:
+ err_re = []
if revs is None:
revs = self._default_sent_revs
- out, err = self.run_send(args)
- self.assertEquals(
- 'Bundling %d revision(s).\n' % len(revs), err)
+ out, err = self.run_send(args, err_re=err_re)
+ bundling_revs = 'Bundling %d revision(s).\n' % len(revs)
+ if with_warning:
+ self.assertEndsWith(err, bundling_revs)
+ else:
+ self.assertEquals(bundling_revs, err)
md = merge_directive.MergeDirective.from_lines(StringIO(out))
self.assertEqual('parent', md.base_revision_id)
br = serializer.read_bundle(StringIO(md.get_raw_bundle()))
@@ -396,7 +403,7 @@
self._default_sent_revs = ['modified-in-local', 'local']
def test_send_default(self):
- self.assertSendFails([])
+ self.assertSendSucceeds([], with_warning=True)
def test_send_with_revision(self):
self.assertSendSucceeds(['-r', 'revid:local'], revs=['local'])
@@ -412,11 +419,9 @@
self.assertSendFails([])
self.assertSendSucceeds(['--no-strict'])
-
def test_send_bogus_config_var_ignored(self):
self.set_config_send_strict("I'm unsure")
- self.assertSendFails([])
-
+ self.assertSendSucceeds([], with_warning=True)
def test_send_no_strict_command_line_override_config(self):
self.set_config_send_strict('true')
More information about the bazaar-commits
mailing list