74
74
def test_remove_added_files(self):
75
"""Removal of newly added files must fail."""
75
"""Removal of newly added files must back them up."""
76
76
tree = self.get_tree(TestRemove.files)
77
77
tree.add(TestRemove.files)
78
78
self.assertInWorkingTree(TestRemove.files)
79
err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
80
TestRemove.files, keep_files=False)
81
self.assertContainsRe(err.changes_as_text,
82
'(?s)added:.*a.*b/.*b/c.*d/')
83
self.assertInWorkingTree(TestRemove.files)
84
self.failUnlessExists(TestRemove.files)
79
tree.remove(TestRemove.files, keep_files=False)
80
self.assertNotInWorkingTree(TestRemove.files)
81
self.failUnlessExists(['a.~1~', 'b.~1~/', 'b.~1~/c.~1~', 'd.~1~/'])
87
84
def test_remove_changed_file(self):
88
"""Removal of a changed files must fail."""
85
"""Removal of changed files must back it up."""
89
86
tree = self.get_committed_tree(['a'])
90
87
self.build_tree_contents([('a', "some other new content!")])
91
88
self.assertInWorkingTree('a')
92
err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
93
'a', keep_files=False)
94
self.assertContainsRe(err.changes_as_text, '(?s)modified:.*a')
95
self.assertInWorkingTree('a')
96
self.failUnlessExists('a')
89
tree.remove('a', keep_files=False)
90
self.assertNotInWorkingTree(TestRemove.files)
91
self.failUnlessExists('a.~1~')
99
94
def test_remove_deleted_files(self):
133
128
self.assertInWorkingTree(rfilesx)
134
129
self.failUnlessExists(rfilesx)
136
err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
137
rfilesx, keep_files=False)
138
self.assertContainsRe(err.changes_as_text,
139
'(?s)modified:.*ax.*bx/cx')
140
self.assertInWorkingTree(rfilesx)
141
self.failUnlessExists(rfilesx)
131
tree.remove(rfilesx, keep_files=False)
132
self.assertNotInWorkingTree(rfilesx)
133
self.failUnlessExists(['bx.~1~/cx.~1~', 'bx.~1~', 'ax.~1~'])
134
self.failIfExists('dx.~1~') # unchanged file
144
137
def test_force_remove_changed_files(self):
150
143
tree.remove(TestRemove.files, keep_files=False, force=True)
151
144
self.assertRemovedAndDeleted(TestRemove.files)
145
self.failIfExists(['a.~1~', 'b.~1~/', 'b.~1~/c', 'd.~1~/'])
154
148
def test_remove_unknown_files(self):
155
"""Try to delete unknown files."""
149
"""Unknown files shuld be backed up"""
156
150
tree = self.get_tree(TestRemove.files)
157
err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
158
TestRemove.files, keep_files=False)
159
self.assertContainsRe(err.changes_as_text,
160
'(?s)unknown:.*d/.*b/c.*b/.*a.*')
151
tree.remove(TestRemove.files, keep_files=False)
152
self.assertRemovedAndDeleted(TestRemove.files)
153
self.failUnlessExists(['a.~1~', 'b.~1~/', 'b.~1~/c.~1~', 'd.~1~/'])
163
156
def test_remove_nonexisting_files(self):
204
197
def test_remove_changed_ignored_files(self):
205
"""Changed ignored files should not be deleted."""
198
"""Changed ignored files should be backed up."""
206
199
files = ['an_ignored_file']
207
200
tree = self.get_tree(files)
209
202
ignores.add_runtime_ignores(["*ignored*"])
210
203
self.assertInWorkingTree(files)
211
204
self.assertNotEquals(None, tree.is_ignored(files[0]))
212
err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
213
files, keep_files=False)
214
self.assertContainsRe(err.changes_as_text,
215
'(?s)added:.*' + files[0])
216
self.assertInWorkingTree(files)
206
tree.remove(files, keep_files=False)
207
self.assertNotInWorkingTree(files)
208
self.failUnlessExists('an_ignored_file.~1~')
219
211
def test_dont_remove_directory_with_unknowns(self):
220
"""Directories with unknowns should not be deleted."""
212
"""Directories with unknowns should be backed up."""
221
213
directories = ['a/', 'b/', 'c/', 'c/c/']
222
214
tree = self.get_committed_tree(directories)
224
216
self.build_tree(['a/unknown_file'])
225
err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
226
'a', keep_files=False)
227
self.assertContainsRe(err.changes_as_text,
228
'(?s)unknown:.*a/unknown_file')
217
tree.remove('a', keep_files=False)
218
self.failUnlessExists('a.~1~/unknown_file')
230
220
self.build_tree(['b/unknown_directory'])
231
err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
232
'b', keep_files=False)
233
self.assertContainsRe(err.changes_as_text,
234
'(?s)unknown:.*b/unknown_directory')
221
tree.remove('b', keep_files=False)
222
self.failUnlessExists('b.~1~/unknown_directory')
236
224
self.build_tree(['c/c/unknown_file'])
237
err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
238
'c/c', keep_files=False)
239
self.assertContainsRe(err.changes_as_text,
240
'(?s)unknown:.*c/c/unknown_file')
242
self.assertInWorkingTree(directories)
243
self.failUnlessExists(directories)
225
tree.remove('c/c', keep_files=False)
226
self.failUnlessExists('c/c.~1~/unknown_file')
228
tree.remove('c', keep_files=False)
229
self.failUnlessExists('c.~1~/')
231
self.assertNotInWorkingTree(directories)
246
234
def test_force_remove_directory_with_unknowns(self):
264
252
def test_remove_directory_with_changed_file(self):
265
"""Refuse to delete directories with changed files."""
266
files = ['b/', 'b/c']
267
tree = self.get_committed_tree(files)
268
self.build_tree_contents([('b/c', "some other new content!")])
270
err = self.assertRaises(errors.BzrRemoveChangedFilesError, tree.remove,
271
'b', keep_files=False)
272
self.assertContainsRe(err.changes_as_text, '(?s)modified:.*b/c')
273
self.assertInWorkingTree(files)
274
self.failUnlessExists(files)
253
"""Backup directories with changed files."""
254
files = ['b/', 'b/c']
255
tree = self.get_committed_tree(files)
256
self.build_tree_contents([('b/c', "some other new content!")])
258
tree.remove('b', keep_files=False)
259
self.failUnlessExists('b.~1~/c.~1~')
260
self.assertNotInWorkingTree(files)
262
def test_remove_force_directory_with_changed_file(self):
263
"""Delete directories with changed files when forced."""
264
files = ['b/', 'b/c']
265
tree = self.get_committed_tree(files)
266
self.build_tree_contents([('b/c', "some other new content!")])
276
268
# see if we can force it now..
277
269
tree.remove('b', keep_files=False, force=True)