~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2009-03-24 05:21:02 UTC
  • mfrom: (4192 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4202.
  • Revision ID: mbp@sourcefrog.net-20090324052102-8kk087b32tep3d9h
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008 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
67
67
    def test_remove_unchanged_files(self):
68
68
        """Check that unchanged files are removed and deleted."""
69
69
        tree = self.get_committed_tree(TestRemove.files)
70
 
 
71
70
        tree.remove(TestRemove.files, keep_files=False)
72
71
        self.assertRemovedAndDeleted(TestRemove.files)
 
72
        tree._validate()
73
73
 
74
74
    def test_remove_added_files(self):
75
75
        """Removal of newly added files must fail."""
82
82
            '(?s)added:.*a.*b/.*b/c.*d/')
83
83
        self.assertInWorkingTree(TestRemove.files)
84
84
        self.failUnlessExists(TestRemove.files)
 
85
        tree._validate()
85
86
 
86
87
    def test_remove_changed_file(self):
87
88
        """Removal of a changed files must fail."""
93
94
        self.assertContainsRe(err.changes_as_text, '(?s)modified:.*a')
94
95
        self.assertInWorkingTree('a')
95
96
        self.failUnlessExists('a')
 
97
        tree._validate()
96
98
 
97
99
    def test_remove_deleted_files(self):
98
100
        """Check that files are removed if they don't exist any more."""
101
103
            osutils.delete_any(f)
102
104
        self.assertInWorkingTree(TestRemove.files)
103
105
        self.failIfExists(TestRemove.files)
104
 
 
105
106
        tree.remove(TestRemove.files, keep_files=False)
106
107
        self.assertRemovedAndDeleted(TestRemove.files)
 
108
        tree._validate()
107
109
 
108
110
    def test_remove_renamed_files(self):
109
111
        """Check that files are removed even if they are renamed."""
117
119
 
118
120
        tree.remove(rfilesx, keep_files=False)
119
121
        self.assertRemovedAndDeleted(rfilesx)
 
122
        tree._validate()
120
123
 
121
124
    def test_remove_renamed_changed_files(self):
122
125
        """Check that files are not removed if they are renamed and changed."""
136
139
            '(?s)modified:.*ax.*bx/cx')
137
140
        self.assertInWorkingTree(rfilesx)
138
141
        self.failUnlessExists(rfilesx)
 
142
        tree._validate()
139
143
 
140
144
    def test_force_remove_changed_files(self):
141
145
        """Check that changed files are removed and deleted when forced."""
145
149
 
146
150
        tree.remove(TestRemove.files, keep_files=False, force=True)
147
151
        self.assertRemovedAndDeleted(TestRemove.files)
 
152
        tree._validate()
148
153
 
149
154
    def test_remove_unknown_files(self):
150
155
        """Try to delete unknown files."""
153
158
            TestRemove.files, keep_files=False)
154
159
        self.assertContainsRe(err.changes_as_text,
155
160
            '(?s)unknown:.*d/.*b/c.*b/.*a.*')
 
161
        tree._validate()
156
162
 
157
163
    def test_remove_nonexisting_files(self):
158
164
        """Try to delete non-existing files."""
159
165
        tree = self.get_tree(TestRemove.files)
160
166
        tree.remove([''], keep_files=False)
161
167
        tree.remove(['xyz', 'abc/def'], keep_files=False)
 
168
        tree._validate()
162
169
 
163
170
    def test_remove_unchanged_directory(self):
164
171
        """Unchanged directories should be deleted."""
166
173
        tree = self.get_committed_tree(files)
167
174
        tree.remove('b', keep_files=False)
168
175
        self.assertRemovedAndDeleted('b')
 
176
        tree._validate()
 
177
 
 
178
    def test_remove_absent_directory(self):
 
179
        """Removing a absent directory succeeds without corruption (#150438)."""
 
180
        paths = ['a/', 'a/b']
 
181
        tree = self.get_committed_tree(paths)
 
182
        self.get_transport('.').delete_tree('a')
 
183
        tree.remove(['a'])
 
184
        self.assertRemovedAndDeleted('b')
 
185
        tree._validate()
169
186
 
170
187
    def test_remove_unknown_ignored_files(self):
171
188
        """Unknown ignored files should be deleted."""
182
199
        self.assertNotEquals(None, tree.is_ignored('b/unknown_ignored_dir'))
183
200
        tree.remove('b', keep_files=False)
184
201
        self.assertRemovedAndDeleted('b')
 
202
        tree._validate()
185
203
 
186
204
    def test_remove_changed_ignored_files(self):
187
205
        """Changed ignored files should not be deleted."""
196
214
        self.assertContainsRe(err.changes_as_text,
197
215
            '(?s)added:.*' + files[0])
198
216
        self.assertInWorkingTree(files)
 
217
        tree._validate()
199
218
 
200
219
    def test_dont_remove_directory_with_unknowns(self):
201
220
        """Directories with unknowns should not be deleted."""
222
241
 
223
242
        self.assertInWorkingTree(directories)
224
243
        self.failUnlessExists(directories)
 
244
        tree._validate()
225
245
 
226
246
    def test_force_remove_directory_with_unknowns(self):
227
247
        """Unchanged non-empty directories should be deleted when forced."""
239
259
 
240
260
        self.assertRemovedAndDeleted(files)
241
261
        self.assertRemovedAndDeleted(other_files)
 
262
        tree._validate()
242
263
 
243
264
    def test_remove_directory_with_changed_file(self):
244
265
        """Refuse to delete directories with changed files."""
255
276
        # see if we can force it now..
256
277
        tree.remove('b', keep_files=False, force=True)
257
278
        self.assertRemovedAndDeleted(files)
 
279
        tree._validate()
258
280
 
259
281
    def test_remove_directory_with_renames(self):
260
282
        """Delete directory with renames in or out."""
278
300
        # check if it works with renames in
279
301
        tree.remove('b', keep_files=False)
280
302
        self.assertRemovedAndDeleted(['b/'])
 
303
        tree._validate()
281
304
 
282
305
    def test_non_cwd(self):
283
306
        tree = self.make_branch_and_tree('tree')
287
310
        tree.remove('dir/', keep_files=False)
288
311
        self.failIfExists('tree/dir/file')
289
312
        self.assertNotInWorkingTree('tree/dir/file', 'tree')
 
313
        tree._validate()
290
314
 
291
315
    def test_remove_uncommitted_removed_file(self):
292
316
        # As per bug #152811
294
318
        tree.remove('a', keep_files=False)
295
319
        tree.remove('a', keep_files=False)
296
320
        self.failIfExists('a')
 
321
        tree._validate()
297
322
 
298
323
    def test_remove_file_and_containing_dir(self):
299
324
        tree = self.get_committed_tree(['config/', 'config/file'])
301
326
        tree.remove('config', keep_files=False)
302
327
        self.failIfExists('config/file')
303
328
        self.failIfExists('config')
 
329
        tree._validate()
 
330
 
 
331
    def test_remove_dir_before_bzr(self):
 
332
        # As per bug #272648. Note that a file must be present in the directory
 
333
        # or the bug doesn't manifest itself.
 
334
        tree = self.get_committed_tree(['.aaa/', '.aaa/file'])
 
335
        tree.remove('.aaa/', keep_files=False)
 
336
        self.failIfExists('.aaa/file')
 
337
        self.failIfExists('.aaa')
 
338
        tree._validate()