~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Marius Kruger
  • Date: 2010-07-09 22:45:25 UTC
  • mto: (5384.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5385.
  • Revision ID: marius.kruger@enerweb.co.za-20100709224525-a0bijmcw3dw02r8g
* make the backup file name generator in bzrdir available to others
* Whenever bzr is asked to delete stuff, back it up if the content is not in version control.
* Update whitebox tests (Did them first btw. Vila's voice keeps ringing in my head)
* deprecate the now unused BzrRemoveChangedFilesError

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
        tree._validate()
73
73
 
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~/'])
85
82
        tree._validate()
86
83
 
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~')
97
92
        tree._validate()
98
93
 
99
94
    def test_remove_deleted_files(self):
122
117
        tree._validate()
123
118
 
124
119
    def test_remove_renamed_changed_files(self):
125
 
        """Check that files are not removed if they are renamed and changed."""
 
120
        """Check that files that are renamed and changed are backed up."""
126
121
        tree = self.get_committed_tree(TestRemove.files)
127
122
 
128
123
        for f in TestRemove.rfiles:
133
128
        self.assertInWorkingTree(rfilesx)
134
129
        self.failUnlessExists(rfilesx)
135
130
 
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
142
135
        tree._validate()
143
136
 
144
137
    def test_force_remove_changed_files(self):
149
142
 
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~/'])
152
146
        tree._validate()
153
147
 
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~/'])
161
154
        tree._validate()
162
155
 
163
156
    def test_remove_nonexisting_files(self):
202
195
        tree._validate()
203
196
 
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)
208
201
        tree.add(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)
 
205
 
 
206
        tree.remove(files, keep_files=False)
 
207
        self.assertNotInWorkingTree(files)
 
208
        self.failUnlessExists('an_ignored_file.~1~')
217
209
        tree._validate()
218
210
 
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)
223
215
 
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')
229
219
 
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')
235
223
 
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')
241
 
 
242
 
        self.assertInWorkingTree(directories)
243
 
        self.failUnlessExists(directories)
 
225
        tree.remove('c/c', keep_files=False)
 
226
        self.failUnlessExists('c/c.~1~/unknown_file')
 
227
 
 
228
        tree.remove('c', keep_files=False)
 
229
        self.failUnlessExists('c.~1~/')
 
230
 
 
231
        self.assertNotInWorkingTree(directories)
244
232
        tree._validate()
245
233
 
246
234
    def test_force_remove_directory_with_unknowns(self):
262
250
        tree._validate()
263
251
 
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!")])
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)
 
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!")])
 
257
 
 
258
        tree.remove('b', keep_files=False)
 
259
        self.failUnlessExists('b.~1~/c.~1~')
 
260
        self.assertNotInWorkingTree(files)
 
261
 
 
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!")])
275
267
 
276
268
        # see if we can force it now..
277
269
        tree.remove('b', keep_files=False, force=True)