Rev 5212: (garyvdm for bialix) bzr clean-tree should not delete nested bzrdirs. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed May 5 15:44:58 BST 2010
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5212 [merge]
revision-id: pqm at pqm.ubuntu.com-20100505144453-4ewd3ms50q5m9tgw
parent: pqm at pqm.ubuntu.com-20100505132524-enlf40fsv53johdt
parent: garyvdm at gmail.com-20100505085716-qvvrjncz0erg61p8
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2010-05-05 15:44:53 +0100
message:
(garyvdm for bialix) bzr clean-tree should not delete nested bzrdirs.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/clean_tree.py clean_tree.py-20050827022328-5ba46e22d074695c
bzrlib/tests/blackbox/test_clean_tree.py test_clean_tree.py-20090219235516-em1ybc01twsqacx9-1
=== modified file 'NEWS'
--- a/NEWS 2010-05-05 13:25:24 +0000
+++ b/NEWS 2010-05-05 14:44:53 +0000
@@ -48,6 +48,10 @@
better with sudo.
(Martin <gzlist at googlemail.com>, Parth Malwankar, #376388)
+* ``bzr clean-tree`` should not delete nested bzrdirs. Required for proper
+ support of bzr-externals and scmproj plugins.
+ (Alexander Belchenko, bug #572098)
+
* ``bzr ignore`` will no longer add duplicate patterns to .bzrignore.
(Gordon Tyler, #572092)
=== modified file 'bzrlib/clean_tree.py'
--- a/bzrlib/clean_tree.py 2010-04-30 11:03:59 +0000
+++ b/bzrlib/clean_tree.py 2010-05-04 09:20:17 +0000
@@ -18,6 +18,7 @@
import os
import shutil
+from bzrlib import bzrdir, errors
from bzrlib.osutils import isdir
from bzrlib.trace import note
from bzrlib.workingtree import WorkingTree
@@ -51,11 +52,14 @@
try:
deletables = list(iter_deletables(tree, unknown=unknown,
ignored=ignored, detritus=detritus))
+ deletables = _filter_out_nested_bzrdirs(deletables)
if len(deletables) == 0:
note('Nothing to delete.')
return 0
if not no_prompt:
for path, subp in deletables:
+ # FIXME using print is very bad idea
+ # clean_tree should accept to_file argument to write the output
print subp
val = raw_input('Are you sure you wish to delete these [y/N]?')
if val.lower() not in ('y', 'yes'):
@@ -66,6 +70,27 @@
tree.unlock()
+def _filter_out_nested_bzrdirs(deletables):
+ result = []
+ for path, subp in deletables:
+ # bzr won't recurse into unknowns/ignored directories by default
+ # so we don't pay a penalty for checking subdirs of path for nested
+ # bzrdir.
+ # That said we won't detect the branch in the subdir of non-branch
+ # directory and therefore delete it. (worth to FIXME?)
+ if isdir(path):
+ try:
+ bzrdir.BzrDir.open(path)
+ except errors.NotBranchError:
+ result.append((path,subp))
+ else:
+ # TODO may be we need to notify user about skipped directories?
+ pass
+ else:
+ result.append((path,subp))
+ return result
+
+
def delete_items(deletables, dry_run=False):
"""Delete files in the deletables iterable"""
has_deleted = False
=== modified file 'bzrlib/tests/blackbox/test_clean_tree.py'
--- a/bzrlib/tests/blackbox/test_clean_tree.py 2010-05-02 20:10:25 +0000
+++ b/bzrlib/tests/blackbox/test_clean_tree.py 2010-05-05 08:57:16 +0000
@@ -21,6 +21,7 @@
import os
+from bzrlib import ignores
from bzrlib.tests import TestCaseWithTransport
@@ -63,6 +64,21 @@
self.failIfExists('name~')
self.failIfExists('name.pyc')
+ def test_clean_tree_nested_bzrdir(self):
+ # clean-tree should not blindly delete nested bzrdirs (branches)
+ # bug https://bugs.launchpad.net/bzr/+bug/572098
+ # so it will play well with scmproj/bzr-externals plugins.
+ wt1 = self.make_branch_and_tree('.')
+ wt2 = self.make_branch_and_tree('foo')
+ wt3 = self.make_branch_and_tree('bar')
+ ignores.tree_ignores_add_patterns(wt1, ['./foo'])
+ self.run_bzr(['clean-tree', '--unknown', '--force'])
+ self.failUnlessExists('foo')
+ self.failUnlessExists('bar')
+ self.run_bzr(['clean-tree', '--ignored', '--force'])
+ self.failUnlessExists('foo')
+ self.failUnlessExists('bar')
+
def test_clean_tree_directory(self):
"""Test --directory option"""
tree = self.make_branch_and_tree('a')
More information about the bazaar-commits
mailing list