/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Marius Kruger
  • Date: 2007-02-16 06:16:11 UTC
  • mto: This revision was merged to the branch mainline in revision 2455.
  • Revision ID: amanic@gmail.com-20070216061611-sjscmgi4v5rozq6h
"bzr remove" and "bzr rm" will now remove the working file.
This has been done for consistency with svn and the unix rm command.

The old remove behaviour has been retained in the new command
"bzr unversion", which will just stop versioning the file,
but not delete it.
(Addressing Bug #82602)

Exisitng tests have been reworked and new tests were added to test these
changes properly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
 
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
 
 
18
import os
 
19
 
 
20
from bzrlib.tests.blackbox import ExternalBase
 
21
from bzrlib.workingtree import WorkingTree
 
22
 
 
23
_id='-id'
 
24
a='a'
 
25
b='b/'
 
26
c='b/c'
 
27
files=(a,b,c)
 
28
 
 
29
 
 
30
class TestRemove(ExternalBase):
 
31
 
 
32
    def __init__(self, methodName='runTest'):
 
33
        super(TestRemove, self).__init__(methodName)
 
34
        self.cmd = 'remove'
 
35
        self.shape = None
 
36
 
 
37
    def _make_tree(self,files):
 
38
        tree = self.make_branch_and_tree('.')
 
39
        self.build_tree(files)
 
40
        for f in files:
 
41
            id=f+_id
 
42
            tree.add(f, id)
 
43
            self.assertEqual(tree.path2id(f), id)
 
44
            self.failUnlessExists(f)
 
45
            self.assertInWorkingTree(f)
 
46
        return tree
 
47
 
 
48
    def assertCommandPerformedOnFiles(self,files):
 
49
        for f in files:
 
50
            self.failIfExists(f)
 
51
            self.assertNotInWorkingTree(f)
 
52
 
 
53
    def test_command_no_files_specified(self):
 
54
        self.build_tree([])
 
55
        tree = self.make_branch_and_tree('.')
 
56
 
 
57
        (out,err) = self.runbzr(self.cmd, retcode=3)
 
58
        self.assertEquals(err.strip(),
 
59
            "bzr: ERROR: Specify one or more files to remove, or use --new.")
 
60
 
 
61
        (out,err) = self.runbzr(self.cmd+' --new', retcode=3)
 
62
        self.assertEquals(err.strip(),"bzr: ERROR: No matching files.")
 
63
        (out,err) = self.runbzr(self.cmd+' --new .', retcode=3)
 
64
        self.assertEquals(out.strip(), "")
 
65
        self.assertEquals(err.strip(), "bzr: ERROR: No matching files.")
 
66
 
 
67
    def test_command_on_invalid_files(self):
 
68
        self.build_tree([a])
 
69
        tree = self.make_branch_and_tree('.')
 
70
 
 
71
        (out,err) = self.runbzr(self.cmd + ' .')
 
72
        self.assertEquals(out.strip(), "")
 
73
        self.assertEquals(err.strip(), "")
 
74
 
 
75
        (out,err) = self.runbzr(self.cmd + ' a')
 
76
        self.assertEquals(out.strip(), "")
 
77
        self.assertEquals(err.strip(), "a is not versioned.")
 
78
 
 
79
        (out,err) = self.runbzr(self.cmd + ' b')
 
80
        self.assertEquals(out.strip(), "")
 
81
        self.assertEquals(err.strip(), "b does not exist.")
 
82
 
 
83
    def test_command_one_file(self):
 
84
        self.build_tree([a])
 
85
        tree = self.make_branch_and_tree('.')
 
86
        tree.add(a)
 
87
        self.assertInWorkingTree(a)
 
88
        self.runbzr([self.cmd, a])
 
89
        self.assertCommandPerformedOnFiles([a])
 
90
 
 
91
    def test_command_on_deleted(self):
 
92
        self.runbzr("init")
 
93
        self.build_tree([a])
 
94
        self.runbzr(['add', a])
 
95
        self.runbzr(['commit', '-m', 'added a'])
 
96
        os.unlink(a)
 
97
        self.assertInWorkingTree(a)
 
98
        self.runbzr([self.cmd, a])
 
99
        self.assertNotInWorkingTree(a)
 
100
 
 
101
    def test_command_with_new(self):
 
102
        tree = self._make_tree(files)
 
103
 
 
104
        self.runbzr(self.cmd+' --new')
 
105
        self.assertCommandPerformedOnFiles(files)
 
106
 
 
107
    def test_command_with_new_in_dir1(self):
 
108
        tree = self._make_tree(files)
 
109
        (out,err) = self.runbzr(self.cmd+' --new %s %s'%(b,c))
 
110
 
 
111
        tree = WorkingTree.open('.')
 
112
        self.assertInWorkingTree(a)
 
113
        self.assertEqual(tree.path2id(a), a+_id)
 
114
        self.assertCommandPerformedOnFiles([b,c])
 
115
 
 
116
    def test_command_with_new_in_dir2(self):
 
117
        tree = self._make_tree(files)
 
118
        self.runbzr(self.cmd+' --new .')
 
119
        tree = WorkingTree.open('.')
 
120
        self.assertCommandPerformedOnFiles([a])
 
 
b'\\ No newline at end of file'