~bzr-pqm/bzr/bzr.dev

5384.1.1 by Vincent Ladeuil
`bzr remove` now just backs up changed files instead of annoying you
1
# Copyright (C) 2007-2010 Canonical Ltd
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
16
17
"""Tests for interface conformance of 'WorkingTree.remove'"""
18
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
19
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
5819.2.1 by Jelmer Vernooij
Fix imports.
20
from bzrlib import ignores, osutils
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
21
22
class TestRemove(TestCaseWithWorkingTree):
23
    """Tests WorkingTree.remove"""
24
2475.5.2 by Marius Kruger
* blackbox/test_remove
25
    files = ['a', 'b/', 'b/c', 'd/']
26
    rfiles = ['b/c', 'b', 'a', 'd']
5340.8.5 by Marius Kruger
* extract backup_files
27
    backup_files = ['a.~1~', 'b.~1~/', 'b.~1~/c.~1~', 'd.~1~/']
2292.1.24 by Marius Kruger
minor text cleanups
28
2655.2.15 by Marius Kruger
Apply Alexander's comments:
29
    def get_tree(self, files):
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
30
        tree = self.make_branch_and_tree('.')
2655.2.8 by Marius Kruger
* workingtree_implementations/test_remove
31
        self.build_tree(files)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
32
        self.assertPathExists(files)
2655.2.8 by Marius Kruger
* workingtree_implementations/test_remove
33
        return tree
34
2655.2.15 by Marius Kruger
Apply Alexander's comments:
35
    def get_committed_tree(self, files, message="Committing"):
36
        tree = self.get_tree(files)
2655.2.8 by Marius Kruger
* workingtree_implementations/test_remove
37
        tree.add(files)
38
        tree.commit(message)
39
        self.assertInWorkingTree(files)
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
40
        return tree
41
2655.2.15 by Marius Kruger
Apply Alexander's comments:
42
    def assertRemovedAndDeleted(self, files):
43
        self.assertNotInWorkingTree(files)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
44
        self.assertPathDoesNotExist(files)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
45
46
    def assertRemovedAndNotDeleted(self, files):
47
        self.assertNotInWorkingTree(files)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
48
        self.assertPathExists(files)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
49
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
50
    def test_remove_keep(self):
2655.2.4 by Marius Kruger
* workingtree.remove
51
        """Check that files and directories are unversioned but not deleted."""
2655.2.15 by Marius Kruger
Apply Alexander's comments:
52
        tree = self.get_tree(TestRemove.files)
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
53
        tree.add(TestRemove.files)
54
        self.assertInWorkingTree(TestRemove.files)
55
56
        tree.remove(TestRemove.files)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
57
        self.assertRemovedAndNotDeleted(TestRemove.files)
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
58
2655.2.4 by Marius Kruger
* workingtree.remove
59
    def test_remove_keep_subtree(self):
60
        """Check that a directory is unversioned but not deleted."""
61
        tree = self.make_branch_and_tree('.')
62
        subtree = self.make_branch_and_tree('subtree')
63
        tree.add('subtree', 'subtree-id')
64
65
        tree.remove('subtree')
2655.2.15 by Marius Kruger
Apply Alexander's comments:
66
        self.assertRemovedAndNotDeleted('subtree')
2655.2.4 by Marius Kruger
* workingtree.remove
67
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
68
    def test_remove_unchanged_files(self):
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
69
        """Check that unchanged files are removed and deleted."""
2655.2.15 by Marius Kruger
Apply Alexander's comments:
70
        tree = self.get_committed_tree(TestRemove.files)
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
71
        tree.remove(TestRemove.files, keep_files=False)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
72
        self.assertRemovedAndDeleted(TestRemove.files)
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
73
        tree._validate()
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
74
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
75
    def test_remove_added_files(self):
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
76
        """Removal of newly added files must back them up."""
2655.2.15 by Marius Kruger
Apply Alexander's comments:
77
        tree = self.get_tree(TestRemove.files)
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
78
        tree.add(TestRemove.files)
79
        self.assertInWorkingTree(TestRemove.files)
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
80
        tree.remove(TestRemove.files, keep_files=False)
81
        self.assertNotInWorkingTree(TestRemove.files)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
82
        self.assertPathExists(TestRemove.backup_files)
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
83
        tree._validate()
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
84
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
85
    def test_remove_changed_file(self):
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
86
        """Removal of changed files must back it up."""
3044.1.1 by Martin Pool
Fix up calls to TestCase.build_tree passing a string rather than a list
87
        tree = self.get_committed_tree(['a'])
