~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: 2011-08-17 18:13:57 UTC
  • mfrom: (5268.7.29 transport-segments)
  • Revision ID: pqm@pqm.ubuntu.com-20110817181357-y5q5eth1hk8bl3om
(jelmer) Allow specifying the colocated branch to use in the branch URL,
 and retrieving the branch name using ControlDir._get_selected_branch.
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2010 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
18
import os
19
19
import sys
20
20
 
21
 
from bzrlib.tests import SymlinkFeature, TestSkipped
22
 
from bzrlib.tests.blackbox import ExternalBase
 
21
from bzrlib.tests import (
 
22
    script,
 
23
    features,
 
24
    TestCaseWithTransport,
 
25
    TestSkipped,
 
26
    )
23
27
from bzrlib.workingtree import WorkingTree
24
28
from bzrlib import osutils
25
29
 
31
35
files=(a, b, c, d)
32
36
 
33
37
 
34
 
class TestRemove(ExternalBase):
 
38
class TestRemove(TestCaseWithTransport):
35
39
 
36
40
    def _make_tree_and_add(self, paths):
37
41
        tree = self.make_branch_and_tree('.')
49
53
        for f in files:
50
54
            id=f+_id
51
55
            self.assertNotInWorkingTree(f)
52
 
            self.failIfExists(f)
 
56
            self.assertPathDoesNotExist(f)
53
57
 
54
58
    def assertFilesUnversioned(self, files):
55
59
        for f in files:
56
60
            self.assertNotInWorkingTree(f)
57
 
            self.failUnlessExists(f)
 
61
            self.assertPathExists(f)
58
62
 
59
63
    def changeFile(self, file_name):
60
64
        f = file(file_name, 'ab')
61
65
        f.write("\nsome other new content!")
62
66
        f.close()
63
67
 
64
 
    def run_bzr_remove_changed_files(self, error_regexes, files_to_remove):
65
 
        error_regexes.extend(["Can't safely remove modified or unknown files:",
66
 
            'Use --keep to not delete them,'
67
 
            ' or --force to delete them regardless.'
68
 
            ])
69
 
        self.run_bzr_error(error_regexes,
70
 
            ['remove'] + list(files_to_remove))
71
 
        #see if we can force it now
72
 
        self.run_bzr(['remove', '--force'] + list(files_to_remove))
 
68
    def run_bzr_remove_changed_files(self, files_to_remove, working_dir=None):
 
69
        self.run_bzr(['remove'] + list(files_to_remove),
 
70
           working_dir=working_dir)
73
71
 
74
72
    def test_remove_new_no_files_specified(self):
75
73
        tree = self.make_branch_and_tree('.')
82
80
        self.assertEqual('', err)
83
81
        self.assertEqual('', out)
84
82
        self.assertInWorkingTree('foo', tree=tree)
85
 
        self.failUnlessExists('foo')
 
83
        self.assertPathExists('foo')
86
84
 
87
85
    def test_remove_no_files_specified_missing_dir_and_contents(self):
88
86
        tree = self._make_tree_and_add(
96
94
            err)
97
95
        # non-missing paths not touched:
98
96
        self.assertInWorkingTree('foo', tree=tree)
99
 
        self.failUnlessExists('foo')
 
97
        self.assertPathExists('foo')
100
98
        self.assertInWorkingTree('dir', tree=tree)
101
 
        self.failUnlessExists('dir')
 
99
        self.assertPathExists('dir')
102
100
        # missing files unversioned
103
101
        self.assertNotInWorkingTree('dir/missing', tree=tree)
104
102
        self.assertNotInWorkingTree('dir/missing/child', tree=tree)
122
120
        self.assertEqual('removed bar\n', err)
123
121
        # non-missing files not touched:
124
122
        self.assertInWorkingTree('foo', tree=tree)
125
 
        self.failUnlessExists('foo')
 
123
        self.assertPathExists('foo')
126
124
        # missing files unversioned
127
125
        self.assertNotInWorkingTree('bar', tree=tree)
128
126
 
129
127
    def test_remove_no_files_specified_missing_link(self):
130
 
        self.requireFeature(SymlinkFeature)
 
128
        self.requireFeature(features.SymlinkFeature)
131
129
        tree = self._make_tree_and_add(['foo'])
132
130
        os.symlink('foo', 'linkname')
133
131
        tree.add(['linkname'])
137
135
        self.assertEqual('removed linkname\n', err)
138
136
        # non-missing files not touched:
