~bzr-pqm/bzr/bzr.dev

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