/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2005, 2006 Canonical Ltd
1551.6.25 by Aaron Bentley
split out blackbox test for bzr remove
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
2292.1.34 by Marius Kruger
Move "magically convert commands like 'remove abc' to ['remove', 'abc']"
18
import os, re, shlex
1551.6.25 by Aaron Bentley
split out blackbox test for bzr remove
19
20
from bzrlib.tests.blackbox import ExternalBase
1551.6.26 by Aaron Bentley
Add support for remove --new
21
from bzrlib.workingtree import WorkingTree
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
22
from bzrlib import osutils
23
24
_id='-id'
25
a='a'
26
b='b/'
27
c='b/c'
2292.1.30 by Marius Kruger
* Minor text fixes.
28
d='d/'
29
files=(a, b, c, d)
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
30
31
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
32
class TestRemove(ExternalBase):
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
33
2292.1.34 by Marius Kruger
Move "magically convert commands like 'remove abc' to ['remove', 'abc']"
34
    def run_bzr_captured(self, argv, retcode=0, encoding=None, stdin=None,
35
                         working_dir=None):
36
37
        # magically convert commands like 'remove abc' to ['remove', 'abc']
38
        if (isinstance(argv, tuple) and len(argv) == 1 and
39
            isinstance(argv[0], basestring)):
40
            argv = shlex.split(argv[0])
41
        return ExternalBase.run_bzr_captured(self, argv, retcode, encoding,
42
            stdin, working_dir)
43
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
44
    def _make_add_and_assert_tree(self, files):
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
45
        tree = self.make_branch_and_tree('.')
46
        self.build_tree(files)
47
        for f in files:
2292.1.23 by Marius Kruger
Revert test_too_much.py and just do the minimum te get the tests to pass.
48
            id=str(f).replace('/', '_') + _id
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
49
            tree.add(f, id)
50
            self.assertEqual(tree.path2id(f), id)
51
            self.failUnlessExists(f)
52
            self.assertInWorkingTree(f)
53
        return tree
54
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
55
    def assertFilesDeleted(self, files):
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
56
        for f in files:
57
            id=f+_id
58
            self.assertNotInWorkingTree(f)
2292.1.14 by Marius Kruger
* blackbox/test_remove
59
            self.failIfExists(f)
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
60
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
61
    def assertFilesUnversioned(self, files):
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
62
        for f in files:
63
            self.assertNotInWorkingTree(f)
2292.1.14 by Marius Kruger
* blackbox/test_remove
64
            self.failUnlessExists(f)
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
65
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
66
    def changeFile(self, file_name):
67
        f = file(file_name, 'ab')
68
        f.write("\nsome other new content!")
69
        f.close()
70
71
    def run_bzr_remove_changed_files(self, error_regexes, files_to_remove):
2292.1.26 by Marius Kruger
* tests/__init__
72
        error_regexes.extend(["Can't remove changed or unknown files:",
73
            'Use --keep to not delete them,'
74
            ' or --force to delete them regardless.'
75
            ])
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
76
        self.run_bzr_error(error_regexes,
77
            'remove ' + ' '.join(files_to_remove))
78
        #see if we can force it now
79
        self.run_bzr('remove --force ' + ' '.join(files_to_remove))
2292.1.26 by Marius Kruger
* tests/__init__
80
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
81
    def test_remove_no_files_specified(self):
2292.1.3 by Marius Kruger
Factored out common code from test_remove.py into test_unversion.py
82
        tree = self._make_add_and_assert_tree([])
2292.1.26 by Marius Kruger
* tests/__init__
83
        self.run_bzr_error(["bzr: ERROR: Specify one or more files to remove, "
84
            "or use --new."], 'remove')
85
86
        self.run_bzr_error(["bzr: ERROR: No matching files."], 'remove --new')
87
88
        self.run_bzr_error(["bzr: ERROR: No matching files."],
89
            'remove --new .')
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
90
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
91
    def test_rm_one_file(self):
