/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.2 by Vincent Ladeuil
Fix assertNotEquals being deprecated by using assertNotEqual.
1
# Copyright (C) 2007-2012, 2016 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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
19
from breezy.tests.per_workingtree import TestCaseWithWorkingTree
20
from breezy import ignores, osutils
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
21
7143.15.2 by Jelmer Vernooij
Run autopep8.
22
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
23
class TestRemove(TestCaseWithWorkingTree):
24
    """Tests WorkingTree.remove"""
25
2475.5.2 by Marius Kruger
* blackbox/test_remove
26
    files = ['a', 'b/', 'b/c', 'd/']
27
    rfiles = ['b/c', 'b', 'a', 'd']
5340.8.5 by Marius Kruger
* extract backup_files
28
    backup_files = ['a.~1~', 'b.~1~/', 'b.~1~/c.~1~', 'd.~1~/']
7199.3.2 by Jelmer Vernooij
Fix remaining remove tests.
29
    backup_files_no_version_dirs = ['a.~1~', 'b.~1~/', 'b.~1~/c.~1~']
2292.1.24 by Marius Kruger
minor text cleanups
30
2655.2.15 by Marius Kruger
Apply Alexander's comments:
31
    def get_tree(self, files):
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
32
        tree = self.make_branch_and_tree('.')
2655.2.8 by Marius Kruger
* workingtree_implementations/test_remove
33
        self.build_tree(files)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
34
        self.assertPathExists(files)
2655.2.8 by Marius Kruger
* workingtree_implementations/test_remove
35
        return tree
36
2655.2.15 by Marius Kruger
Apply Alexander's comments:
37
    def get_committed_tree(self, files, message="Committing"):
38
        tree = self.get_tree(files)
2655.2.8 by Marius Kruger
* workingtree_implementations/test_remove
39
        tree.add(files)
40
        tree.commit(message)
6913.4.1 by Jelmer Vernooij
Fix some remove tests for foreign branches.
41
        if not tree.has_versioned_directories():
42
            self.assertInWorkingTree(
43
                [f for f in files if not f.endswith("/")])
44
            self.assertPathExists(files)
45
        else:
46
            self.assertInWorkingTree(files)
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
47
        return tree
48
2655.2.15 by Marius Kruger
Apply Alexander's comments:
49
    def assertRemovedAndDeleted(self, files):
50
        self.assertNotInWorkingTree(files)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
51
        self.assertPathDoesNotExist(files)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
52
53
    def assertRemovedAndNotDeleted(self, files):
54
        self.assertNotInWorkingTree(files)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
55
        self.assertPathExists(files)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
56
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
57
    def test_remove_keep(self):
2655.2.4 by Marius Kruger
* workingtree.remove
58
        """Check that files and directories are unversioned but not deleted."""
2655.2.15 by Marius Kruger
Apply Alexander's comments:
59
        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()
60
        tree.add(TestRemove.files)
61
62
        tree.remove(TestRemove.files)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
63
        self.assertRemovedAndNotDeleted(TestRemove.files)
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
64
2655.2.4 by Marius Kruger
* workingtree.remove
65
    def test_remove_keep_subtree(self):
66
        """Check that a directory is unversioned but not deleted."""
67
        tree = self.make_branch_and_tree('.')
68
        subtree = self.make_branch_and_tree('subtree')
6926.2.8 by Jelmer Vernooij
Fix some more tests.
69
        subtree.commit('')
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
70
        tree.add('subtree')
2655.2.4 by Marius Kruger
* workingtree.remove
71
72
        tree.remove('subtree')
2655.2.15 by Marius Kruger
Apply Alexander's comments:
73
        self.assertRemovedAndNotDeleted('subtree')
2655.2.4 by Marius Kruger
* workingtree.remove
74
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
75
    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()
76
        """Check that unchanged files are removed and deleted."""
2655.2.15 by Marius Kruger
Apply Alexander's comments:
77
        tree = self.get_committed_tree(TestRemove.files)
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
78
        tree.remove(TestRemove.files, keep_files=False)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
