~bzr-pqm/bzr/bzr.dev

5273.1.5 by Vincent Ladeuil
Merge bzr.dev into cleanup
1
# Copyright (C) 2006-2010 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
5268.3.1 by Matt Giuca
remove-tree now refuses to run without --force if there are shelved changes.
22
from bzrlib import shelf
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
23
from bzrlib.tests import TestCaseWithTransport
24
25
26
class TestRemoveTree(TestCaseWithTransport):
2127.2.1 by Daniel Silverstone
Add remove-tree and its blackbox tests
27
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
28
    def setUp(self):
29
        super(TestRemoveTree, self).setUp()
30
        self.tree = self.make_branch_and_tree('branch1')
31
        self.build_tree(['branch1/foo'])
32
        self.tree.add('foo')
33
        self.tree.commit('1')
34
        self.failUnlessExists('branch1/foo')
35
36
    # Success modes
37
38
    def test_remove_tree_original_branch(self):
2127.2.1 by Daniel Silverstone
Add remove-tree and its blackbox tests
39
        os.chdir('branch1')
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
40
        self.run_bzr('remove-tree')
41
        self.failIfExists('foo')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
42
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
43
    def test_remove_tree_original_branch_explicit(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
44
        self.run_bzr('remove-tree branch1')
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
45
        self.failIfExists('branch1/foo')
46
4748.1.9 by Andrew Bennetts
Fix bug introduced by the change to take multiple locations, and add a test for multiple locations.
47
    def test_remove_tree_multiple_branch_explicit(self):
48
        self.tree.bzrdir.sprout('branch2')
49
        self.run_bzr('remove-tree branch1 branch2')
50
        self.failIfExists('branch1/foo')
51
        self.failIfExists('branch2/foo')
52
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
53
    def test_remove_tree_sprouted_branch(self):
54
        self.tree.bzrdir.sprout('branch2')
55
        self.failUnlessExists('branch2/foo')
56
        os.chdir('branch2')
57
        self.run_bzr('remove-tree')
58
        self.failIfExists('foo')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
59
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
60
    def test_remove_tree_sprouted_branch_explicit(self):
61
        self.tree.bzrdir.sprout('branch2')
62
        self.failUnlessExists('branch2/foo')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
63
        self.run_bzr('remove-tree branch2')
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
64
        self.failIfExists('branch2/foo')
65
66
    def test_remove_tree_checkout(self):
67
        self.tree.branch.create_checkout('branch2', lightweight=False)
68
        self.failUnlessExists('branch2/foo')
69
        os.chdir('branch2')
70
        self.run_bzr('remove-tree')
71
        self.failIfExists('foo')
72
        os.chdir('..')
73
        self.failUnlessExists('branch1/foo')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
74
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
75
    def test_remove_tree_checkout_explicit(self):
76
        self.tree.branch.create_checkout('branch2', lightweight=False)
77
        self.failUnlessExists('branch2/foo')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
78
        self.run_bzr('remove-tree branch2')
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
79
        self.failIfExists('branch2/foo')
80
        self.failUnlessExists('branch1/foo')
81
82
    # Failure modes
83
84
    def test_remove_tree_lightweight_checkout(self):
85
        self.tree.branch.create_checkout('branch2', lightweight=True)
86
        self.failUnlessExists('branch2/foo')
87
        os.chdir('branch2')
88
        output = self.run_bzr_error(
2127.2.3 by Daniel Silverstone
Oops, fix the message up
89
            ["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
90
            'remove-tree', retcode=3)
91
        self.failUnlessExists('foo')
92
        os.chdir('..')
93
        self.failUnlessExists('branch1/foo')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
94
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
95
    def test_remove_tree_lightweight_checkout_explicit(self):
96
        self.tree.branch.create_checkout('branch2', lightweight=True)
97
        self.failUnlessExists('branch2/foo')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
98
        output = self.run_bzr_error(
99
            ["You cannot remove the working tree from a lightweight checkout"],
100
            'remove-tree branch2', retcode=3)
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
101
        self.failUnlessExists('branch2/foo')
102
        self.failUnlessExists('branch1/foo')
103
104
    def test_remove_tree_empty_dir(self):
105
        os.mkdir('branch2')
106
        os.chdir('branch2')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
107
        output = self.run_bzr_error(["Not a branch"],
108
                                    'remove-tree', retcode=3)
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
109
110
    def test_remove_tree_repeatedly(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
111
        self.run_bzr('remove-tree branch1')
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
112
        self.failIfExists('branch1/foo')
113
        output = self.run_bzr_error(["No working tree to remove"],
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
114
                                    'remove-tree branch1', retcode=3)
2127.2.2 by Daniel Silverstone
Refactor the remove-tree stuff after review from J-A-M
115
116
    def test_remove_tree_remote_path(self):
117
        # TODO: I can't think of a way to implement this...
118
        pass
3667.2.1 by Lukáš Lalinský
Make `bzr remove-tree` not remove trees with uncommitted changes by default
119
120
    def test_remove_tree_uncommitted_changes(self):
121
        self.build_tree(['branch1/bar'])
122
        self.tree.add('bar')
123
        output = self.run_bzr_error(["Working tree .* has uncommitted changes"],
124
                                    'remove-tree branch1', retcode=3)
125
126
    def test_remove_tree_uncommitted_changes_force(self):
127
        self.build_tree(['branch1/bar'])
128
        self.tree.add('bar')
129
        self.run_bzr('remove-tree branch1 --force')
130
        self.failIfExists('branch1/foo')
131
        self.failUnlessExists('branch1/bar')
4672.3.3 by Vincent Ladeuil
Don't allow remove-tree to succeed with pending merges unless
132
133
    def test_remove_tree_pending_merges(self):
134
        self.run_bzr(['branch', 'branch1', 'branch2'])
135
        self.build_tree(['branch1/bar'])
136
        self.tree.add('bar')
137
        self.tree.commit('2')
138
        self.failUnlessExists('branch1/bar')
139
        self.run_bzr(['merge', '../branch1'], working_dir='branch2')
140
        self.failUnlessExists('branch2/bar')
141
        self.run_bzr(['revert', '.'], working_dir='branch2')
142
        self.failIfExists('branch2/bar')
143
        output = self.run_bzr_error(["Working tree .* has uncommitted changes"],
144
                                    'remove-tree branch2', retcode=3)
145
146
    def test_remove_tree_pending_merges_force(self):
147
        self.run_bzr(['branch', 'branch1', 'branch2'])
148
        self.build_tree(['branch1/bar'])
149
        self.tree.add('bar')
150
        self.tree.commit('2')
151
        self.failUnlessExists('branch1/bar')
152
        self.run_bzr(['merge', '../branch1'], working_dir='branch2')
153
        self.failUnlessExists('branch2/bar')
154
        self.run_bzr(['revert', '.'], working_dir='branch2')
155
        self.failIfExists('branch2/bar')
156
        self.run_bzr('remove-tree branch2 --force')
157
        self.failIfExists('branch2/foo')
158
        self.failIfExists('branch2/bar')
5268.3.1 by Matt Giuca
remove-tree now refuses to run without --force if there are shelved changes.
159
160
    def test_remove_tree_shelved_changes(self):
161
        # https://bugs.launchpad.net/bzr/+bug/586639
162
        tree = self.make_branch_and_tree('.')
163
        creator = shelf.ShelfCreator(tree, tree.basis_tree(), [])
164
        self.addCleanup(creator.finalize)
165
        shelf_id = tree.get_shelf_manager().shelve_changes(creator, 'Foo')
166
        output = self.run_bzr_error(["Working tree .* has shelved changes"],
167
                                    'remove-tree', retcode=3)
168
169
    def test_remove_tree_shelved_changes_force(self):
170
        tree = self.make_branch_and_tree('.')
171
        creator = shelf.ShelfCreator(tree, tree.basis_tree(), [])
172
        self.addCleanup(creator.finalize)
173
        shelf_id = tree.get_shelf_manager().shelve_changes(creator, 'Foo')
174
        self.run_bzr('remove-tree --force')
175
        self.run_bzr('checkout')
176
        # Ensure shelf is empty
177
        self.assertIs(None, tree.get_shelf_manager().last_shelf())