31
def getTree(self, files=None):
33
files = TestRemove.files
32
34
tree = self.make_branch_and_tree('.')
33
self.build_tree(TestRemove.files)
35
self.build_tree(files)
36
self.failUnlessExists(files)
39
def getCommittedTree(self, message, files):
40
tree = self.getTree(files)
43
self.assertInWorkingTree(files)
36
46
def test_remove_keep(self):
169
179
tree.remove(['xyz', 'abc/def'], keep_files=False)
171
181
def test_remove_nonempty_directory(self):
172
"""Unchanged non-empty directories should be deleted."""
173
tree = self.make_branch_and_tree('.')
182
"""Unchanged directories should be deleted."""
174
183
files = ['b/', 'b/c', 'b/sub_directory/', 'b/sub_directory/with_file']
175
self.build_tree(files)
184
tree = self.getTree(files)
177
186
tree.commit("make sure b is versioned")
178
187
self.assertInWorkingTree(files)
179
188
self.failUnlessExists(files)
180
self.build_tree(['b/unknown_directory/', 'b/unknown_directory/ud2/'])
181
189
tree.remove('b', keep_files=False)
182
190
self.assertNotInWorkingTree('b')
183
191
self.failIfExists('b')
185
def test_remove_nonempty_directory_with_unknowns(self):
186
"""Unchanged non-empty directories should not be deleted."""
187
tree = self.getTree()
188
tree.add(TestRemove.files)
189
tree.commit("make sure b is versioned")
190
self.assertInWorkingTree(TestRemove.files)
191
self.failUnlessExists(TestRemove.files)
192
self.build_tree(['b/my_unknown_file'])
194
err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
195
TestRemove.b, keep_files=False)
196
self.assertContainsRe(err.changes_as_text,
197
'(?s)unknown:.*b/my_unknown_file')
199
self.assertInWorkingTree(TestRemove.b)
200
self.failUnlessExists(TestRemove.b)
202
def test_force_remove_nonempty_directory(self):
193
def test_dont_remove_directory_with_unknowns(self):
194
"""Directories with unknowns should not be deleted."""
195
directories = ['a/', 'b/', 'c/', 'c/c/']
196
tree = self.getCommittedTree("make sure directories is versioned",
199
self.build_tree(['a/unknown_file'])
200
err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
201
'a', keep_files=False)
202
self.assertContainsRe(err.changes_as_text,
203
'(?s)unknown:.*a/unknown_file')
205
self.build_tree(['b/unknown_directory'])
206
err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
207
'b', keep_files=False)
208
self.assertContainsRe(err.changes_as_text,
209
'(?s)unknown:.*b/unknown_directory')
211
self.build_tree(['c/c/unknown_file'])
212
err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
213
'c/c', keep_files=False)
214
self.assertContainsRe(err.changes_as_text,
215
'(?s)unknown:.*c/c/unknown_file')
217
self.assertInWorkingTree(directories)
218
self.failUnlessExists(directories)
220
def test_force_remove_directory_with_unknowns(self):
203
221
"""Unchanged non-empty directories should be deleted when forced."""
204
222
tree = self.getTree()
205
223
tree.add(TestRemove.files)