Merge lp:~bialix/bzr/2.1-clean-tree-bzrdir into lp:bzr/2.1

Proposed by Alexander Belchenko
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: no longer in the source branch.
Merged at revision: 4840
Proposed branch: lp:~bialix/bzr/2.1-clean-tree-bzrdir
Merge into: lp:bzr/2.1
Diff against target: 100 lines (+45/-0)
3 files modified
NEWS (+4/-0)
bzrlib/clean_tree.py (+25/-0)
bzrlib/tests/blackbox/test_clean_tree.py (+16/-0)
To merge this branch: bzr merge lp:~bialix/bzr/2.1-clean-tree-bzrdir
Reviewer Review Type Date Requested Status
Vincent Ladeuil Approve
Review via email: mp+24669@code.launchpad.net

Commit message

``bzr clean-tree`` should not delete nested bzrdirs. (bialix, #572098)

Description of the change

To post a comment you must log in.
Revision history for this message
Alexander Belchenko (bialix) wrote :

I've received mail from lp, it says:

Launchpad encountered an error during the following operation: generating the diff for a merge proposal. The source branch has no revisions.

What I'm doing wrong?

Revision history for this message
Vincent Ladeuil (vila) wrote :

I think the email is just another fallout from maverick branches creation. The diff looks fine as did the change.

review: Approve
Revision history for this message
Andrew Bennetts (spiv) wrote :

I don't think you did anything wrong, I think that was a Launchpad bug stemming from the (now fixed) delays in pulling and scanning branches.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2010-04-30 08:13:34 +0000
+++ NEWS 2010-05-05 01:45:38 +0000
@@ -13,6 +13,10 @@
13Bug Fixes13Bug Fixes
14*********14*********
1515
16* ``bzr clean-tree`` should not delete nested bzrdirs. Required for proper
17 support of bzr-externals and scmproj plugins.
18 (Alexander Belchenko, bug #572098)
19
16* ``bzr switch`` does not die if a ConfigurableFileMerger is used.20* ``bzr switch`` does not die if a ConfigurableFileMerger is used.
17 (Aaron Bentley, #559436)21 (Aaron Bentley, #559436)
1822
1923
=== modified file 'bzrlib/clean_tree.py'
--- bzrlib/clean_tree.py 2009-03-23 14:59:43 +0000
+++ bzrlib/clean_tree.py 2010-05-05 01:45:38 +0000
@@ -20,6 +20,7 @@
20import shutil20import shutil
21import sys21import sys
2222
23from bzrlib import bzrdir, errors
23from bzrlib.osutils import has_symlinks, isdir24from bzrlib.osutils import has_symlinks, isdir
24from bzrlib.trace import note25from bzrlib.trace import note
25from bzrlib.workingtree import WorkingTree26from bzrlib.workingtree import WorkingTree
@@ -53,11 +54,14 @@
53 try:54 try:
54 deletables = list(iter_deletables(tree, unknown=unknown,55 deletables = list(iter_deletables(tree, unknown=unknown,
55 ignored=ignored, detritus=detritus))56 ignored=ignored, detritus=detritus))
57 deletables = _filter_out_nested_bzrdirs(deletables)
56 if len(deletables) == 0:58 if len(deletables) == 0:
57 note('Nothing to delete.')59 note('Nothing to delete.')
58 return 060 return 0
59 if not no_prompt:61 if not no_prompt:
60 for path, subp in deletables:62 for path, subp in deletables:
63 # FIXME using print is very bad idea
64 # clean_tree should accept to_file argument to write the output
61 print subp65 print subp
62 val = raw_input('Are you sure you wish to delete these [y/N]?')66 val = raw_input('Are you sure you wish to delete these [y/N]?')
63 if val.lower() not in ('y', 'yes'):67 if val.lower() not in ('y', 'yes'):
@@ -68,6 +72,27 @@
68 tree.unlock()72 tree.unlock()
6973
7074
75def _filter_out_nested_bzrdirs(deletables):
76 result = []
77 for path, subp in deletables:
78 # bzr won't recurse into unknowns/ignored directories by default
79 # so we don't pay a penalty for checking subdirs of path for nested
80 # bzrdir.
81 # That said we won't detect the branch in the subdir of non-branch
82 # directory and therefore delete it. (worth to FIXME?)
83 if isdir(path):
84 try:
85 bzrdir.BzrDir.open(path)
86 except errors.NotBranchError:
87 result.append((path,subp))
88 else:
89 # TODO may be we need to notify user about skipped directories?
90 pass
91 else:
92 result.append((path,subp))
93 return result
94
95
71def delete_items(deletables, dry_run=False):96def delete_items(deletables, dry_run=False):
72 """Delete files in the deletables iterable"""97 """Delete files in the deletables iterable"""
73 has_deleted = False98 has_deleted = False
7499
=== modified file 'bzrlib/tests/blackbox/test_clean_tree.py'
--- bzrlib/tests/blackbox/test_clean_tree.py 2009-03-23 14:59:43 +0000
+++ bzrlib/tests/blackbox/test_clean_tree.py 2010-05-05 01:45:38 +0000
@@ -21,6 +21,7 @@
2121
22import os22import os
2323
24from bzrlib import ignores
24from bzrlib.tests import TestCaseWithTransport25from bzrlib.tests import TestCaseWithTransport
2526
2627
@@ -62,3 +63,18 @@
62 self.failIfExists('name')63 self.failIfExists('name')
63 self.failIfExists('name~')64 self.failIfExists('name~')
64 self.failIfExists('name.pyc')65 self.failIfExists('name.pyc')
66
67 def test_clean_tree_nested_bzrdir(self):
68 # clean-tree should not blindly delete nested bzrdirs (branches)
69 # bug https://bugs.launchpad.net/bzr/+bug/572098
70 # so it will play well with scmproj/bzr-externals plugins.
71 wt1 = self.make_branch_and_tree('.')
72 wt2 = self.make_branch_and_tree('foo')
73 wt3 = self.make_branch_and_tree('bar')
74 ignores.tree_ignores_add_patterns(wt1, ['./foo'])
75 self.run_bzr(['clean-tree', '--unknown', '--force'])
76 self.failUnlessExists('foo')
77 self.failUnlessExists('bar')
78 self.run_bzr(['clean-tree', '--ignored', '--force'])
79 self.failUnlessExists('foo')
80 self.failUnlessExists('bar')

Subscribers

People subscribed via source and target branches