79
        self.assertRemovedAndDeleted(TestRemove.files)
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
80
        tree._validate()
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
81
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
82
    def test_remove_added_files(self):
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
83
        """Removal of newly added files must back them up."""
2655.2.15 by Marius Kruger
Apply Alexander's comments:
84
        tree = self.get_tree(TestRemove.files)
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
85
        tree.add(TestRemove.files)
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
86
        tree.remove(TestRemove.files, keep_files=False)
87
        self.assertNotInWorkingTree(TestRemove.files)
7199.3.2 by Jelmer Vernooij
Fix remaining remove tests.
88
        if tree.has_versioned_directories():
89
            self.assertPathExists(TestRemove.backup_files)
90
        else:
91
            self.assertPathExists(TestRemove.backup_files_no_version_dirs)
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
92
        tree._validate()
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
93
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
94
    def test_remove_changed_file(self):
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
95
        """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
96
        tree = self.get_committed_tree(['a'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
97
        self.build_tree_contents([('a', b"some other new content!")])
2655.2.9 by Marius Kruger
* workingtree_implementations/test_remove
98
        self.assertInWorkingTree('a')
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
99
        tree.remove('a', keep_files=False)
100
        self.assertNotInWorkingTree(TestRemove.files)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
101
        self.assertPathExists('a.~1~')
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
102
        tree._validate()
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
103
104
    def test_remove_deleted_files(self):
105
        """Check that files are removed if they don't exist any more."""
2655.2.15 by Marius Kruger
Apply Alexander's comments:
106
        tree = self.get_committed_tree(TestRemove.files)
2475.5.1 by Marius Kruger
Fix bug and test: bzr rm refuses to delete renamed files
107
        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()
108
            osutils.delete_any(f)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
109
        self.assertPathDoesNotExist(TestRemove.files)
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
110
        tree.remove(TestRemove.files, keep_files=False)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
111
        self.assertRemovedAndDeleted(TestRemove.files)
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
112
        tree._validate()
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
113
2475.5.1 by Marius Kruger
Fix bug and test: bzr rm refuses to delete renamed files
114
    def test_remove_renamed_files(self):
2475.5.2 by Marius Kruger
* blackbox/test_remove
115
        """Check that files are removed even if they are renamed."""
2655.2.15 by Marius Kruger
Apply Alexander's comments:
116
        tree = self.get_committed_tree(TestRemove.files)
2475.5.1 by Marius Kruger
Fix bug and test: bzr rm refuses to delete renamed files
117
118
        for f in TestRemove.rfiles:
7143.15.2 by Jelmer Vernooij
Run autopep8.
119
            tree.rename_one(f, f + 'x')
2475.5.1 by Marius Kruger
Fix bug and test: bzr rm refuses to delete renamed files
120
        rfilesx = ['bx/cx', 'bx', 'ax', 'dx']
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
121
        self.assertPathExists(rfilesx)
2475.5.1 by Marius Kruger
Fix bug and test: bzr rm refuses to delete renamed files
122
123
        tree.remove(rfilesx, keep_files=False)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
124
        self.assertRemovedAndDeleted(rfilesx)
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
125
        tree._validate()
2475.5.1 by Marius Kruger
Fix bug and test: bzr rm refuses to delete renamed files
126
2475.5.2 by Marius Kruger
* blackbox/test_remove
127
    def test_remove_renamed_changed_files(self):
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
128
        """Check that files that are renamed and changed are backed up."""
2655.2.15 by Marius Kruger
Apply Alexander's comments:
129
        tree = self.get_committed_tree(TestRemove.files)
2475.5.2 by Marius Kruger
* blackbox/test_remove
130
131
        for f in TestRemove.rfiles:
7143.15.2 by Jelmer Vernooij
Run autopep8.
132
            tree.rename_one(f, f + 'x')
2475.5.2 by Marius Kruger
* blackbox/test_remove
133
        rfilesx = ['bx/cx', 'bx', 'ax', 'dx']