2475.5.2 by Marius Kruger
* blackbox/test_remove
88
        self.build_tree_contents([('a', "some other new content!")])
2655.2.9 by Marius Kruger
* workingtree_implementations/test_remove
89
        self.assertInWorkingTree('a')
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
90
        tree.remove('a', keep_files=False)
91
        self.assertNotInWorkingTree(TestRemove.files)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
92
        self.assertPathExists('a.~1~')
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
93
        tree._validate()
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
94
95
    def test_remove_deleted_files(self):
96
        """Check that files are removed if they don't exist any more."""
2655.2.15 by Marius Kruger
Apply Alexander's comments:
97
        tree = self.get_committed_tree(TestRemove.files)
2475.5.1 by Marius Kruger
Fix bug and test: bzr rm refuses to delete renamed files
98
        for f in TestRemove.rfiles:
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
99
            osutils.delete_any(f)
100
        self.assertInWorkingTree(TestRemove.files)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
101
        self.assertPathDoesNotExist(TestRemove.files)
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
102
        tree.remove(TestRemove.files, keep_files=False)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
103
        self.assertRemovedAndDeleted(TestRemove.files)
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
104
        tree._validate()
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
105
2475.5.1 by Marius Kruger
Fix bug and test: bzr rm refuses to delete renamed files
106
    def test_remove_renamed_files(self):
2475.5.2 by Marius Kruger
* blackbox/test_remove
107
        """Check that files are removed even if they are renamed."""
2655.2.15 by Marius Kruger
Apply Alexander's comments:
108
        tree = self.get_committed_tree(TestRemove.files)
2475.5.1 by Marius Kruger
Fix bug and test: bzr rm refuses to delete renamed files
109
110
        for f in TestRemove.rfiles:
111
            tree.rename_one(f,f+'x')
112
        rfilesx = ['bx/cx', 'bx', 'ax', 'dx']
113
        self.assertInWorkingTree(rfilesx)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
114
        self.assertPathExists(rfilesx)
2475.5.1 by Marius Kruger
Fix bug and test: bzr rm refuses to delete renamed files
115
116
        tree.remove(rfilesx, keep_files=False)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
117
        self.assertRemovedAndDeleted(rfilesx)
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
118
        tree._validate()
2475.5.1 by Marius Kruger
Fix bug and test: bzr rm refuses to delete renamed files
119
2475.5.2 by Marius Kruger
* blackbox/test_remove
120
    def test_remove_renamed_changed_files(self):
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
121
        """Check that files that are renamed and changed are backed up."""
2655.2.15 by Marius Kruger
Apply Alexander's comments:
122
        tree = self.get_committed_tree(TestRemove.files)
2475.5.2 by Marius Kruger
* blackbox/test_remove
123
124
        for f in TestRemove.rfiles:
125
            tree.rename_one(f,f+'x')
126
        rfilesx = ['bx/cx', 'bx', 'ax', 'dx']
127
        self.build_tree_contents([('ax','changed and renamed!'),
128
                                  ('bx/cx','changed and renamed!')])
129
        self.assertInWorkingTree(rfilesx)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
130
        self.assertPathExists(rfilesx)
2475.5.2 by Marius Kruger
* blackbox/test_remove
131
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
132
        tree.remove(rfilesx, keep_files=False)
133
        self.assertNotInWorkingTree(rfilesx)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
134
        self.assertPathExists(['bx.~1~/cx.~1~', 'bx.~1~', 'ax.~1~'])
135
        self.assertPathDoesNotExist('dx.~1~') # unchanged file
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
136
        tree._validate()
2475.5.2 by Marius Kruger
* blackbox/test_remove
137
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
138
    def test_force_remove_changed_files(self):
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
139
        """Check that changed files are removed and deleted when forced."""
2655.2.15 by Marius Kruger
Apply Alexander's comments:
140
        tree = self.get_tree(TestRemove.files)
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
141
        tree.add(TestRemove.files)
142
        self.assertInWorkingTree(TestRemove.files)
143
144
        tree.remove(TestRemove.files, keep_files=False, force=True)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
145
        self.assertRemovedAndDeleted(TestRemove.files)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
146
        self.assertPathDoesNotExist(['a.~1~', 'b.~1~/', 'b.~1~/c', 'd.~1~/'])
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
147
        tree._validate()
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
148
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
149
    def test_remove_unknown_files(self):
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
150
        """Unknown files shuld be backed up"""
2655.2.15 by Marius Kruger
Apply Alexander's comments:
151
        tree = self.get_tree(TestRemove.files)
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
152
        tree.remove(TestRemove.files, keep_files=False)