92
        tree = self._make_add_and_assert_tree([a])
93
        self.run_bzr("commit -m 'added a'")
94
        self.run_bzr('rm a', error_regexes=["deleted a"])
95
        self.assertFilesDeleted([a])
96
97
    def test_remove_one_file(self):
98
        tree = self._make_add_and_assert_tree([a])
99
        self.run_bzr("commit -m 'added a'")
100
        self.run_bzr('remove a', error_regexes=["deleted a"])
101
        self.assertFilesDeleted([a])
102
103
    def test_remove_keep_one_file(self):
104
        tree = self._make_add_and_assert_tree([a])
105
        self.run_bzr('remove --keep a', error_regexes=["removed a"])
106
        self.assertFilesUnversioned([a])
107
108
    def test_remove_one_deleted_file(self):
109
        tree = self._make_add_and_assert_tree([a])
110
        self.run_bzr("commit -m 'added a'")
111
        os.unlink(a)
112
        self.assertInWorkingTree(a)
113
        self.run_bzr('remove a')
114
        self.assertNotInWorkingTree(a)
115
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
116
    def test_remove_invalid_files(self):
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
117
        self.build_tree(files)
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
118
        tree = self.make_branch_and_tree('.')
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
119
        self.run_bzr_remove_changed_files(['unknown:[.\s]*xyz[.\s]*abc/def'],
120
            ['.', 'xyz', 'abc/def'])
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
121
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
122
    def test_remove_unversioned_files(self):
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
123
        self.build_tree(files)
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
124
        tree = self.make_branch_and_tree('.')
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
125
        self.run_bzr_remove_changed_files(
126
            ['unknown:[.\s]*d/[.\s]*b/c[.\s]*b/[.\s]*a'], files)
127
128
    def test_remove_changed_files(self):
129
        tree = self._make_add_and_assert_tree(files)
130
        self.run_bzr("commit -m 'added files'")
131
        self.changeFile(a)
132
        self.changeFile(c)
133
        self.run_bzr_remove_changed_files(['modified:[.\s]*a[.\s]*b/c'], files)
134
135
    def test_remove_changed_files_from_child_dir(self):
136
        tree = self._make_add_and_assert_tree(files)
137
        self.run_bzr("commit -m 'added files'")
138
        self.changeFile(a)
139
        self.changeFile(c)
140
        os.chdir('b')
141
        self.run_bzr_remove_changed_files(['modified:[.\s]*a[.\s]*b/c'],
142
            ['../a', 'c', '.', '../d'])
143
        os.chdir('..')
144
        self.assertNotInWorkingTree(files)
145
        self.failIfExists(files)
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
146
147
    def test_remove_keep_unversioned_files(self):
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
148
        self.build_tree(files)
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
149
        tree = self.make_branch_and_tree('.')
2292.1.27 by Marius Kruger
* tests/__init__.TestCase.run_bzr_captured
150
        self.run_bzr('remove --keep a', error_regexes=["a is not versioned."])
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
151
        self.assertFilesUnversioned(files)
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
152
153
    def test_remove_force_unversioned_files(self):
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
154
        self.build_tree(files)
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
155
        tree = self.make_branch_and_tree('.')
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
156
        self.run_bzr('remove --force ' + ' '.join(files),
157
                     error_regexes=["deleted a", "deleted b",
158
                                    "deleted b/c", "deleted d"])
159
        self.assertFilesDeleted(files)
160
161
    def test_remove_deleted_files(self):
162
        tree = self._make_add_and_assert_tree(files)
163
        self.run_bzr("commit -m 'added files'")
164
        my_files=[f for f in files]
165
        my_files.sort(reverse=True)
166
        for f in my_files:
167
            osutils.delete_any(f)
168
        self.assertInWorkingTree(files)
169
        self.failIfExists(files)
170
        self.run_bzr('remove ' + ' '.join(files))
171
        self.assertNotInWorkingTree(a)
172
        self.failIfExists(files)
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
173
174
    def test_remove_non_existing_files(self):