6855.4.1 by Jelmer Vernooij
Yet more bees.
134
        self.build_tree_contents([('ax', b'changed and renamed!'),
135
                                  ('bx/cx', b'changed and renamed!')])
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
136
        self.assertPathExists(rfilesx)
2475.5.2 by Marius Kruger
* blackbox/test_remove
137
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
138
        tree.remove(rfilesx, keep_files=False)
139
        self.assertNotInWorkingTree(rfilesx)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
140
        self.assertPathExists(['bx.~1~/cx.~1~', 'bx.~1~', 'ax.~1~'])
7199.3.2 by Jelmer Vernooij
Fix remaining remove tests.
141
        if (tree.supports_rename_tracking() or
142
                not tree.has_versioned_directories()):
7143.15.2 by Jelmer Vernooij
Run autopep8.
143
            self.assertPathDoesNotExist('dx.~1~')  # unchanged file
6913.4.1 by Jelmer Vernooij
Fix some remove tests for foreign branches.
144
        else:
7143.15.2 by Jelmer Vernooij
Run autopep8.
145
            self.assertPathExists('dx.~1~')  # renamed, so appears changed
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
146
        tree._validate()
2475.5.2 by Marius Kruger
* blackbox/test_remove
147
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
148
    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()
149
        """Check that changed files are removed and deleted when forced."""
2655.2.15 by Marius Kruger
Apply Alexander's comments:
150
        tree = self.get_tree(TestRemove.files)
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
151
        tree.add(TestRemove.files)
152
153
        tree.remove(TestRemove.files, keep_files=False, force=True)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
154
        self.assertRemovedAndDeleted(TestRemove.files)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
155
        self.assertPathDoesNotExist(['a.~1~', 'b.~1~/', 'b.~1~/c', 'd.~1~/'])
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
156
        tree._validate()
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
157
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
158
    def test_remove_unknown_files(self):
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
159
        """Unknown files shuld be backed up"""
2655.2.15 by Marius Kruger
Apply Alexander's comments:
160
        tree = self.get_tree(TestRemove.files)
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
161
        tree.remove(TestRemove.files, keep_files=False)
162
        self.assertRemovedAndDeleted(TestRemove.files)
7199.3.2 by Jelmer Vernooij
Fix remaining remove tests.
163
        if tree.has_versioned_directories():
164
            self.assertPathExists(TestRemove.backup_files)
165
        else:
166
            self.assertPathExists(TestRemove.backup_files_no_version_dirs)
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
167
        tree._validate()
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
168
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
169
    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()
170
        """Try to delete non-existing files."""
2655.2.15 by Marius Kruger
Apply Alexander's comments:
171
        tree = self.get_tree(TestRemove.files)
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
172
        tree.remove([''], keep_files=False)
2475.5.2 by Marius Kruger
* blackbox/test_remove
173
        tree.remove(['xyz', 'abc/def'], keep_files=False)
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
174
        tree._validate()
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
175
2655.2.12 by Marius Kruger
Remove unknown ignored files wihtout needing --force'
176
    def test_remove_unchanged_directory(self):
2655.2.8 by Marius Kruger
* workingtree_implementations/test_remove
177
        """Unchanged directories should be deleted."""
2655.2.6 by Marius Kruger
* workingtree.remove
178
        files = ['b/', 'b/c', 'b/sub_directory/', 'b/sub_directory/with_file']
2655.2.15 by Marius Kruger
Apply Alexander's comments:
179
        tree = self.get_committed_tree(files)
2655.2.6 by Marius Kruger
* workingtree.remove
180
        tree.remove('b', keep_files=False)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
181
        self.assertRemovedAndDeleted('b')
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
182
        tree._validate()
183
184
    def test_remove_absent_directory(self):
185
        """Removing a absent directory succeeds without corruption (#150438)."""
186
        paths = ['a/', 'a/b']
187
        tree = self.get_committed_tree(paths)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
188
        tree.controldir.root_transport.delete_tree('a')
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
189
        tree.remove(['a'])
190
        self.assertRemovedAndDeleted('b')
191
        tree._validate()
