~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_workingtree/test_remove.py

`bzr remove` now just backs up changed files instead of annoying you

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2007-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
24
24
 
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~/']
27
28
 
28
29
    def get_tree(self, files):
29
30
        tree = self.make_branch_and_tree('.')
72
73
        tree._validate()
73
74
 
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)
85
83
        tree._validate()
86
84
 
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~')
97
93
        tree._validate()
98
94
 
99
95
    def test_remove_deleted_files(self):
122
118
        tree._validate()
123
119
 
124
120
    def test_remove_renamed_changed_files(self):
125
 
        """Check that files are not removed if they are renamed and changed."""
 
121
        """Check that files that are renamed and changed are backed up."""
126
122
        tree = self.get_committed_tree(TestRemove.files)
127
123
 
128
124
        for f in TestRemove.rfiles:
133
129
        self.assertInWorkingTree(rfilesx)
134
130
        self.failUnlessExists(rfilesx)
135
131
 
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
142
136
        tree._validate()
143
137
 
144
138
    def test_force_remove_changed_files(self):
149
143
 
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~/'])
152
147
        tree._validate()
153
148
 
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)
161
155
        tree._validate()
162
156
 
163
157
    def test_remove_nonexisting_files(self):
202
196
        tree._validate()
203
197
 
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)
208
202
        tree.add(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)
 
206
 
 
207
        tree.remove(files, keep_files=False)
 
208
        self.assertNotInWorkingTree(files)
 
209
        self.failUnlessExists('an_ignored_file.~1~')
217
210
        tree._validate()
218
211
 
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)
223
216
 
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')
229
220
 
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')
235
224
 
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')
241
 
 
242
 
        self.assertInWorkingTree(directories)
243
 
        self.failUnlessExists(directories)
 
226
        tree.remove('c/c', keep_files=False)
 
227
        self.failUnlessExists('c/c.~1~/unknown_file')
 
228
 
 
229
        tree.remove('c', keep_files=False)
 
230
        self.failUnlessExists('c.~1~/')
 
231
 
 
232
        self.assertNotInWorkingTree(directories)
244
233
        tree._validate()
245
234
 
246
235
    def test_force_remove_directory_with_unknowns(self):
262
251
        tree._validate()
263
252
 
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!")])
269
 
 
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!")])
 
258
 
 
259
        tree.remove('b', keep_files=False)
 
260
        self.failUnlessExists('b.~1~/c.~1~')
 
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!")])
275
268
 
276
269
        # see if we can force it now..
277
270
        tree.remove('b', keep_files=False, force=True)