175
        tree = self._make_add_and_assert_tree([])
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
176
        self.run_bzr_remove_changed_files(['unknown:[.\s]*b'], ['b'])
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
177
178
    def test_remove_keep_non_existing_files(self):
179
        tree = self._make_add_and_assert_tree([])
2292.1.27 by Marius Kruger
* tests/__init__.TestCase.run_bzr_captured
180
        self.run_bzr('remove --keep b', error_regexes=["b is not versioned."])
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
181
2292.1.23 by Marius Kruger
Revert test_too_much.py and just do the minimum te get the tests to pass.
182
    def test_remove_files(self):
183
        tree = self._make_add_and_assert_tree(files)
2292.1.27 by Marius Kruger
* tests/__init__.TestCase.run_bzr_captured
184
        self.run_bzr("commit -m 'added files'")
2292.1.30 by Marius Kruger
* Minor text fixes.
185
        self.run_bzr('remove a b b/c d',
186
                     error_regexes=["deleted a", "deleted b", "deleted b/c",
187
                     "deleted d"])
2292.1.23 by Marius Kruger
Revert test_too_much.py and just do the minimum te get the tests to pass.
188
        self.assertFilesDeleted(files)
189
190
    def test_remove_keep_files(self):
191
        tree = self._make_add_and_assert_tree(files)
2292.1.27 by Marius Kruger
* tests/__init__.TestCase.run_bzr_captured
192
        self.run_bzr("commit -m 'added files'")
2292.1.30 by Marius Kruger
* Minor text fixes.
193
        self.run_bzr('remove --keep a b b/c d',
194
                     error_regexes=["removed a", "removed b", "removed b/c",
195
                     "removed d"])
2292.1.23 by Marius Kruger
Revert test_too_much.py and just do the minimum te get the tests to pass.
196
        self.assertFilesUnversioned(files)
197
2292.1.27 by Marius Kruger
* tests/__init__.TestCase.run_bzr_captured
198
    def test_remove_with_new(self):
2292.1.3 by Marius Kruger
Factored out common code from test_remove.py into test_unversion.py
199
        tree = self._make_add_and_assert_tree(files)
2292.1.27 by Marius Kruger
* tests/__init__.TestCase.run_bzr_captured
200
        self.run_bzr('remove --new --keep',
201
                     error_regexes=["removed a", "removed b", "removed b/c"])
2292.1.14 by Marius Kruger
* blackbox/test_remove
202
        self.assertFilesUnversioned(files)
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
203
2292.1.27 by Marius Kruger
* tests/__init__.TestCase.run_bzr_captured
204
    def test_remove_with_new_in_dir1(self):
2292.1.3 by Marius Kruger
Factored out common code from test_remove.py into test_unversion.py
205
        tree = self._make_add_and_assert_tree(files)
2292.1.27 by Marius Kruger
* tests/__init__.TestCase.run_bzr_captured
206
        self.run_bzr('remove --new --keep b b/c',
207
                     error_regexes=["removed b", "removed b/c"])
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
208
        tree = WorkingTree.open('.')
209
        self.assertInWorkingTree(a)
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
210
        self.assertEqual(tree.path2id(a), a + _id)
2292.1.14 by Marius Kruger
* blackbox/test_remove
211
        self.assertFilesUnversioned([b,c])
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
212
2292.1.27 by Marius Kruger
* tests/__init__.TestCase.run_bzr_captured
213
    def test_remove_with_new_in_dir2(self):
2292.1.3 by Marius Kruger
Factored out common code from test_remove.py into test_unversion.py
214
        tree = self._make_add_and_assert_tree(files)
2292.1.27 by Marius Kruger
* tests/__init__.TestCase.run_bzr_captured
215
        self.run_bzr('remove --new --keep .',
216
                     error_regexes=["removed a", "removed b", "removed b/c"])
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
217
        tree = WorkingTree.open('.')
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
218
        self.assertFilesUnversioned(files)