~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-08-15 05:40:08 UTC
  • mfrom: (3619.5.4 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20080815054008-1xrwm20d1wv9fyt7
(robertc) Improve bzr rm to detect missing files and have an alias to
        del. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import os
19
19
import sys
20
20
 
21
 
from bzrlib.tests import TestSkipped
 
21
from bzrlib.tests import SymlinkFeature, TestSkipped
22
22
from bzrlib.tests.blackbox import ExternalBase
23
23
from bzrlib.workingtree import WorkingTree
24
24
from bzrlib import osutils
33
33
 
34
34
class TestRemove(ExternalBase):
35
35
 
36
 
    def _make_add_and_assert_tree(self, files):
 
36
    def _make_tree_and_add(self, paths):
37
37
        tree = self.make_branch_and_tree('.')
38
 
        self.build_tree(files)
39
 
        for f in files:
40
 
            id=str(f).replace('/', '_') + _id
41
 
            tree.add(f, id)
42
 
            self.assertEqual(tree.path2id(f), id)
43
 
            self.failUnlessExists(f)
44
 
            self.assertInWorkingTree(f)
 
38
        tree.lock_write()
 
39
        try:
 
40
            self.build_tree(paths)
 
41
            for path in paths:
 
42
                file_id=str(path).replace('/', '_') + _id
 
43
                tree.add(path, file_id)
 
44
        finally:
 
45
            tree.unlock()
45
46
        return tree
46
47
 
47
48
    def assertFilesDeleted(self, files):
70
71
        #see if we can force it now
71
72
        self.run_bzr(['remove', '--force'] + list(files_to_remove))
72
73
 
 
74
    def test_remove_new_no_files_specified(self):
 
75
        tree = self.make_branch_and_tree('.')
 
76
        self.run_bzr_error(["bzr: ERROR: No matching files."], 'remove --new')
 
77
        self.run_bzr_error(["bzr: ERROR: No matching files."], 'remove --new .')
 
78
 
73
79
    def test_remove_no_files_specified(self):
74
 
        tree = self._make_add_and_assert_tree([])
75
 
        self.run_bzr_error(["bzr: ERROR: Specify one or more files to remove, "
76
 
            "or use --new."], 'remove')
77
 
 
78
 
        self.run_bzr_error(["bzr: ERROR: No matching files."], 'remove --new')
79
 
 
80
 
        self.run_bzr_error(["bzr: ERROR: No matching files."],
81
 
            'remove --new .')
 
80
        tree = self._make_tree_and_add(['foo'])
 
81
        out, err = self.run_bzr(['rm'])
 
82
        self.assertEqual('', err)
 
83
        self.assertEqual('', out)
 
84
        self.assertInWorkingTree('foo', tree=tree)
 
85
        self.failUnlessExists('foo')
 
86
 
 
87
    def test_remove_no_files_specified_missing_dir_and_contents(self):
 
88
        tree = self._make_tree_and_add(
 
89
            ['foo', 'dir/', 'dir/missing/', 'dir/missing/child'])
 
90
        self.get_transport('.').delete_tree('dir/missing')
 
91
        out, err = self.run_bzr(['rm'])
 
92
        self.assertEqual('', out)
 
93
        self.assertEqual(
 
94
            'removed dir/missing/child\n'
 
95
            'removed dir/missing\n',
 
96
            err)
 
97
        # non-missing paths not touched:
 
98
        self.assertInWorkingTree('foo', tree=tree)
 
99
        self.failUnlessExists('foo')
 
100
        self.assertInWorkingTree('dir', tree=tree)
 
101
        self.failUnlessExists('dir')
 
102
        # missing files unversioned
 
103
        self.assertNotInWorkingTree('dir/missing', tree=tree)
 
104
        self.assertNotInWorkingTree('dir/missing/child', tree=tree)
 
105
 
 
106
    def test_remove_no_files_specified_already_deleted(self):
 
107
        tree = self._make_tree_and_add(['foo', 'bar'])
 
108
        tree.commit('save foo and bar')
 
109
        os.unlink('bar')
 
110
        self.run_bzr(['rm'])
 
111
        self.assertEqual(None, tree.path2id('bar'))
 
112
        # Running rm with a deleted file does not error.
 
113
        out, err = self.run_bzr(['rm'])
 
114
        self.assertEqual('', out)
 
115
        self.assertEqual('', err)
 
116
 
 
117
    def test_remove_no_files_specified_missing_file(self):
 
118
        tree = self._make_tree_and_add(['foo', 'bar'])
 
119
        os.unlink('bar')
 
120
        out, err = self.run_bzr(['rm'])
 
121
        self.assertEqual('', out)
 
122
        self.assertEqual('removed bar\n', err)
 
123
        # non-missing files not touched:
 
124
        self.assertInWorkingTree('foo', tree=tree)
 
125
        self.failUnlessExists('foo')
 
126
        # missing files unversioned
 
127
        self.assertNotInWorkingTree('bar', tree=tree)
 
128
 
 
129
    def test_remove_no_files_specified_missing_link(self):
 
130
        self.requireFeature(SymlinkFeature)
 
131
        tree = self._make_tree_and_add(['foo'])
 
132
        os.symlink('foo', 'linkname')
 
133
        tree.add(['linkname'])
 
134
        os.unlink('linkname')
 
135
        out, err = self.run_bzr(['rm'])
 
136
        self.assertEqual('', out)
 
137
        self.assertEqual('removed linkname\n', err)
 
138
        # non-missing files not touched:
 
139
        self.assertInWorkingTree('foo', tree=tree)
 
140
        self.failUnlessExists('foo')
 
141
        # missing files unversioned
 
142
        self.assertNotInWorkingTree('linkname', tree=tree)
82
143
 
83
144
    def test_rm_one_file(self):
84
 
        tree = self._make_add_and_assert_tree([a])
 
145
        tree = self._make_tree_and_add([a])
85
146
        self.run_bzr("commit -m 'added a'")
86
147
        self.run_bzr('rm a', error_regexes=["deleted a"])
87
148
        self.assertFilesDeleted([a])
88
149
 
89
150
    def test_remove_one_file(self):
90
 
        tree = self._make_add_and_assert_tree([a])
 
151
        tree = self._make_tree_and_add([a])
91
152
        self.run_bzr("commit -m 'added a'")
92
153
        self.run_bzr('remove a', error_regexes=["deleted a"])
93
154
        self.assertFilesDeleted([a])
94
155
 
95
156
    def test_remove_keep_one_file(self):
96
 
        tree = self._make_add_and_assert_tree([a])
 
157
        tree = self._make_tree_and_add([a])
97
158
        self.run_bzr('remove --keep a', error_regexes=["removed a"])
98
159
        self.assertFilesUnversioned([a])
99
160
 
100
161
    def test_remove_one_deleted_file(self):
101
 
        tree = self._make_add_and_assert_tree([a])
 
162
        tree = self._make_tree_and_add([a])
102
163
        self.run_bzr("commit -m 'added a'")
103
164
        os.unlink(a)
104
165
        self.assertInWorkingTree(a)
117
178
            ['unknown:[.\s]*d/[.\s]*b/c[.\s]*b/[.\s]*a'], files)
