~bzr-pqm/bzr/bzr.dev

2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
1
# Copyright (C) 2006 Canonical Ltd
2127.2.1 by Daniel Silverstone
Add remove-tree and its blackbox tests
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2127.2.1 by Daniel Silverstone
Add remove-tree and its blackbox tests
16
17
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
18
"""Black-box tests for bzr remove-tree."""
2127.2.1 by Daniel Silverstone
Add remove-tree and its blackbox tests
19
20
import os
21
22
from bzrlib.tests.blackbox import ExternalBase
23
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
24
2127.2.1 by Daniel Silverstone
Add remove-tree and its blackbox tests
25
class TestRemoveTree(ExternalBase):
26
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
27
    def setUp(self):
28
        super(TestRemoveTree, self).setUp()
29
        self.tree = self.make_branch_and_tree('branch1')
30
        self.build_tree(['branch1/foo'])
31
        self.tree.add('foo')
32
        self.tree.commit('1')
33
        self.failUnlessExists('branch1/foo')
34
35
    # Success modes
36
37
    def test_remove_tree_original_branch(self):
2127.2.1 by Daniel Silverstone
Add remove-tree and its blackbox tests
38
        os.chdir('branch1')
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
39
        self.run_bzr('remove-tree')
40
        self.failIfExists('foo')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
41
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
42
    def test_remove_tree_original_branch_explicit(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
43
        self.run_bzr('remove-tree branch1')
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
44
        self.failIfExists('branch1/foo')
45
4748.1.9 by Andrew Bennetts
Fix bug introduced by the change to take multiple locations, and add a test for multiple locations.
46
    def test_remove_tree_multiple_branch_explicit(self):
47
        self.tree.bzrdir.sprout('branch2')
48
        self.run_bzr('remove-tree branch1 branch2')
49
        self.failIfExists('branch1/foo')
50
        self.failIfExists('branch2/foo')
51
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
52
    def test_remove_tree_sprouted_branch(self):
53
        self.tree.bzrdir.sprout('branch2')
54
        self.failUnlessExists('branch2/foo')
55
        os.chdir('branch2')
56
        self.run_bzr('remove-tree')
57
        self.failIfExists('foo')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
58
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
59
    def test_remove_tree_sprouted_branch_explicit(self):
60
        self.tree.bzrdir.sprout('branch2')
61
        self.failUnlessExists('branch2/foo')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
62
        self.run_bzr('remove-tree branch2')
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
63
        self.failIfExists('branch2/foo')
64
65
    def test_remove_tree_checkout(self):
66
        self.tree.branch.create_checkout('branch2', lightweight=False)
67
        self.failUnlessExists('branch2/foo')
68
        os.chdir('branch2')
69
        self.run_bzr('remove-tree')
70
        self.failIfExists('foo')
71
        os.chdir('..')
72
        self.failUnlessExists('branch1/foo')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
73
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
74
    def test_remove_tree_checkout_explicit(self):
75
        self.tree.branch.create_checkout('branch2', lightweight=False)
76
        self.failUnlessExists('branch2/foo')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
77
        self.run_bzr('remove-tree branch2')
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
78
        self.failIfExists('branch2/foo')
79
        self.failUnlessExists('branch1/foo')
80
81
    # Failure modes
82
83
    def test_remove_tree_lightweight_checkout(self):
84
        self.tree.branch.create_checkout('branch2', lightweight=True)
85
        self.failUnlessExists('branch2/foo')
86
        os.chdir('branch2')
87
        output = self.run_bzr_error(
2127.2.3 by Daniel Silverstone
Oops, fix the message up
88
            ["You cannot remove the working tree from a lightweight checkout"],
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
89
            'remove-tree', retcode=3)
90
        self.failUnlessExists('foo')
91
        os.chdir('..')
92
        self.failUnlessExists('branch1/foo')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
93
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
94
    def test_remove_tree_lightweight_checkout_explicit(self):
95
        self.tree.branch.create_checkout('branch2', lightweight=True)
96
        self.failUnlessExists('branch2/foo')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
97
        output = self.run_bzr_error(
98
            ["You cannot remove the working tree from a lightweight checkout"],
99
            'remove-tree branch2', retcode=3)
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
100
        self.failUnlessExists('branch2/foo')
101
        self.failUnlessExists('branch1/foo')
102
103
    def test_remove_tree_empty_dir(self):
104
        os.mkdir('branch2')
105
        os.chdir('branch2')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
106
        output = self.run_bzr_error(["Not a branch"],
107
                                    'remove-tree', retcode=3)
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
108
109
    def test_remove_tree_repeatedly(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
110
        self.run_bzr('remove-tree branch1')
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
111
        self.failIfExists('branch1/foo')
112
        output = self.run_bzr_error(["No working tree to remove"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
113
                                    'remove-tree branch1', retcode=3)
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
114
115
    def test_remove_tree_remote_path(self):
116
        # TODO: I can't think of a way to implement this...
117
        pass
3667.2.1 by Lukáš Lalinský
Make `bzr remove-tree` not remove trees with uncommitted changes by default
118
119
    def test_remove_tree_uncommitted_changes(self):
120
        self.build_tree(['branch1/bar'])
121
        self.tree.add('bar')
122
        output = self.run_bzr_error(["Working tree .* has uncommitted changes"],
123
                                    'remove-tree branch1', retcode=3)
124
125
    def test_remove_tree_uncommitted_changes_force(self):
126
        self.build_tree(['branch1/bar'])
127
        self.tree.add('bar')
128
        self.run_bzr('remove-tree branch1 --force')
129
        self.failIfExists('branch1/foo')
130
        self.failUnlessExists('branch1/bar')
4672.3.3 by Vincent Ladeuil
Don't allow remove-tree to succeed with pending merges unless
131
132
    def test_remove_tree_pending_merges(self):
133
        self.run_bzr(['branch', 'branch1', 'branch2'])
134
        self.build_tree(['branch1/bar'])
135
        self.tree.add('bar')
136
        self.tree.commit('2')
137
        self.failUnlessExists('branch1/bar')
138
        self.run_bzr(['merge', '../branch1'], working_dir='branch2')
139
        self.failUnlessExists('branch2/bar')
140
        self.run_bzr(['revert', '.'], working_dir='branch2')
141
        self.failIfExists('branch2/bar')
142
        output = self.run_bzr_error(["Working tree .* has uncommitted changes"],
143
                                    'remove-tree branch2', retcode=3)
144
145
    def test_remove_tree_pending_merges_force(self):
146
        self.run_bzr(['branch', 'branch1', 'branch2'])
147
        self.build_tree(['branch1/bar'])
148
        self.tree.add('bar')
149
        self.tree.commit('2')
150
        self.failUnlessExists('branch1/bar')
151
        self.run_bzr(['merge', '../branch1'], working_dir='branch2')
152
        self.failUnlessExists('branch2/bar')
153
        self.run_bzr(['revert', '.'], working_dir='branch2')
154
        self.failIfExists('branch2/bar')
155
        self.run_bzr('remove-tree branch2 --force')
156
        self.failIfExists('branch2/foo')
157
        self.failIfExists('branch2/bar')