153
        self.assertRemovedAndDeleted(TestRemove.files)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
154
        self.assertPathExists(TestRemove.backup_files)
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
155
        tree._validate()
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
156
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
157
    def test_remove_nonexisting_files(self):
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
158
        """Try to delete non-existing files."""
2655.2.15 by Marius Kruger
Apply Alexander's comments:
159
        tree = self.get_tree(TestRemove.files)
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
160
        tree.remove([''], keep_files=False)
2475.5.2 by Marius Kruger
* blackbox/test_remove
161
        tree.remove(['xyz', 'abc/def'], keep_files=False)
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
162
        tree._validate()
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
163
2655.2.12 by Marius Kruger
Remove unknown ignored files wihtout needing --force'
164
    def test_remove_unchanged_directory(self):
2655.2.8 by Marius Kruger
* workingtree_implementations/test_remove
165
        """Unchanged directories should be deleted."""
2655.2.6 by Marius Kruger
* workingtree.remove
166
        files = ['b/', 'b/c', 'b/sub_directory/', 'b/sub_directory/with_file']
2655.2.15 by Marius Kruger
Apply Alexander's comments:
167
        tree = self.get_committed_tree(files)
2655.2.6 by Marius Kruger
* workingtree.remove
168
        tree.remove('b', keep_files=False)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
169
        self.assertRemovedAndDeleted('b')
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
170
        tree._validate()
171
172
    def test_remove_absent_directory(self):
173
        """Removing a absent directory succeeds without corruption (#150438)."""
174
        paths = ['a/', 'a/b']
175
        tree = self.get_committed_tree(paths)
176
        self.get_transport('.').delete_tree('a')
177
        tree.remove(['a'])
178
        self.assertRemovedAndDeleted('b')
179
        tree._validate()
2292.1.30 by Marius Kruger
* Minor text fixes.
180
2655.2.12 by Marius Kruger
Remove unknown ignored files wihtout needing --force'
181
    def test_remove_unknown_ignored_files(self):
2655.2.15 by Marius Kruger
Apply Alexander's comments:
182
        """Unknown ignored files should be deleted."""
183
        tree = self.get_committed_tree(['b/'])
2655.2.12 by Marius Kruger
Remove unknown ignored files wihtout needing --force'
184
        ignores.add_runtime_ignores(["*ignored*"])
185
186
        self.build_tree(['unknown_ignored_file'])
2655.2.15 by Marius Kruger
Apply Alexander's comments:
187
        self.assertNotEquals(None, tree.is_ignored('unknown_ignored_file'))
2655.2.12 by Marius Kruger
Remove unknown ignored files wihtout needing --force'
188
        tree.remove('unknown_ignored_file', keep_files=False)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
189
        self.assertRemovedAndDeleted('unknown_ignored_file')
2655.2.12 by Marius Kruger
Remove unknown ignored files wihtout needing --force'
190
191
        self.build_tree(['b/unknown_ignored_file', 'b/unknown_ignored_dir/'])
2655.2.15 by Marius Kruger
Apply Alexander's comments:
192
        self.assertNotEquals(None, tree.is_ignored('b/unknown_ignored_file'))
193
        self.assertNotEquals(None, tree.is_ignored('b/unknown_ignored_dir'))
2655.2.12 by Marius Kruger
Remove unknown ignored files wihtout needing --force'
194
        tree.remove('b', keep_files=False)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
195
        self.assertRemovedAndDeleted('b')
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
196
        tree._validate()
2655.2.12 by Marius Kruger
Remove unknown ignored files wihtout needing --force'
197
3042.2.1 by Lukáš Lalinský
Fix ``bzr rm`` to not delete modified and ignored files.
198
    def test_remove_changed_ignored_files(self):
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
199
        """Changed ignored files should be backed up."""
3042.2.1 by Lukáš Lalinský
Fix ``bzr rm`` to not delete modified and ignored files.
200
        files = ['an_ignored_file']
201
        tree = self.get_tree(files)
202
        tree.add(files)
203
        ignores.add_runtime_ignores(["*ignored*"])
204
        self.assertInWorkingTree(files)
205
        self.assertNotEquals(None, tree.is_ignored(files[0]))
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
206
207
        tree.remove(files, keep_files=False)
208
        self.assertNotInWorkingTree(files)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
209
        self.assertPathExists('an_ignored_file.~1~')
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
210
        tree._validate()
3042.2.1 by Lukáš Lalinský
Fix ``bzr rm`` to not delete modified and ignored files.
211
2655.2.8 by Marius Kruger
* workingtree_implementations/test_remove
212
    def test_dont_remove_directory_with_unknowns(self):
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
213
        """Directories with unknowns should be backed up."""