2292.1.30 by Marius Kruger
* Minor text fixes.
192
2655.2.12 by Marius Kruger
Remove unknown ignored files wihtout needing --force'
193
    def test_remove_unknown_ignored_files(self):
2655.2.15 by Marius Kruger
Apply Alexander's comments:
194
        """Unknown ignored files should be deleted."""
195
        tree = self.get_committed_tree(['b/'])
2655.2.12 by Marius Kruger
Remove unknown ignored files wihtout needing --force'
196
        ignores.add_runtime_ignores(["*ignored*"])
197
198
        self.build_tree(['unknown_ignored_file'])
6614.1.2 by Vincent Ladeuil
Fix assertNotEquals being deprecated by using assertNotEqual.
199
        self.assertNotEqual(None, tree.is_ignored('unknown_ignored_file'))
2655.2.12 by Marius Kruger
Remove unknown ignored files wihtout needing --force'
200
        tree.remove('unknown_ignored_file', keep_files=False)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
201
        self.assertRemovedAndDeleted('unknown_ignored_file')
2655.2.12 by Marius Kruger
Remove unknown ignored files wihtout needing --force'
202
203
        self.build_tree(['b/unknown_ignored_file', 'b/unknown_ignored_dir/'])
6614.1.2 by Vincent Ladeuil
Fix assertNotEquals being deprecated by using assertNotEqual.
204
        self.assertNotEqual(None, tree.is_ignored('b/unknown_ignored_file'))
205
        self.assertNotEqual(None, tree.is_ignored('b/unknown_ignored_dir'))
2655.2.12 by Marius Kruger
Remove unknown ignored files wihtout needing --force'
206
        tree.remove('b', keep_files=False)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
207
        self.assertRemovedAndDeleted('b')
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
208
        tree._validate()
2655.2.12 by Marius Kruger
Remove unknown ignored files wihtout needing --force'
209
3042.2.1 by Lukáš Lalinský
Fix ``bzr rm`` to not delete modified and ignored files.
210
    def test_remove_changed_ignored_files(self):
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
211
        """Changed ignored files should be backed up."""
3042.2.1 by Lukáš Lalinský
Fix ``bzr rm`` to not delete modified and ignored files.
212
        files = ['an_ignored_file']
213
        tree = self.get_tree(files)
214
        tree.add(files)
215
        ignores.add_runtime_ignores(["*ignored*"])
6614.1.2 by Vincent Ladeuil
Fix assertNotEquals being deprecated by using assertNotEqual.
216
        self.assertNotEqual(None, tree.is_ignored(files[0]))
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
217
218
        tree.remove(files, keep_files=False)
219
        self.assertNotInWorkingTree(files)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
220
        self.assertPathExists('an_ignored_file.~1~')
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
221
        tree._validate()
3042.2.1 by Lukáš Lalinský
Fix ``bzr rm`` to not delete modified and ignored files.
222
2655.2.8 by Marius Kruger
* workingtree_implementations/test_remove
223
    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
224
        """Directories with unknowns should be backed up."""
6913.4.1 by Jelmer Vernooij
Fix some remove tests for foreign branches.
225
        directories = ['a/', 'b/', 'c/', 'c/c/', 'c/blah']
2655.2.15 by Marius Kruger
Apply Alexander's comments:
226
        tree = self.get_committed_tree(directories)
2655.2.8 by Marius Kruger
* workingtree_implementations/test_remove
227
228
        self.build_tree(['a/unknown_file'])
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
229
        tree.remove('a', keep_files=False)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
230
        self.assertPathExists('a.~1~/unknown_file')
2655.2.8 by Marius Kruger
* workingtree_implementations/test_remove
231
232
        self.build_tree(['b/unknown_directory'])
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
233
        tree.remove('b', keep_files=False)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
234
        self.assertPathExists('b.~1~/unknown_directory')
2655.2.8 by Marius Kruger
* workingtree_implementations/test_remove
235
236
        self.build_tree(['c/c/unknown_file'])
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
237
        tree.remove('c/c', keep_files=False)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
238
        self.assertPathExists('c/c.~1~/unknown_file')
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
239
240
        tree.remove('c', keep_files=False)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
