1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# Copyright (C) 2006-2012 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Black-box tests for bzr remove-tree."""
import os
from bzrlib import shelf
from bzrlib.tests import TestCaseWithTransport
class TestRemoveTree(TestCaseWithTransport):
def setUp(self):
super(TestRemoveTree, self).setUp()
self.tree = self.make_branch_and_tree('branch1')
self.build_tree(['branch1/foo'])
self.tree.add('foo')
self.tree.commit('1')
self.assertPathExists('branch1/foo')
# Success modes
def test_remove_tree_original_branch(self):
self.run_bzr('remove-tree', working_dir='branch1')
self.assertPathDoesNotExist('branch1/foo')
def test_remove_tree_original_branch_explicit(self):
self.run_bzr('remove-tree branch1')
self.assertPathDoesNotExist('branch1/foo')
def test_remove_tree_multiple_branch_explicit(self):
self.tree.bzrdir.sprout('branch2')
self.run_bzr('remove-tree branch1 branch2')
self.assertPathDoesNotExist('branch1/foo')
self.assertPathDoesNotExist('branch2/foo')
def test_remove_tree_sprouted_branch(self):
self.tree.bzrdir.sprout('branch2')
self.assertPathExists('branch2/foo')
self.run_bzr('remove-tree', working_dir='branch2')
self.assertPathDoesNotExist('branch2/foo')
def test_remove_tree_sprouted_branch_explicit(self):
self.tree.bzrdir.sprout('branch2')
self.assertPathExists('branch2/foo')
self.run_bzr('remove-tree branch2')
self.assertPathDoesNotExist('branch2/foo')
def test_remove_tree_checkout(self):
self.tree.branch.create_checkout('branch2', lightweight=False)
self.assertPathExists('branch2/foo')
self.run_bzr('remove-tree', working_dir='branch2')
self.assertPathDoesNotExist('branch2/foo')
self.assertPathExists('branch1/foo')
def test_remove_tree_checkout_explicit(self):
self.tree.branch.create_checkout('branch2', lightweight=False)
self.assertPathExists('branch2/foo')
self.run_bzr('remove-tree branch2')
self.assertPathDoesNotExist('branch2/foo')
self.assertPathExists('branch1/foo')
# Failure modes
def test_remove_tree_lightweight_checkout(self):
self.tree.branch.create_checkout('branch2', lightweight=True)
self.assertPathExists('branch2/foo')
output = self.run_bzr_error(
["You cannot remove the working tree from a lightweight checkout"],
'remove-tree', retcode=3, working_dir='branch2')
self.assertPathExists('branch2/foo')
self.assertPathExists('branch1/foo')
def test_remove_tree_lightweight_checkout_explicit(self):
self.tree.branch.create_checkout('branch2', lightweight=True)
self.assertPathExists('branch2/foo')
output = self.run_bzr_error(
["You cannot remove the working tree from a lightweight checkout"],
'remove-tree branch2', retcode=3)
self.assertPathExists('branch2/foo')
self.assertPathExists('branch1/foo')
def test_remove_tree_empty_dir(self):
os.mkdir('branch2')
output = self.run_bzr_error(
["Not a branch"], 'remove-tree', retcode=3, working_dir='branch2')
def test_remove_tree_repeatedly(self):
self.run_bzr('remove-tree branch1')
self.assertPathDoesNotExist('branch1/foo')
output = self.run_bzr_error(["No working tree to remove"],
'remove-tree branch1', retcode=3)
def test_remove_tree_remote_path(self):
# TODO: I can't think of a way to implement this...
pass
def test_remove_tree_uncommitted_changes(self):
self.build_tree(['branch1/bar'])
self.tree.add('bar')
output = self.run_bzr_error(["Working tree .* has uncommitted changes"],
'remove-tree branch1', retcode=3)
def test_remove_tree_uncommitted_changes_force(self):
self.build_tree(['branch1/bar'])
self.tree.add('bar')
self.run_bzr('remove-tree branch1 --force')
self.assertPathDoesNotExist('branch1/foo')
self.assertPathExists('branch1/bar')
def test_remove_tree_pending_merges(self):
self.run_bzr(['branch', 'branch1', 'branch2'])
self.build_tree(['branch1/bar'])
self.tree.add('bar')
self.tree.commit('2')
self.assertPathExists('branch1/bar')
self.run_bzr(['merge', '../branch1'], working_dir='branch2')
self.assertPathExists('branch2/bar')
self.run_bzr(['revert', '.'], working_dir='branch2')
self.assertPathDoesNotExist('branch2/bar')
output = self.run_bzr_error(["Working tree .* has uncommitted changes"],
'remove-tree branch2', retcode=3)
def test_remove_tree_pending_merges_force(self):
self.run_bzr(['branch', 'branch1', 'branch2'])
self.build_tree(['branch1/bar'])
self.tree.add('bar')
self.tree.commit('2')
self.assertPathExists('branch1/bar')
self.run_bzr(['merge', '../branch1'], working_dir='branch2')
self.assertPathExists('branch2/bar')
self.run_bzr(['revert', '.'], working_dir='branch2')
self.assertPathDoesNotExist('branch2/bar')
self.run_bzr('remove-tree branch2 --force')
self.assertPathDoesNotExist('branch2/foo')
self.assertPathDoesNotExist('branch2/bar')
def test_remove_tree_shelved_changes(self):
# https://bugs.launchpad.net/bzr/+bug/586639
tree = self.make_branch_and_tree('.')
creator = shelf.ShelfCreator(tree, tree.basis_tree(), [])
self.addCleanup(creator.finalize)
shelf_id = tree.get_shelf_manager().shelve_changes(creator, 'Foo')
output = self.run_bzr_error(["Working tree .* has shelved changes"],
'remove-tree', retcode=3)
def test_remove_tree_shelved_changes_force(self):
tree = self.make_branch_and_tree('.')
creator = shelf.ShelfCreator(tree, tree.basis_tree(), [])
self.addCleanup(creator.finalize)
shelf_id = tree.get_shelf_manager().shelve_changes(creator, 'Foo')
self.run_bzr('remove-tree --force')
self.run_bzr('checkout')
# Ensure shelf is empty
self.assertIs(None, tree.get_shelf_manager().last_shelf())
|