2655.2.8 by Marius Kruger
* workingtree_implementations/test_remove
214
        directories = ['a/', 'b/', 'c/', 'c/c/']
2655.2.15 by Marius Kruger
Apply Alexander's comments:
215
        tree = self.get_committed_tree(directories)
2655.2.8 by Marius Kruger
* workingtree_implementations/test_remove
216
217
        self.build_tree(['a/unknown_file'])
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
218
        tree.remove('a', keep_files=False)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
219
        self.assertPathExists('a.~1~/unknown_file')
2655.2.8 by Marius Kruger
* workingtree_implementations/test_remove
220
221
        self.build_tree(['b/unknown_directory'])
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
222
        tree.remove('b', keep_files=False)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
223
        self.assertPathExists('b.~1~/unknown_directory')
2655.2.8 by Marius Kruger
* workingtree_implementations/test_remove
224
225
        self.build_tree(['c/c/unknown_file'])
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
226
        tree.remove('c/c', keep_files=False)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
227
        self.assertPathExists('c/c.~1~/unknown_file')
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
228
229
        tree.remove('c', keep_files=False)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
230
        self.assertPathExists('c.~1~/')
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
231
232
        self.assertNotInWorkingTree(directories)
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
233
        tree._validate()
2655.2.8 by Marius Kruger
* workingtree_implementations/test_remove
234
235
    def test_force_remove_directory_with_unknowns(self):
2655.2.4 by Marius Kruger
* workingtree.remove
236
        """Unchanged non-empty directories should be deleted when forced."""
2655.2.9 by Marius Kruger
* workingtree_implementations/test_remove
237
        files = ['b/', 'b/c']
2655.2.15 by Marius Kruger
Apply Alexander's comments:
238
        tree = self.get_committed_tree(files)
2655.2.4 by Marius Kruger
* workingtree.remove
239
240
        other_files = ['b/unknown_file', 'b/sub_directory/',
2655.2.6 by Marius Kruger
* workingtree.remove
241
            'b/sub_directory/with_file', 'b/sub_directory/sub_directory/']
2655.2.4 by Marius Kruger
* workingtree.remove
242
        self.build_tree(other_files)
243
2655.2.9 by Marius Kruger
* workingtree_implementations/test_remove
244
        self.assertInWorkingTree(files)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
245
        self.assertPathExists(files)
2655.2.9 by Marius Kruger
* workingtree_implementations/test_remove
246
247
        tree.remove('b', keep_files=False, force=True)
248
2655.2.15 by Marius Kruger
Apply Alexander's comments:
249
        self.assertRemovedAndDeleted(files)
250
        self.assertRemovedAndDeleted(other_files)
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
251
        tree._validate()
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
252
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
253
    def test_remove_directory_with_changed_file(self):
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
254
        """Backup directories with changed files."""
255
        files = ['b/', 'b/c']
256
        tree = self.get_committed_tree(files)
257
        self.build_tree_contents([('b/c', "some other new content!")])
258
259
        tree.remove('b', keep_files=False)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
260
        self.assertPathExists('b.~1~/c.~1~')
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
261
        self.assertNotInWorkingTree(files)
262
263
    def test_remove_force_directory_with_changed_file(self):
264
        """Delete directories with changed files when forced."""
265
        files = ['b/', 'b/c']
266
        tree = self.get_committed_tree(files)
267
        self.build_tree_contents([('b/c', "some other new content!")])
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
268
2655.2.15 by Marius Kruger
Apply Alexander's comments:
269
        # see if we can force it now..
2655.2.9 by Marius Kruger
* workingtree_implementations/test_remove
270
        tree.remove('b', keep_files=False, force=True)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
271
        self.assertRemovedAndDeleted(files)
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
272
        tree._validate()
1551.15.11 by Aaron Bentley
Bugfix WorkingTree.remove to handle subtrees, and non-cwd trees
273
2668.3.1 by Daniel Watkins
Added test to fix bug #129880.
274
    def test_remove_directory_with_changed_emigrated_file(self):
275
        # As per bug #129880
276
        tree = self.make_branch_and_tree('.')
5160.2.8 by Marius Kruger
fix andrew's nits
277
        self.build_tree_contents([('somedir/',), ('somedir/file', 'contents')])
2668.3.1 by Daniel Watkins
Added test to fix bug #129880.
278
        tree.add(['somedir', 'somedir/file'])
279
        tree.commit(message="first")
280
        self.build_tree_contents([('somedir/file', 'changed')])
