~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge bzr.dev into cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 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
18
18
import os
19
19
import sys
20
20
 
21
 
from bzrlib.tests import (
22
 
    script,
23
 
    SymlinkFeature,
24
 
    TestCaseWithTransport,
25
 
    TestSkipped,
26
 
    )
 
21
from bzrlib.tests import SymlinkFeature, TestSkipped
 
22
from bzrlib.tests.blackbox import ExternalBase
27
23
from bzrlib.workingtree import WorkingTree
28
24
from bzrlib import osutils
29
25
 
35
31
files=(a, b, c, d)
36
32
 
37
33
 
38
 
class TestRemove(TestCaseWithTransport):
 
34
class TestRemove(ExternalBase):
39
35
 
40
36
    def _make_tree_and_add(self, paths):
41
37
        tree = self.make_branch_and_tree('.')
53
49
        for f in files:
54
50
            id=f+_id
55
51
            self.assertNotInWorkingTree(f)
56
 
            self.assertPathDoesNotExist(f)
 
52
            self.failIfExists(f)
57
53
 
58
54
    def assertFilesUnversioned(self, files):
59
55
        for f in files:
60
56
            self.assertNotInWorkingTree(f)
61
 
            self.assertPathExists(f)
 
57
            self.failUnlessExists(f)
62
58
 
63
59
    def changeFile(self, file_name):
64
60
        f = file(file_name, 'ab')
65
61
        f.write("\nsome other new content!")
66
62
        f.close()
67
63
 
68
 
    def run_bzr_remove_changed_files(self, files_to_remove, working_dir=None):
69
 
        self.run_bzr(['remove'] + list(files_to_remove),
70
 
           working_dir=working_dir)
 
64
    def run_bzr_remove_changed_files(self, error_regexes, files_to_remove,
 
65
                                     working_dir=None):
 
66
        error_regexes.extend(["Can't safely remove modified or unknown files:",
 
67
            'Use --keep to not delete them,'
 
68
            ' or --force to delete them regardless.'
 
69
            ])
 
70
        self.run_bzr_error(error_regexes,
 
71
                           ['remove'] + list(files_to_remove),
 
72
                           working_dir=working_dir)
 
73
        #see if we can force it now
 
74
        self.run_bzr(['remove', '--force'] + list(files_to_remove),
 
75
                     working_dir=working_dir)
71
76
 
72
77
    def test_remove_new_no_files_specified(self):
73
78
        tree = self.make_branch_and_tree('.')
80
85
        self.assertEqual('', err)
81
86
        self.assertEqual('', out)
82
87
        self.assertInWorkingTree('foo', tree=tree)
83
 
        self.assertPathExists('foo')
 
88
        self.failUnlessExists('foo')
84
89
 
85
90
    def test_remove_no_files_specified_missing_dir_and_contents(self):
86
91
        tree = self._make_tree_and_add(
94
99
            err)
95
100
        # non-missing paths not touched:
96
101
        self.assertInWorkingTree('foo', tree=tree)
97
 
        self.assertPathExists('foo')
 
102
        self.failUnlessExists('foo')
98
103
        self.assertInWorkingTree('dir', tree=tree)
99
 
        self.assertPathExists('dir')
 
104
        self.failUnlessExists('dir')
100
105
        # missing files unversioned
101
106
        self.assertNotInWorkingTree('dir/missing', tree=tree)
102
107
        self.assertNotInWorkingTree('dir/missing/child', tree=tree)
120
125
        self.assertEqual('removed bar\n', err)
121
126
        # non-missing files not touched:
122
127
        self.assertInWorkingTree('foo', tree=tree)
123
 
        self.assertPathExists('foo')
 
128
        self.failUnlessExists('foo')
124
129
        # missing files unversioned
125
130
        self.assertNotInWorkingTree('bar', tree=tree)
126
131
 
135
140
        self.assertEqual('removed linkname\n', err)
136
141
        # non-missing files not touched:
137
142
        self.assertInWorkingTree('foo', tree=tree)
138
 
        self.assertPathExists('foo')
 
143
        self.failUnlessExists('foo')
