/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.32 by Marius Kruger
* tests/__init__.run_bzr
34
    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.
35
        tree = self.make_branch_and_tree('.')
36
        self.build_tree(files)
37
        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.
38
            id=str(f).replace('/', '_') + _id
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
39
            tree.add(f, id)
40
            self.assertEqual(tree.path2id(f), id)
41
            self.failUnlessExists(f)
42
            self.assertInWorkingTree(f)
43
        return tree
44
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
45
    def assertFilesDeleted(self, files):
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
46
        for f in files:
47
            id=f+_id
48
            self.assertNotInWorkingTree(f)
2292.1.14 by Marius Kruger
* blackbox/test_remove
49
            self.failIfExists(f)
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
50
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
51
    def assertFilesUnversioned(self, files):
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
52
        for f in files:
53
            self.assertNotInWorkingTree(f)
2292.1.14 by Marius Kruger
* blackbox/test_remove
54
            self.failUnlessExists(f)
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
55
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
56
    def changeFile(self, file_name):
57
        f = file(file_name, 'ab')
58
        f.write("\nsome other new content!")
59
        f.close()
60
61
    def run_bzr_remove_changed_files(self, error_regexes, files_to_remove):
2292.1.26 by Marius Kruger
* tests/__init__
62
        error_regexes.extend(["Can't remove changed or unknown files:",
63
            'Use --keep to not delete them,'
64
            ' or --force to delete them regardless.'
65
            ])
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
66
        self.run_bzr_error(error_regexes,
2605.1.2 by Martin Pool
Fix up run_bzr calls
67
            ['remove'] + list(files_to_remove))
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
68
        #see if we can force it now
2605.1.2 by Martin Pool
Fix up run_bzr calls
69
        self.run_bzr(['remove', '--force'] + list(files_to_remove))
2292.1.26 by Marius Kruger
* tests/__init__
70
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
71
    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
72
        tree = self._make_add_and_assert_tree([])
2292.1.26 by Marius Kruger
* tests/__init__
73
        self.run_bzr_error(["bzr: ERROR: Specify one or more files to remove, "
74
            "or use --new."], 'remove')
75
76
        self.run_bzr_error(["bzr: ERROR: No matching files."], 'remove --new')
77
78
        self.run_bzr_error(["bzr: ERROR: No matching files."],
79
            'remove --new .')
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
80
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
81
    def test_rm_one_file(self):
82
        tree = self._make_add_and_assert_tree([a])
83
        self.run_bzr("commit -m 'added a'")
84
        self.run_bzr('rm a', error_regexes=["deleted a"])
85
        self.assertFilesDeleted([a])
86
87
    def test_remove_one_file(self):
88
        tree = self._make_add_and_assert_tree([a])
89
        self.run_bzr("commit -m 'added a'")
90
        self.run_bzr('remove a', error_regexes=["deleted a"])
91
        self.assertFilesDeleted([a])
92
93
    def test_remove_keep_one_file(self):
94
        tree = self._make_add_and_assert_tree([a])
95
        self.run_bzr('remove --keep a', error_regexes=["removed a"])
96
        self.assertFilesUnversioned([a])
97
98
    def test_remove_one_deleted_file(self):
99
        tree = self._make_add_and_assert_tree([a])
100
        self.run_bzr("commit -m 'added a'")
101
        os.unlink(a)
102
        self.assertInWorkingTree(a)
103
        self.run_bzr('remove a')
104
        self.assertNotInWorkingTree(a)
105
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
106
    def test_remove_invalid_files(self):
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
107
        self.build_tree(files)
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
108
        tree = self.make_branch_and_tree('.')
2605.1.1 by Martin Pool
Merge fix for rm renamed files
109
        self.run_bzr(['remove', '.', 'xyz', 'abc/def'])
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
110
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
111
    def test_remove_unversioned_files(self):
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
112
        self.build_tree(files)
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
113
        tree = self.make_branch_and_tree('.')
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
114
        self.run_bzr_remove_changed_files(
115
            ['unknown:[.\s]*d/[.\s]*b/c[.\s]*b/[.\s]*a'], files)
116
117
    def test_remove_changed_files(self):
118
        tree = self._make_add_and_assert_tree(files)
119
        self.run_bzr("commit -m 'added files'")
120
        self.changeFile(a)
121
        self.changeFile(c)
122
        self.run_bzr_remove_changed_files(['modified:[.\s]*a[.\s]*b/c'], files)
123
124
    def test_remove_changed_files_from_child_dir(self):
125
        tree = self._make_add_and_assert_tree(files)
126
        self.run_bzr("commit -m 'added files'")
127
        self.changeFile(a)
128
        self.changeFile(c)
129
        os.chdir('b')
130
        self.run_bzr_remove_changed_files(['modified:[.\s]*a[.\s]*b/c'],
131
            ['../a', 'c', '.', '../d'])
132
        os.chdir('..')
133
        self.assertNotInWorkingTree(files)
