~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2006-10-06 07:13:51 UTC
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20061006071351-e3fdd47eed1c3e7e
lazy import revisionspec and errors for bzrlib.options

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 by 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
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
 
import os, re, shlex
 
18
import os
19
19
 
20
20
from bzrlib.tests.blackbox import ExternalBase
21
21
from bzrlib.workingtree import WorkingTree
22
 
from bzrlib import osutils
23
 
 
24
 
_id='-id'
25
 
a='a'
26
 
b='b/'
27
 
c='b/c'
28
 
d='d/'
29
 
files=(a, b, c, d)
30
22
 
31
23
 
32
24
class TestRemove(ExternalBase):
33
25
 
34
 
    def _make_add_and_assert_tree(self, files):
35
 
        tree = self.make_branch_and_tree('.')
36
 
        self.build_tree(files)
37
 
        for f in files:
38
 
            id=str(f).replace('/', '_') + _id
39
 
            tree.add(f, id)
40
 
            self.assertEqual(tree.path2id(f), id)
41
 
            self.failUnlessExists(f)
42
 
            self.assertInWorkingTree(f)
43
 
        return tree
44
 
 
45
 
    def assertFilesDeleted(self, files):
46
 
        for f in files:
47
 
            id=f+_id
48
 
            self.assertNotInWorkingTree(f)
49
 
            self.failIfExists(f)
50
 
 
51
 
    def assertFilesUnversioned(self, files):
52
 
        for f in files:
53
 
            self.assertNotInWorkingTree(f)
54
 
            self.failUnlessExists(f)
55
 
 
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):
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
 
            ])
66
 
        self.run_bzr_error(error_regexes,
67
 
            'remove ' + ' '.join(files_to_remove))
68
 
        #see if we can force it now
69
 
        self.run_bzr('remove --force ' + ' '.join(files_to_remove))
70
 
 
71
 
    def test_remove_no_files_specified(self):
72
 
        tree = self._make_add_and_assert_tree([])
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 .')
80
 
 
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
 
 
106
 
    def test_remove_invalid_files(self):
107
 
        self.build_tree(files)
108
 
        tree = self.make_branch_and_tree('.')
109
 
        self.run_bzr_remove_changed_files(['unknown:[.\s]*xyz[.\s]*abc/def'],
110
 
            ['.', 'xyz', 'abc/def'])
111
 
 
112
 
    def test_remove_unversioned_files(self):
113
 
        self.build_tree(files)
114
 
        tree = self.make_branch_and_tree('.')
115
 
        self.run_bzr_remove_changed_files(
116
 
            ['unknown:[.\s]*d/[.\s]*b/c[.\s]*b/[.\s]*a'], files)
117
 
 
118
 
    def test_remove_changed_files(self):
119
 
        tree = self._make_add_and_assert_tree(files)
120
 
        self.run_bzr("commit -m 'added files'")
121
 
        self.changeFile(a)
122
 
        self.changeFile(c)
123
 
        self.run_bzr_remove_changed_files(['modified:[.\s]*a[.\s]*b/c'], files)
124
 
 
125
 
    def test_remove_changed_files_from_child_dir(self):
126
 
        tree = self._make_add_and_assert_tree(files)
127
 
        self.run_bzr("commit -m 'added files'")
128
 
        self.changeFile(a)
129
 
        self.changeFile(c)
130
 
        os.chdir('b')
131
 
        self.run_bzr_remove_changed_files(['modified:[.\s]*a[.\s]*b/c'],
132
 
            ['../a', 'c', '.', '../d'])
133
 
        os.chdir('..')
134
 
        self.assertNotInWorkingTree(files)
135
 
        self.failIfExists(files)
136
 
 
137
 
    def test_remove_keep_unversioned_files(self):
138
 
        self.build_tree(files)
139
 
        tree = self.make_branch_and_tree('.')
140
 
        self.run_bzr('remove --keep a', error_regexes=["a is not versioned."])
141
 
        self.assertFilesUnversioned(files)
142
 
 
143
 
    def test_remove_force_unversioned_files(self):
144
 
        self.build_tree(files)
145
 
        tree = self.make_branch_and_tree('.')
146
 
        self.run_bzr('remove --force ' + ' '.join(files),
147
 
                     error_regexes=["deleted a", "deleted b",
148
 
                                    "deleted b/c", "deleted d"])
149
 
        self.assertFilesDeleted(files)
150
 
 
151
 
    def test_remove_deleted_files(self):
152
 
        tree = self._make_add_and_assert_tree(files)
153
 
        self.run_bzr("commit -m 'added files'")
154
 
        my_files=[f for f in files]
155
 
        my_files.sort(reverse=True)
156
 
        for f in my_files:
157
 
            osutils.delete_any(f)
158
 
        self.assertInWorkingTree(files)
159
 
        self.failIfExists(files)
160
 
        self.run_bzr('remove ' + ' '.join(files))