241
        self.assertPathExists('c.~1~/')
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
242
243
        self.assertNotInWorkingTree(directories)
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
244
        tree._validate()
2655.2.8 by Marius Kruger
* workingtree_implementations/test_remove
245
246
    def test_force_remove_directory_with_unknowns(self):
2655.2.4 by Marius Kruger
* workingtree.remove
247
        """Unchanged non-empty directories should be deleted when forced."""
2655.2.9 by Marius Kruger
* workingtree_implementations/test_remove
248
        files = ['b/', 'b/c']
2655.2.15 by Marius Kruger
Apply Alexander's comments:
249
        tree = self.get_committed_tree(files)
2655.2.4 by Marius Kruger
* workingtree.remove
250
251
        other_files = ['b/unknown_file', 'b/sub_directory/',
7143.15.2 by Jelmer Vernooij
Run autopep8.
252
                       'b/sub_directory/with_file', 'b/sub_directory/sub_directory/']
2655.2.4 by Marius Kruger
* workingtree.remove
253
        self.build_tree(other_files)
254
2655.2.9 by Marius Kruger
* workingtree_implementations/test_remove
255
        self.assertInWorkingTree(files)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
256
        self.assertPathExists(files)
2655.2.9 by Marius Kruger
* workingtree_implementations/test_remove
257
258
        tree.remove('b', keep_files=False, force=True)
259
2655.2.15 by Marius Kruger
Apply Alexander's comments:
260
        self.assertRemovedAndDeleted(files)
261
        self.assertRemovedAndDeleted(other_files)
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
262
        tree._validate()
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
263
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
264
    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
265
        """Backup directories with changed files."""
266
        files = ['b/', 'b/c']
267
        tree = self.get_committed_tree(files)
6855.4.1 by Jelmer Vernooij
Yet more bees.
268
        self.build_tree_contents([('b/c', b"some other new content!")])
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
269
270
        tree.remove('b', keep_files=False)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
271
        self.assertPathExists('b.~1~/c.~1~')
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
272
        self.assertNotInWorkingTree(files)
273
274
    def test_remove_force_directory_with_changed_file(self):
275
        """Delete directories with changed files when forced."""
276
        files = ['b/', 'b/c']
277
        tree = self.get_committed_tree(files)
6855.4.1 by Jelmer Vernooij
Yet more bees.
278
        self.build_tree_contents([('b/c', b"some other new content!")])
2292.1.20 by Marius Kruger
move test_workingtree.TestRemove to workingtree_implementations/test_remove
279
2655.2.15 by Marius Kruger
Apply Alexander's comments:
280
        # see if we can force it now..
2655.2.9 by Marius Kruger
* workingtree_implementations/test_remove
281
        tree.remove('b', keep_files=False, force=True)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
282
        self.assertRemovedAndDeleted(files)
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
283
        tree._validate()
1551.15.11 by Aaron Bentley
Bugfix WorkingTree.remove to handle subtrees, and non-cwd trees
284
2668.3.1 by Daniel Watkins
Added test to fix bug #129880.
285
    def test_remove_directory_with_changed_emigrated_file(self):
286
        # As per bug #129880
287
        tree = self.make_branch_and_tree('.')
7143.15.2 by Jelmer Vernooij
Run autopep8.
288
        self.build_tree_contents(
289
            [('somedir/',), (b'somedir/file', b'contents')])
2668.3.1 by Daniel Watkins
Added test to fix bug #129880.
290
        tree.add(['somedir', 'somedir/file'])
291
        tree.commit(message="first")
6855.4.1 by Jelmer Vernooij
Yet more bees.
292
        self.build_tree_contents([('somedir/file', b'changed')])
2668.3.1 by Daniel Watkins
Added test to fix bug #129880.
293
        tree.rename_one('somedir/file', 'moved-file')
294
        tree.remove('somedir', keep_files=False)
295
        self.assertNotInWorkingTree('somedir')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
296
        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
297
        self.assertInWorkingTree('moved-file')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
298
        self.assertPathExists('moved-file')
