25
25
files = ['a', 'b/', 'b/c', 'd/']
26
26
rfiles = ['b/c', 'b', 'a', 'd']
27
backup_files = ['a.~1~', 'b.~1~/', 'b.~1~/c.~1~', 'd.~1~/']
28
29
def get_tree(self, files):
29
30
tree = self.make_branch_and_tree('.')
74
75
def test_remove_added_files(self):
75
"""Removal of newly added files must fail."""
76
"""Removal of newly added files must back them up."""
76
77
tree = self.get_tree(TestRemove.files)
77
78
tree.add(TestRemove.files)
78
79
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)
80
tree.remove(TestRemove.files, keep_files=False)
81
self.assertNotInWorkingTree(TestRemove.files)
82
self.failUnlessExists(TestRemove.backup_files)
87
85
def test_remove_changed_file(self):
88
"""Removal of a changed files must fail."""
86
"""Removal of changed files must back it up."""
89
87
tree = self.get_committed_tree(['a'])
90
88
self.build_tree_contents([('a', "some other new content!")])
91
89
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')
90
tree.remove('a', keep_files=False)
91
self.assertNotInWorkingTree(TestRemove.files)
92
self.failUnlessExists('a.~1~')
99
95
def test_remove_deleted_files(self):
133
129
self.assertInWorkingTree(rfilesx)
134
130
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)
132
tree.remove(rfilesx, keep_files=False)
133
self.assertNotInWorkingTree(rfilesx)
134
self.failUnlessExists(['bx.~1~/cx.~1~', 'bx.~1~', 'ax.~1~'])
135
self.failIfExists('dx.~1~') # unchanged file
144
138
def test_force_remove_changed_files(self):
150
144
tree.remove(TestRemove.files, keep_files=False, force=True)
151
145
self.assertRemovedAndDeleted(TestRemove.files)
146
self.failIfExists(['a.~1~', 'b.~1~/', 'b.~1~/c', 'd.~1~/'])
154
149
def test_remove_unknown_files(self):
155
"""Try to delete unknown files."""
150
"""Unknown files shuld be backed up"""
156
151
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.*')
152
tree.remove(TestRemove.files, keep_files=False)
153
self.assertRemovedAndDeleted(TestRemove.files)
154
self.failUnlessExists(TestRemove.backup_files)
163
157
def test_remove_nonexisting_files(self):
204
198
def test_remove_changed_ignored_files(self):
205
"""Changed ignored files should not be deleted."""
199
"""Changed ignored files should be backed up."""
206
200
files = ['an_ignored_file']
207
201
tree = self.get_tree(files)
209
203
ignores.add_runtime_ignores(["*ignored*"])
210
204
self.assertInWorkingTree(files)
211
205
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)
207
tree.remove(files, keep_files=False)
208
self.assertNotInWorkingTree(files)
209
self.failUnlessExists('an_ignored_file.~1~')
219
212
def test_dont_remove_directory_with_unknowns(self):
220
"""Directories with unknowns should not be deleted."""
213
"""Directories with unknowns should be backed up."""
221
214
directories = ['a/', 'b/', 'c/', 'c/c/']
222
215
tree = self.get_committed_tree(directories)
224
217
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')
218
tree.remove('a', keep_files=False)
219
self.failUnlessExists('a.~1~/unknown_file')
230
221
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')
222
tree.remove('b', keep_files=False)
223
self.failUnlessExists('b.~1~/unknown_directory')
236
225
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)
226
tree.remove('c/c', keep_files=False)
227
self.failUnlessExists('c/c.~1~/unknown_file')
229
tree.remove('c', keep_files=False)
230
self.failUnlessExists('c.~1~/')
232
self.assertNotInWorkingTree(directories)
246
235
def test_force_remove_directory_with_unknowns(self):
264
253
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)
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!")])
259
tree.remove('b', keep_files=False)
260
self.failUnlessExists('b.~1~/c.~1~')
261
self.assertNotInWorkingTree(files)
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!")])
276
269
# see if we can force it now..
277
270
tree.remove('b', keep_files=False, force=True)