161
 
        self.assertNotInWorkingTree(a)
162
 
        self.failIfExists(files)
163
 
 
164
 
    def test_remove_non_existing_files(self):
165
 
        tree = self._make_add_and_assert_tree([])
166
 
        self.run_bzr_remove_changed_files(['unknown:[.\s]*b'], ['b'])
167
 
 
168
 
    def test_remove_keep_non_existing_files(self):
169
 
        tree = self._make_add_and_assert_tree([])
170
 
        self.run_bzr('remove --keep b', error_regexes=["b is not versioned."])
171
 
 
172
 
    def test_remove_files(self):
173
 
        tree = self._make_add_and_assert_tree(files)
174
 
        self.run_bzr("commit -m 'added files'")
175
 
        self.run_bzr('remove a b b/c d',
176
 
                     error_regexes=["deleted a", "deleted b", "deleted b/c",
177
 
                     "deleted d"])
178
 
        self.assertFilesDeleted(files)
179
 
 
180
 
    def test_remove_keep_files(self):
181
 
        tree = self._make_add_and_assert_tree(files)
182
 
        self.run_bzr("commit -m 'added files'")
183
 
        self.run_bzr('remove --keep a b b/c d',
184
 
                     error_regexes=["removed a", "removed b", "removed b/c",
185
 
                     "removed d"])
186
 
        self.assertFilesUnversioned(files)
187
 
 
188
 
    def test_remove_with_new(self):
189
 
        tree = self._make_add_and_assert_tree(files)
190
 
        self.run_bzr('remove --new --keep',
191
 
                     error_regexes=["removed a", "removed b", "removed b/c"])
192
 
        self.assertFilesUnversioned(files)
193
 
 
194
 
    def test_remove_with_new_in_dir1(self):
195
 
        tree = self._make_add_and_assert_tree(files)
196
 
        self.run_bzr('remove --new --keep b b/c',
197
 
                     error_regexes=["removed b", "removed b/c"])
198
 
        tree = WorkingTree.open('.')
199
 
        self.assertInWorkingTree(a)
200
 
        self.assertEqual(tree.path2id(a), a + _id)
201
 
        self.assertFilesUnversioned([b,c])
202
 
 
203
 
    def test_remove_with_new_in_dir2(self):
204
 
        tree = self._make_add_and_assert_tree(files)
205
 
        self.run_bzr('remove --new --keep .',
206
 
                     error_regexes=["removed a", "removed b", "removed b/c"])
207
 
        tree = WorkingTree.open('.')
208
 
        self.assertFilesUnversioned(files)
 
26
    def test_remove_deleted(self):
 
27
        self.runbzr("init")
 
28
        self.build_tree(['a'])
 
29
        self.runbzr(['add', 'a'])
 
30
        self.runbzr(['commit', '-m', 'added a'])
 
31
        os.unlink('a')
 
32
        self.runbzr(['remove', 'a'])
 
33
 
 
34
    def test_remove_new(self):
 
35
        self.build_tree(['filefile',
 
36
                         'dir/',
 
37
                         'dir/filefilefile'])
 
38
        wt = self.make_branch_and_tree('.')
 
39
        wt.add(['filefile', 'dir', 'dir/filefilefile'], 
 
40
               ['filefile-id', 'dir-id', 'filefilefile-id'])
 
41
        self.assertEqual(wt.path2id('filefile'), 'filefile-id')
 
42
        self.assertEqual(wt.path2id('dir/filefilefile'), 'filefilefile-id')
 
43
        self.assertEqual(wt.path2id('dir'), 'dir-id')
 
44
        self.runbzr('remove --new')
 
45
        wt = WorkingTree.open('.')
 
46
        self.assertIs(wt.path2id('filefile'), None)
 
47
        self.assertIs(wt.path2id('dir/filefilefile'), None)
 
48
        self.assertIs(wt.path2id('dir'), None)
 
49
        wt.add(['filefile', 'dir', 'dir/filefilefile'], 
 
50
               ['filefile-id', 'dir-id', 'filefilefile-id'])
 
51
        self.assertEqual(wt.path2id('filefile'), 'filefile-id')
 
52
        self.assertEqual(wt.path2id('dir/filefilefile'), 'filefilefile-id')
 
53
        self.assertEqual(wt.path2id('dir'), 'dir-id')
 
54
        self.runbzr('remove --new dir')
 
55
        wt = WorkingTree.open('.')
 
56
        self.assertEqual(wt.path2id('filefile'), 'filefile-id')
 
57
        self.assertIs(wt.path2id('dir/filefilefile'), None)
 
58
        self.assertIs(wt.path2id('dir'), None)
 
59
        self.runbzr('remove --new .')
 
60
        wt = WorkingTree.open('.')
 
61
        self.assertIs(wt.path2id('filefile'), None)
 
62
        self.runbzr('remove --new .', retcode=3)