139
144
        # missing files unversioned
140
145
        self.assertNotInWorkingTree('linkname', tree=tree)
141
146
 
172
177
    def test_remove_unversioned_files(self):
173
178
        self.build_tree(files)
174
179
        tree = self.make_branch_and_tree('.')
175
 
        self.run_bzr_remove_changed_files(files)
 
180
        self.run_bzr_remove_changed_files(
 
181
            ['unknown:[.\s]*d/[.\s]*b/c[.\s]*b/[.\s]*a'], files)
176
182
 
177
183
    def test_remove_changed_files(self):
178
184
        tree = self._make_tree_and_add(files)
179
185
        self.run_bzr("commit -m 'added files'")
180
186
        self.changeFile(a)
181
187
        self.changeFile(c)
182
 
        self.run_bzr_remove_changed_files(files)
 
188
        self.run_bzr_remove_changed_files(['modified:[.\s]*a[.\s]*b/c'], files)
183
189
 
184
190
    def test_remove_changed_ignored_files(self):
185
191
        tree = self._make_tree_and_add(['a'])
186
192
        self.run_bzr(['ignore', 'a'])
187
 
        self.run_bzr_remove_changed_files(['a'])
 
193
        self.run_bzr_remove_changed_files(['added:[.\s]*a'], ['a'])
188
194
 
189
195
    def test_remove_changed_files_from_child_dir(self):
190
196
        if sys.platform == 'win32':
194
200
        self.changeFile(a)
195
201
        self.changeFile(c)
196
202
        self.run_bzr_remove_changed_files(
 
203
            ['modified:[.\s]*a[.\s]*b/c'],
197
204
            ['../a', 'c', '.', '../d'], working_dir='b')
198
205
        self.assertNotInWorkingTree(files)
199
 
        self.assertPathDoesNotExist(files)
 
206
        self.failIfExists(files)
200
207
 
201
208
    def test_remove_keep_unversioned_files(self):
202
209
        self.build_tree(files)
204
211
        self.run_bzr('remove --keep a', error_regexes=["a is not versioned."])
205
212
        self.assertFilesUnversioned(files)
206
213
 
207
 
    def test_remove_no_backup_unversioned_files(self):
208
 
        self.build_tree(files)
209
 
        tree = self.make_branch_and_tree('.')
210
 
        script.ScriptRunner().run_script(self, '''
211
 
        $ bzr remove --no-backup a b/ b/c d/
212
 
        2>deleted d
213
 
        2>removed b/c (but kept a copy: b/c.~1~)
214
 
        2>deleted b
215
 
        2>deleted a
216
 
        ''')
217
 
        self.assertFilesDeleted(files)
218
 
 
219
214
    def test_remove_force_unversioned_files(self):
220
215
        self.build_tree(files)
221
216
        tree = self.make_branch_and_tree('.')
222
 
        script.ScriptRunner().run_script(self, '''
223
 
        $ bzr remove --force a b/ b/c d/
224
 
        2>(The --force option is deprecated, rather use --no-backup in future.)
225
 
        2>deleted d
226
 
        2>removed b/c (but kept a copy: b/c.~1~)
227
 
        2>deleted b
228
 
        2>deleted a
229
 
        ''')
 
217
        self.run_bzr(['remove', '--force'] + list(files),
 
218
                     error_regexes=["deleted a", "deleted b",
 
219
                                    "deleted b/c", "deleted d"])
230
220
        self.assertFilesDeleted(files)
231
221
 
232
222
    def test_remove_deleted_files(self):
237
227
        for f in my_files:
238
228
            osutils.delete_any(f)
239
229
        self.assertInWorkingTree(files)
240
 
        self.assertPathDoesNotExist(files)
 
230
        self.failIfExists(files)
241
231
        self.run_bzr('remove ' + ' '.join(files))
242
232
        self.assertNotInWorkingTree(a)
243
 
        self.assertPathDoesNotExist(files)
 
233
        self.failIfExists(files)
244
234
 
245
235
    def test_remove_non_existing_files(self):
246
236
        tree = self._make_tree_and_add([])