118
179
 
119
180
    def test_remove_changed_files(self):
120
 
        tree = self._make_add_and_assert_tree(files)
 
181
        tree = self._make_tree_and_add(files)
121
182
        self.run_bzr("commit -m 'added files'")
122
183
        self.changeFile(a)
123
184
        self.changeFile(c)
124
185
        self.run_bzr_remove_changed_files(['modified:[.\s]*a[.\s]*b/c'], files)
125
186
 
126
187
    def test_remove_changed_ignored_files(self):
127
 
        tree = self._make_add_and_assert_tree(['a'])
 
188
        tree = self._make_tree_and_add(['a'])
128
189
        self.run_bzr(['ignore', 'a'])
129
190
        self.run_bzr_remove_changed_files(['added:[.\s]*a'], ['a'])
130
191
 
131
192
    def test_remove_changed_files_from_child_dir(self):
132
193
        if sys.platform == 'win32':
133
194
            raise TestSkipped("Windows unable to remove '.' directory")
134
 
        tree = self._make_add_and_assert_tree(files)
 
195
        tree = self._make_tree_and_add(files)
135
196
        self.run_bzr("commit -m 'added files'")
136
197
        self.changeFile(a)
137
198
        self.changeFile(c)
157
218
        self.assertFilesDeleted(files)
158
219
 
159
220
    def test_remove_deleted_files(self):
160
 
        tree = self._make_add_and_assert_tree(files)
 
221
        tree = self._make_tree_and_add(files)
161
222
        self.run_bzr("commit -m 'added files'")
162
223
        my_files=[f for f in files]
163
224
        my_files.sort(reverse=True)
170
231
        self.failIfExists(files)
171
232
 
172
233
    def test_remove_non_existing_files(self):
173
 
        tree = self._make_add_and_assert_tree([])
 
234
        tree = self._make_tree_and_add([])
174
235
        self.run_bzr(['remove', 'b'])
175
236
 
176
237
    def test_remove_keep_non_existing_files(self):
177
 
        tree = self._make_add_and_assert_tree([])
 
238
        tree = self._make_tree_and_add([])
178
239
        self.run_bzr('remove --keep b', error_regexes=["b is not versioned."])
179
240
 
180
241
    def test_remove_files(self):
181
 
        tree = self._make_add_and_assert_tree(files)
 
242
        tree = self._make_tree_and_add(files)
182
243
        self.run_bzr("commit -m 'added files'")
183
244
        self.run_bzr('remove a b b/c d',
184
245
                     error_regexes=["deleted a", "deleted b", "deleted b/c",
186
247
        self.assertFilesDeleted(files)
187
248
 
188
249
    def test_remove_keep_files(self):
189
 
        tree = self._make_add_and_assert_tree(files)
 
250
        tree = self._make_tree_and_add(files)
190
251
        self.run_bzr("commit -m 'added files'")
191
252
        self.run_bzr('remove --keep a b b/c d',
192
253
                     error_regexes=["removed a", "removed b", "removed b/c",
194
255
        self.assertFilesUnversioned(files)
195
256
 
196
257
    def test_remove_with_new(self):
197
 
        tree = self._make_add_and_assert_tree(files)
 
258
        tree = self._make_tree_and_add(files)
198
259
        self.run_bzr('remove --new --keep',
199
260
                     error_regexes=["removed a", "removed b", "removed b/c"])
200
261
        self.assertFilesUnversioned(files)
201
262
 
202
263
    def test_remove_with_new_in_dir1(self):
203
 
        tree = self._make_add_and_assert_tree(files)
 
264
        tree = self._make_tree_and_add(files)
204
265
        self.run_bzr('remove --new --keep b b/c',
205
266
                     error_regexes=["removed b", "removed b/c"])
206
267
        tree = WorkingTree.open('.')
209
270
        self.assertFilesUnversioned([b,c])
210
271
 
211
272
    def test_remove_with_new_in_dir2(self):
212
 
        tree = self._make_add_and_assert_tree(files)
 
273
        tree = self._make_tree_and_add(files)
213
274
        self.run_bzr('remove --new --keep .',
214
275
                     error_regexes=["removed a", "removed b", "removed b/c"])
215
276
        tree = WorkingTree.open('.')