2668.3.1 by Daniel Watkins
Added test to fix bug #129880.
299
2655.2.11 by Marius Kruger
* Update NEWS
300
    def test_remove_directory_with_renames(self):
301
        """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
302
6913.4.1 by Jelmer Vernooij
Fix some remove tests for foreign branches.
303
        files = ['a/', 'a/file', 'a/directory/', 'a/directory/stuff', 'b/']
2655.2.10 by Marius Kruger
add test for removing a direcory with something that has been moved out
304
        files_to_move = ['a/file', 'a/directory/']
305
2655.2.15 by Marius Kruger
Apply Alexander's comments:
306
        tree = self.get_committed_tree(files)
307
        # move stuff from a=>b
2655.2.10 by Marius Kruger
add test for removing a direcory with something that has been moved out
308
        tree.move(['a/file', 'a/directory'], to_dir='b')
309
310
        moved_files = ['b/file', 'b/directory/']
2655.2.15 by Marius Kruger
Apply Alexander's comments:
311
        self.assertRemovedAndDeleted(files_to_move)
2655.2.10 by Marius Kruger
add test for removing a direcory with something that has been moved out
312
        self.assertInWorkingTree(moved_files)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
313
        self.assertPathExists(moved_files)
2655.2.10 by Marius Kruger
add test for removing a direcory with something that has been moved out
314
2655.2.11 by Marius Kruger
* Update NEWS
315
        # 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
316
        tree.remove('a', keep_files=False)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
317
        self.assertRemovedAndDeleted(['a/'])
2655.2.11 by Marius Kruger
* Update NEWS
318
319
        # check if it works with renames in
320
        tree.remove('b', keep_files=False)
2655.2.15 by Marius Kruger
Apply Alexander's comments:
321
        self.assertRemovedAndDeleted(['b/'])
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
322
        tree._validate()
2655.2.10 by Marius Kruger
add test for removing a direcory with something that has been moved out
323
1551.15.11 by Aaron Bentley
Bugfix WorkingTree.remove to handle subtrees, and non-cwd trees
324
    def test_non_cwd(self):
325
        tree = self.make_branch_and_tree('tree')
326
        self.build_tree(['tree/dir/', 'tree/dir/file'])
327
        tree.add(['dir', 'dir/file'])
328
        tree.commit('add file')
329
        tree.remove('dir/', keep_files=False)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
330
        self.assertPathDoesNotExist('tree/dir/file')
2655.2.15 by Marius Kruger
Apply Alexander's comments:
331
        self.assertNotInWorkingTree('tree/dir/file', 'tree')
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
332
        tree._validate()
2967.5.8 by Daniel Watkins
Moved tests to correct location.
333
334
    def test_remove_uncommitted_removed_file(self):
335
        # As per bug #152811
336
        tree = self.get_committed_tree(['a'])
337
        tree.remove('a', keep_files=False)
338
        tree.remove('a', keep_files=False)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
339
        self.assertPathDoesNotExist('a')
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
340
        tree._validate()
2967.5.8 by Daniel Watkins
Moved tests to correct location.
341
342
    def test_remove_file_and_containing_dir(self):
343
        tree = self.get_committed_tree(['config/', 'config/file'])
344
        tree.remove('config/file', keep_files=False)
345
        tree.remove('config', keep_files=False)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
346
        self.assertPathDoesNotExist('config/file')
347
        self.assertPathDoesNotExist('config')
3585.2.1 by Robert Collins
Create acceptance test for bug 150438.
348
        tree._validate()
3719.1.1 by Vincent Ladeuil
Fix bug #272648
349
350
    def test_remove_dir_before_bzr(self):
351
        # As per bug #272648. Note that a file must be present in the directory
352
        # or the bug doesn't manifest itself.
353
        tree = self.get_committed_tree(['.aaa/', '.aaa/file'])
354
        tree.remove('.aaa/', keep_files=False)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
355
        self.assertPathDoesNotExist('.aaa/file')
356
        self.assertPathDoesNotExist('.aaa')
3719.1.1 by Vincent Ladeuil
Fix bug #272648
357
        tree._validate()