Rev 4725: (vila) Add a --strict option to dpush in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Fri Oct 2 19:01:10 BST 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4725 [merge]
revision-id: pqm at pqm.ubuntu.com-20091002180105-oeomf71t7l9gpv6g
parent: pqm at pqm.ubuntu.com-20091002101015-hed4j97ksfqyu4mp
parent: v.ladeuil+lp at free.fr-20091002164951-hs4xnw3ly1bmxzpr
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2009-10-02 19:01:05 +0100
message:
(vila) Add a --strict option to dpush
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/foreign.py foreign.py-20081112170002-olsxmandkk8qyfuq-1
bzrlib/help_topics/en/configuration.txt configuration.txt-20060314161707-868350809502af01
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/test_foreign.py test_foreign.py-20081125004048-ywb901edgp9lluxo-1
=== modified file 'NEWS'
--- a/NEWS 2009-10-02 05:43:41 +0000
+++ b/NEWS 2009-10-02 16:48:36 +0000
@@ -57,6 +57,11 @@
longer report incorrect errors about ``Missing inventory ('TREE_ROOT', ...)``
(Robert Collins, #416732)
+* ``bzr dpush`` now aborts if uncommitted changes (including pending merges)
+ are present in the working tree. The configuration option ``dpush_strict``
+ can be used to set the default for this behavior.
+ (Vincent Ladeuil, #438158)
+
* ``bzr info -v`` on a 2a format still claimed that it was a "Development
format" (John Arbash Meinel, #424392)
=== modified file 'bzrlib/foreign.py'
--- a/bzrlib/foreign.py 2009-09-18 01:25:08 +0000
+++ b/bzrlib/foreign.py 2009-10-02 09:11:43 +0000
@@ -271,16 +271,22 @@
"""
hidden = True
takes_args = ['location?']
- takes_options = ['remember', Option('directory',
- help='Branch to push from, '
- 'rather than the one containing the working directory.',
- short_name='d',
- type=unicode,
- ),
- Option('no-rebase', help="Do not rebase after push.")]
+ takes_options = [
+ 'remember',
+ Option('directory',
+ help='Branch to push from, '
+ 'rather than the one containing the working directory.',
+ short_name='d',
+ type=unicode,
+ ),
+ Option('no-rebase', help="Do not rebase after push."),
+ Option('strict',
+ help='Refuse to push if there are uncommitted changes in'
+ ' the working tree, --no-strict disables the check.'),
+ ]
- def run(self, location=None, remember=False, directory=None,
- no_rebase=False):
+ def run(self, location=None, remember=False, directory=None,
+ no_rebase=False, strict=None):
from bzrlib import urlutils
from bzrlib.bzrdir import BzrDir
from bzrlib.errors import BzrCommandError, NoWorkingTree
@@ -294,6 +300,21 @@
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(source_wt.basis_tree())
+ or len(source_wt.get_parent_ids()) > 1):
+ 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.')
stored_loc = source_branch.get_push_location()
if location is None:
if stored_loc is None:
=== modified file 'bzrlib/help_topics/en/configuration.txt'
--- a/bzrlib/help_topics/en/configuration.txt 2009-08-21 09:19:11 +0000
+++ b/bzrlib/help_topics/en/configuration.txt 2009-10-02 09:11:43 +0000
@@ -464,6 +464,13 @@
If present, defines the ``--strict`` option default value for checking
uncommitted changes before pushing.
+dpush_strict
+~~~~~~~~~~~~
+
+If present, defines the ``--strict`` option default value for checking
+uncommitted changes before pushing into a different VCS without any
+custom bzr metadata.
+
bound_location
~~~~~~~~~~~~~~
=== modified file 'bzrlib/tests/blackbox/test_dpush.py'
--- a/bzrlib/tests/blackbox/test_dpush.py 2009-10-02 07:24:29 +0000
+++ b/bzrlib/tests/blackbox/test_dpush.py 2009-10-02 14:35:30 +0000
@@ -25,34 +25,44 @@
bzrdir,
foreign,
tests,
- )
-from bzrlib.tests.test_foreign import (
- DummyForeignVcsDirFormat,
- InterToDummyVcsBranch,
+ workingtree,
)
from bzrlib.tests import (
blackbox,
test_foreign,
)
+from bzrlib.tests.blackbox import test_push
+
+
+def load_tests(standard_tests, module, loader):
+ """Multiply tests for the dpush command."""
+ result = loader.suiteClass()
+
+ # one for each king of change
+ changes_tests, remaining_tests = tests.split_suite_by_condition(
+ standard_tests, tests.condition_isinstance((
+ TestDpushStrictWithChanges,
+ )))
+ changes_scenarios = [
+ ('uncommitted',
+ 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
+ result.addTests(remaining_tests)
+
+ return result
+
class TestDpush(blackbox.ExternalBase):
def setUp(self):
- bzrdir.BzrDirFormat.register_control_format(
- test_foreign.DummyForeignVcsDirFormat)
- branch.InterBranch.register_optimiser(
- test_foreign.InterToDummyVcsBranch)
- self.addCleanup(self.unregister_format)
super(TestDpush, self).setUp()
-
- def unregister_format(self):
- try:
- bzrdir.BzrDirFormat.unregister_control_format(
- test_foreign.DummyForeignVcsDirFormat)
- except ValueError:
- pass
- branch.InterBranch.unregister_optimiser(
- test_foreign.InterToDummyVcsBranch)
+ test_foreign.register_dummy_foreign_for_test(self)
def make_dummy_builder(self, relpath):
builder = self.make_branch_builder(
@@ -103,8 +113,10 @@
newrevid = dc_tree.commit('msg')
self.build_tree_contents([("dc/foofile", "blaaaal")])
- self.check_output("", "dpush -d dc d")
+ self.check_output("", "dpush -d dc d --no-strict")
self.assertFileEqual("blaaaal", "dc/foofile")
+ # if the dummy vcs wasn't that dummy we could uncomment the line below
+ # self.assertFileEqual("blaaaa", "d/foofile")
self.check_output('modified:\n foofile\n', "status dc")
def test_diverged(self):
@@ -124,3 +136,56 @@
output, error = self.run_bzr("dpush -d dc d", retcode=3)
self.assertEquals(output, "")
self.assertContainsRe(error, "have diverged")
+
+
+class TestDpushStrictMixin(object):
+
+ def setUp(self):
+ test_foreign.register_dummy_foreign_for_test(self)
+ # Create an empty branch where we will be able to push
+ self.foreign = self.make_branch(
+ 'to', format=test_foreign.DummyForeignVcsDirFormat())
+
+ def set_config_push_strict(self, value):
+ # set config var (any of bazaar.conf, locations.conf, branch.conf
+ # should do)
+ conf = self.tree.branch.get_config()
+ conf.set_user_option('dpush_strict', value)
+
+ _default_command = ['dpush', '../to']
+ _default_pushed_revid = False # Doesn't aplly for dpush
+
+ def assertPushSucceeds(self, args, pushed_revid=None):
+ self.run_bzr(self._default_command + args,
+ working_dir=self._default_wd)
+ 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)
+ pushed_revid = branch_from.last_revision()
+ branch_to = branch.Branch.open('to')
+ repo_to = branch_to.repository
+ self.assertTrue(repo_to.has_revision(pushed_revid))
+ self.assertEqual(branch_to.last_revision(), pushed_revid)
+
+
+
+class TestDpushStrictWithoutChanges(TestDpushStrictMixin,
+ test_push.TestPushStrictWithoutChanges):
+
+ def setUp(self):
+ test_push.TestPushStrictWithoutChanges.setUp(self)
+ TestDpushStrictMixin.setUp(self)
+
+
+class TestDpushStrictWithChanges(TestDpushStrictMixin,
+ test_push.TestPushStrictWithChanges):
+
+ _changes_type = None # Set by load_tests
+
+ def setUp(self):
+ test_push.TestPushStrictWithChanges.setUp(self)
+ TestDpushStrictMixin.setUp(self)
+
+ def test_push_with_revision(self):
+ raise tests.TestNotApplicable('dpush does not handle --revision')
+
=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py 2009-09-24 05:31:23 +0000
+++ b/bzrlib/tests/blackbox/test_push.py 2009-10-02 11:35:02 +0000
@@ -695,6 +695,8 @@
def setUp(self):
super(TestPushStrictWithChanges, self).setUp()
+ # Apply the changes defined in load_tests: one of _uncommitted_changes,
+ # _pending_merges or _out_of_sync_trees
getattr(self, self._changes_type)()
def _uncommitted_changes(self):
=== modified file 'bzrlib/tests/test_foreign.py'
--- a/bzrlib/tests/test_foreign.py 2009-10-02 09:27:34 +0000
+++ b/bzrlib/tests/test_foreign.py 2009-10-02 14:50:35 +0000
@@ -255,6 +255,17 @@
hardlink=hardlink, stacked=stacked, source_branch=source_branch)
+def register_dummy_foreign_for_test(testcase):
+ bzrdir.BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
+ testcase.addCleanup(bzrdir.BzrDirFormat.unregister_control_format,
+ DummyForeignVcsDirFormat)
+ # We need to register the optimiser to make the dummy appears really
+ # different from a regular bzr repository.
+ branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
+ testcase.addCleanup(branch.InterBranch.unregister_optimiser,
+ InterToDummyVcsBranch)
+
+
class ForeignVcsRegistryTests(tests.TestCase):
"""Tests for the ForeignVcsRegistry class."""
@@ -316,18 +327,8 @@
"""Very basic test for DummyForeignVcs."""
def setUp(self):
- bzrdir.BzrDirFormat.register_control_format(DummyForeignVcsDirFormat)
- branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
- self.addCleanup(self.unregister)
super(DummyForeignVcsTests, self).setUp()
-
- def unregister(self):
- try:
- bzrdir.BzrDirFormat.unregister_control_format(
- DummyForeignVcsDirFormat)
- except ValueError:
- pass
- branch.InterBranch.unregister_optimiser(InterToDummyVcsBranch)
+ register_dummy_foreign_for_test(self)
def test_create(self):
"""Test we can create dummies."""
More information about the bazaar-commits
mailing list