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
1=== modified file 'NEWS'
2--- NEWS 2010-04-30 08:13:34 +0000
3+++ NEWS 2010-05-05 01:45:38 +0000
4@@ -13,6 +13,10 @@
5 Bug Fixes
6 *********
7
8+* ``bzr clean-tree`` should not delete nested bzrdirs. Required for proper
9+ support of bzr-externals and scmproj plugins.
10+ (Alexander Belchenko, bug #572098)
11+
12 * ``bzr switch`` does not die if a ConfigurableFileMerger is used.
13 (Aaron Bentley, #559436)
14
15
16=== modified file 'bzrlib/clean_tree.py'
17--- bzrlib/clean_tree.py 2009-03-23 14:59:43 +0000
18+++ bzrlib/clean_tree.py 2010-05-05 01:45:38 +0000
19@@ -20,6 +20,7 @@
20 import shutil
21 import sys
22
23+from bzrlib import bzrdir, errors
24 from bzrlib.osutils import has_symlinks, isdir
25 from bzrlib.trace import note
26 from bzrlib.workingtree import WorkingTree
27@@ -53,11 +54,14 @@
28 try:
29 deletables = list(iter_deletables(tree, unknown=unknown,
30 ignored=ignored, detritus=detritus))
31+ deletables = _filter_out_nested_bzrdirs(deletables)
32 if len(deletables) == 0:
33 note('Nothing to delete.')
34 return 0
35 if not no_prompt:
36 for path, subp in deletables:
37+ # FIXME using print is very bad idea
38+ # clean_tree should accept to_file argument to write the output
39 print subp
40 val = raw_input('Are you sure you wish to delete these [y/N]?')
41 if val.lower() not in ('y', 'yes'):
42@@ -68,6 +72,27 @@
43 tree.unlock()
44
45
46+def _filter_out_nested_bzrdirs(deletables):
47+ result = []
48+ for path, subp in deletables:
49+ # bzr won't recurse into unknowns/ignored directories by default
50+ # so we don't pay a penalty for checking subdirs of path for nested
51+ # bzrdir.
52+ # That said we won't detect the branch in the subdir of non-branch
53+ # directory and therefore delete it. (worth to FIXME?)
54+ if isdir(path):
55+ try:
56+ bzrdir.BzrDir.open(path)
57+ except errors.NotBranchError:
58+ result.append((path,subp))
59+ else:
60+ # TODO may be we need to notify user about skipped directories?
61+ pass
62+ else:
63+ result.append((path,subp))
64+ return result
65+
66+
67 def delete_items(deletables, dry_run=False):
68 """Delete files in the deletables iterable"""
69 has_deleted = False
70
71=== modified file 'bzrlib/tests/blackbox/test_clean_tree.py'
72--- bzrlib/tests/blackbox/test_clean_tree.py 2009-03-23 14:59:43 +0000
73+++ bzrlib/tests/blackbox/test_clean_tree.py 2010-05-05 01:45:38 +0000
74@@ -21,6 +21,7 @@
75
76 import os
77
78+from bzrlib import ignores
79 from bzrlib.tests import TestCaseWithTransport
80
81
82@@ -62,3 +63,18 @@
83 self.failIfExists('name')
84 self.failIfExists('name~')
85 self.failIfExists('name.pyc')
86+
87+ def test_clean_tree_nested_bzrdir(self):
88+ # clean-tree should not blindly delete nested bzrdirs (branches)
89+ # bug https://bugs.launchpad.net/bzr/+bug/572098
90+ # so it will play well with scmproj/bzr-externals plugins.
91+ wt1 = self.make_branch_and_tree('.')
92+ wt2 = self.make_branch_and_tree('foo')
93+ wt3 = self.make_branch_and_tree('bar')
94+ ignores.tree_ignores_add_patterns(wt1, ['./foo'])
95+ self.run_bzr(['clean-tree', '--unknown', '--force'])
96+ self.failUnlessExists('foo')
97+ self.failUnlessExists('bar')
98+ self.run_bzr(['clean-tree', '--ignored', '--force'])
99+ self.failUnlessExists('foo')
100+ self.failUnlessExists('bar')

Subscribers

People subscribed via source and target branches