134
        self.failIfExists(files)
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
135
136
    def test_remove_keep_unversioned_files(self):
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
137
        self.build_tree(files)
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
138
        tree = self.make_branch_and_tree('.')
2292.1.27 by Marius Kruger
* tests/__init__.TestCase.run_bzr_captured
139
        self.run_bzr('remove --keep a', error_regexes=["a is not versioned."])
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
140
        self.assertFilesUnversioned(files)
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
141
142
    def test_remove_force_unversioned_files(self):
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
143
        self.build_tree(files)
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
144
        tree = self.make_branch_and_tree('.')
2605.1.2 by Martin Pool
Fix up run_bzr calls
145
        self.run_bzr(['remove', '--force'] + list(files),
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
146
                     error_regexes=["deleted a", "deleted b",
147
                                    "deleted b/c", "deleted d"])
148
        self.assertFilesDeleted(files)
149
150
    def test_remove_deleted_files(self):
151
        tree = self._make_add_and_assert_tree(files)
152
        self.run_bzr("commit -m 'added files'")
153
        my_files=[f for f in files]
154
        my_files.sort(reverse=True)
155
        for f in my_files:
156
            osutils.delete_any(f)
157
        self.assertInWorkingTree(files)
158
        self.failIfExists(files)
159
        self.run_bzr('remove ' + ' '.join(files))
160
        self.assertNotInWorkingTree(a)
161
        self.failIfExists(files)
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
162
163
    def test_remove_non_existing_files(self):
164
        tree = self._make_add_and_assert_tree([])
2605.1.1 by Martin Pool
Merge fix for rm renamed files
165
        self.run_bzr(['remove', 'b'])
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
166
167
    def test_remove_keep_non_existing_files(self):
168
        tree = self._make_add_and_assert_tree([])
2292.1.27 by Marius Kruger
* tests/__init__.TestCase.run_bzr_captured
169
        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.
170
2292.1.23 by Marius Kruger
Revert test_too_much.py and just do the minimum te get the tests to pass.
171
    def test_remove_files(self):
172
        tree = self._make_add_and_assert_tree(files)
2292.1.27 by Marius Kruger
* tests/__init__.TestCase.run_bzr_captured
173
        self.run_bzr("commit -m 'added files'")
2292.1.30 by Marius Kruger
* Minor text fixes.
174
        self.run_bzr('remove a b b/c d',
175
                     error_regexes=["deleted a", "deleted b", "deleted b/c",
176
                     "deleted d"])
2292.1.23 by Marius Kruger
Revert test_too_much.py and just do the minimum te get the tests to pass.
177
        self.assertFilesDeleted(files)
178
179
    def test_remove_keep_files(self):
180
        tree = self._make_add_and_assert_tree(files)
2292.1.27 by Marius Kruger
* tests/__init__.TestCase.run_bzr_captured
181
        self.run_bzr("commit -m 'added files'")
2292.1.30 by Marius Kruger
* Minor text fixes.
182
        self.run_bzr('remove --keep a b b/c d',
183
                     error_regexes=["removed a", "removed b", "removed b/c",
184
                     "removed d"])
2292.1.23 by Marius Kruger
Revert test_too_much.py and just do the minimum te get the tests to pass.
185
        self.assertFilesUnversioned(files)
186
2292.1.27 by Marius Kruger
* tests/__init__.TestCase.run_bzr_captured
187
    def test_remove_with_new(self):
2292.1.3 by Marius Kruger
Factored out common code from test_remove.py into test_unversion.py
188
        tree = self._make_add_and_assert_tree(files)
2292.1.27 by Marius Kruger
* tests/__init__.TestCase.run_bzr_captured
189
        self.run_bzr('remove --new --keep',
190
                     error_regexes=["removed a", "removed b", "removed b/c"])
2292.1.14 by Marius Kruger
* blackbox/test_remove
191
        self.assertFilesUnversioned(files)
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
192
2292.1.27 by Marius Kruger
* tests/__init__.TestCase.run_bzr_captured
193
    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
194
        tree = self._make_add_and_assert_tree(files)
2292.1.27 by Marius Kruger
* tests/__init__.TestCase.run_bzr_captured
195
        self.run_bzr('remove --new --keep b b/c',
196
                     error_regexes=["removed b", "removed b/c"])
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
197
        tree = WorkingTree.open('.')
198
        self.assertInWorkingTree(a)
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
199
        self.assertEqual(tree.path2id(a), a + _id)
2292.1.14 by Marius Kruger
* blackbox/test_remove
200
        self.assertFilesUnversioned([b,c])
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
201
2292.1.27 by Marius Kruger
* tests/__init__.TestCase.run_bzr_captured
202
    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
203
        tree = self._make_add_and_assert_tree(files)
2292.1.27 by Marius Kruger
* tests/__init__.TestCase.run_bzr_captured
204
        self.run_bzr('remove --new --keep .',
205
                     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.
206
        tree = WorkingTree.open('.')
2292.1.32 by Marius Kruger
* tests/__init__.run_bzr
207
        self.assertFilesUnversioned(files)