281
        tree.rename_one('somedir/file', 'moved-file')
282
        tree.remove('somedir', keep_files=False)
283
        self.assertNotInWorkingTree('somedir')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
284
        self.assertPathDoesNotExist('somedir')
5160.2.6 by Marius Kruger
check that the file that was moved out of the dir isn't deleted - as per review
285
        self.assertInWorkingTree('moved-file')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
286
        self.assertPathExists('moved-file')
2668.3.1 by Daniel Watkins
Added test to fix bug #129880.
287
2655.2.11 by Marius Kruger
* Update NEWS
288
    def test_remove_directory_with_renames(self):
289
        """Delete directory with renames in or out."""
2655.2.10 by Marius Kruger
add test for removing a direcory with something that has been moved out
290
2655.2.11 by Marius Kruger
* Update NEWS
291
        files = ['a/', 'a/file', 'a/directory/', 'b/']
2655.2.10 by Marius Kruger
add test for removing a direcory with something that has been moved out
292
        files_to_move = ['a/file', 'a/directory/']
293
2655.2.15 by Marius Kruger
Apply Alexander's comments:
294
        tree = self.get_committed_tree(files)
295
        # move stuff from a=>b
2655.2.10 by Marius Kruger
add test for removing a direcory with something that has been moved out
296
        tree.move(['a/file', 'a/directory'], to_dir='b')
297
298
        moved_files = ['b/file', 'b/directory/']
2655.2.15 by Marius Kruger
Apply Alexander's comments:
299
        self.assertRemovedAndDeleted(files_to_move)
2655.2.10 by Marius Kruger
add test for removing a direcory with something that has been moved out
300
        self.assertInWorkingTree(moved_files)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
301
        self.assertPathExists(moved_files)
2655.2.10 by Marius Kruger
add test for removing a direcory with something that has been moved out
302
2655.2.11 by Marius Kruger
* Update NEWS
303
        # check if it works with renames out
2655.2.10 by Marius Kruger
add test for removing a direcory with something that has been moved out
304
        tree.remove('a', keep_files=False)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
305
        self.assertRemovedAndDeleted(['a/'])
2655.2.11 by Marius Kruger
* Update NEWS
306
307
        # check if it works with renames in
308
        tree.remove('b', keep_files=False)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
309
        self.assertRemovedAndDeleted(['b/'])
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
310
        tree._validate()
2655.2.10 by Marius Kruger
add test for removing a direcory with something that has been moved out
311
1551.15.11 by Aaron Bentley
Bugfix WorkingTree.remove to handle subtrees, and non-cwd trees
312
    def test_non_cwd(self):
313
        tree = self.make_branch_and_tree('tree')
314
        self.build_tree(['tree/dir/', 'tree/dir/file'])
315
        tree.add(['dir', 'dir/file'])
316
        tree.commit('add file')
317
        tree.remove('dir/', keep_files=False)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
318
        self.assertPathDoesNotExist('tree/dir/file')
2655.2.15 by Marius Kruger
Apply Alexander's comments:
319
        self.assertNotInWorkingTree('tree/dir/file', 'tree')
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
320
        tree._validate()
2967.5.8 by Daniel Watkins
Moved tests to correct location.
321
322
    def test_remove_uncommitted_removed_file(self):
323
        # As per bug #152811
324
        tree = self.get_committed_tree(['a'])
325
        tree.remove('a', keep_files=False)
326
        tree.remove('a', keep_files=False)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
327
        self.assertPathDoesNotExist('a')
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
328
        tree._validate()
2967.5.8 by Daniel Watkins
Moved tests to correct location.
329
330
    def test_remove_file_and_containing_dir(self):
331
        tree = self.get_committed_tree(['config/', 'config/file'])
332
        tree.remove('config/file', keep_files=False)
333
        tree.remove('config', keep_files=False)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
334
        self.assertPathDoesNotExist('config/file')
335
        self.assertPathDoesNotExist('config')
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
336
        tree._validate()
3719.1.1 by Vincent Ladeuil
Fix bug #272648
337
338
    def test_remove_dir_before_bzr(self):
339
        # As per bug #272648. Note that a file must be present in the directory
340
        # or the bug doesn't manifest itself.
341
        tree = self.get_committed_tree(['.aaa/', '.aaa/file'])
342
        tree.remove('.aaa/', keep_files=False)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
343
        self.assertPathDoesNotExist('.aaa/file')
344
        self.assertPathDoesNotExist('.aaa')
3719.1.1 by Vincent Ladeuil
Fix bug #272648
345
        tree._validate()