139
137
        self.assertInWorkingTree('foo', tree=tree)
140
 
        self.failUnlessExists('foo')
 
138
        self.assertPathExists('foo')
141
139
        # missing files unversioned
142
140
        self.assertNotInWorkingTree('linkname', tree=tree)
143
141
 
174
172
    def test_remove_unversioned_files(self):
175
173
        self.build_tree(files)
176
174
        tree = self.make_branch_and_tree('.')
177
 
        self.run_bzr_remove_changed_files(
178
 
            ['unknown:[.\s]*d/[.\s]*b/c[.\s]*b/[.\s]*a'], files)
 
175
        self.run_bzr_remove_changed_files(files)
179
176
 
180
177
    def test_remove_changed_files(self):
181
178
        tree = self._make_tree_and_add(files)
182
179
        self.run_bzr("commit -m 'added files'")
183
180
        self.changeFile(a)
184
181
        self.changeFile(c)
185
 
        self.run_bzr_remove_changed_files(['modified:[.\s]*a[.\s]*b/c'], files)
 
182
        self.run_bzr_remove_changed_files(files)
186
183
 
187
184
    def test_remove_changed_ignored_files(self):
188
185
        tree = self._make_tree_and_add(['a'])
189
186
        self.run_bzr(['ignore', 'a'])
190
 
        self.run_bzr_remove_changed_files(['added:[.\s]*a'], ['a'])
 
187
        self.run_bzr_remove_changed_files(['a'])
191
188
 
192
189
    def test_remove_changed_files_from_child_dir(self):
193
190
        if sys.platform == 'win32':
196
193
        self.run_bzr("commit -m 'added files'")
197
194
        self.changeFile(a)
198
195
        self.changeFile(c)
199
 
        os.chdir('b')
200
 
        self.run_bzr_remove_changed_files(['modified:[.\s]*a[.\s]*b/c'],
201
 
            ['../a', 'c', '.', '../d'])
202
 
        os.chdir('..')
 
196
        self.run_bzr_remove_changed_files(
 
197
            ['../a', 'c', '.', '../d'], working_dir='b')
203
198
        self.assertNotInWorkingTree(files)
204
 
        self.failIfExists(files)
 
199
        self.assertPathDoesNotExist(files)
205
200
 
206
201
    def test_remove_keep_unversioned_files(self):
207
202
        self.build_tree(files)
209
204
        self.run_bzr('remove --keep a', error_regexes=["a is not versioned."])
210
205
        self.assertFilesUnversioned(files)
211
206
 
 
207
    def test_remove_no_backup_unversioned_files(self):
 
208
        self.build_tree(files)
 
209
        tree = self.make_branch_and_tree('.')
 
210
        script.ScriptRunner().run_script(self, '''
 
211
        $ bzr remove --no-backup a b/ b/c d/
 
212
        2>deleted d
 
213
        2>removed b/c (but kept a copy: b/c.~1~)
 
214
        2>deleted b
 
215
        2>deleted a
 
216
        ''')
 
217
        self.assertFilesDeleted(files)
 
218
 
212
219
    def test_remove_force_unversioned_files(self):
213
220
        self.build_tree(files)
214
221
        tree = self.make_branch_and_tree('.')
215
 
        self.run_bzr(['remove', '--force'] + list(files),
216
 
                     error_regexes=["deleted a", "deleted b",
217
 
                                    "deleted b/c", "deleted d"])
 
222
        script.ScriptRunner().run_script(self, '''
 
223
        $ bzr remove --force a b/ b/c d/
 
224
        2>(The --force option is deprecated, rather use --no-backup in future.)
 
225
        2>deleted d
 
226
        2>removed b/c (but kept a copy: b/c.~1~)
 
227
        2>deleted b
 
228
        2>deleted a
 
229
        ''')
218
230
        self.assertFilesDeleted(files)
219
231
 
220
232
    def test_remove_deleted_files(self):
225
237
        for f in my_files:
226
238
            osutils.delete_any(f)
227
239
        self.assertInWorkingTree(files)
228
 
        self.failIfExists(files)
 
240
        self.assertPathDoesNotExist(files)
229
241
        self.run_bzr('remove ' + ' '.join(files))
230
242
        self.assertNotInWorkingTree(a)
231
 
        self.failIfExists(files)
 
243
        self.assertPathDoesNotExist(files)
232
244
 
233
245
    def test_remove_non_existing_files(self):
234
246
        tree = self._make_tree_and_add([])