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
|
# Copyright (C) 2010 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 brz rmbranch."""
from breezy import (
controldir,
)
from breezy.tests import (
TestCaseWithTransport,
)
class TestRemoveBranch(TestCaseWithTransport):
def example_tree(self, path='.', format=None):
tree = self.make_branch_and_tree(path, format=format)
self.build_tree_contents([(path + '/hello', b'foo')])
tree.add('hello')
tree.commit(message='setup')
self.build_tree_contents([(path + '/goodbye', b'baz')])
tree.add('goodbye')
tree.commit(message='setup')
return tree
def test_remove_local(self):
# Remove a local branch.
tree = self.example_tree('a')
self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
'rmbranch a')
self.run_bzr('rmbranch --force a')
dir = controldir.ControlDir.open('a')
self.assertFalse(dir.has_branch())
self.assertPathExists('a/hello')
self.assertPathExists('a/goodbye')
def test_no_branch(self):
# No branch in the current directory.
self.make_repository('a')
self.run_bzr_error(['Not a branch'], 'rmbranch a')
def test_no_tree(self):
# removing the active branch is possible if there is no tree
tree = self.example_tree('a')
tree.controldir.destroy_workingtree()
self.run_bzr('rmbranch', working_dir='a')
dir = controldir.ControlDir.open('a')
self.assertFalse(dir.has_branch())
def test_no_arg(self):
# location argument defaults to current directory
self.example_tree('a')
self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
'rmbranch a')
self.run_bzr('rmbranch --force', working_dir='a')
dir = controldir.ControlDir.open('a')
self.assertFalse(dir.has_branch())
def test_remove_colo(self):
# Remove a colocated branch.
tree = self.example_tree('a')
tree.controldir.create_branch(name="otherbranch")
self.assertTrue(tree.controldir.has_branch('otherbranch'))
self.run_bzr('rmbranch %s,branch=otherbranch' %
tree.controldir.user_url)
dir = controldir.ControlDir.open('a')
self.assertFalse(dir.has_branch('otherbranch'))
self.assertTrue(dir.has_branch())
def test_remove_colo_directory(self):
# Remove a colocated branch.
tree = self.example_tree('a')
tree.controldir.create_branch(name="otherbranch")
self.assertTrue(tree.controldir.has_branch('otherbranch'))
self.run_bzr('rmbranch otherbranch -d %s' % tree.controldir.user_url)
dir = controldir.ControlDir.open('a')
self.assertFalse(dir.has_branch('otherbranch'))
self.assertTrue(dir.has_branch())
def test_remove_active_colo_branch(self):
# Remove a colocated branch.
dir = self.make_repository('a').controldir
branch = dir.create_branch('otherbranch')
branch.create_checkout('a')
self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
'rmbranch otherbranch -d %s' % branch.controldir.user_url)
self.assertTrue(dir.has_branch('otherbranch'))
self.run_bzr('rmbranch --force otherbranch -d %s' %
branch.controldir.user_url)
self.assertFalse(dir.has_branch('otherbranch'))
|