18
18
"""Black-box tests for bzr rmbranch."""
20
20
from bzrlib import (
23
23
from bzrlib.tests import (
24
24
TestCaseWithTransport,
26
from bzrlib.tests.matchers import ContainsNoVfsCalls
28
29
class TestRemoveBranch(TestCaseWithTransport):
30
def example_branch(self, path='.'):
31
tree = self.make_branch_and_tree(path)
31
def example_tree(self, path='.', format=None):
32
tree = self.make_branch_and_tree(path, format=format)
32
33
self.build_tree_contents([(path + '/hello', 'foo')])
34
35
tree.commit(message='setup')
35
36
self.build_tree_contents([(path + '/goodbye', 'baz')])
36
37
tree.add('goodbye')
37
38
tree.commit(message='setup')
39
41
def test_remove_local(self):
40
42
# Remove a local branch.
41
self.example_branch('a')
42
self.run_bzr('rmbranch a')
43
dir = bzrdir.BzrDir.open('a')
43
tree = self.example_tree('a')
44
self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
46
self.run_bzr('rmbranch --force a')
47
dir = controldir.ControlDir.open('a')
44
48
self.assertFalse(dir.has_branch())
45
self.failUnlessExists('a/hello')
46
self.failUnlessExists('a/goodbye')
49
self.assertPathExists('a/hello')
50
self.assertPathExists('a/goodbye')
48
52
def test_no_branch(self):
49
# No branch in the current directory.
53
# No branch in the current directory.
50
54
self.make_repository('a')
51
55
self.run_bzr_error(['Not a branch'],
58
def test_no_tree(self):
59
# removing the active branch is possible if there is no tree
60
tree = self.example_tree('a')
61
tree.bzrdir.destroy_workingtree()
62
self.run_bzr('rmbranch', working_dir='a')
63
dir = controldir.ControlDir.open('a')
64
self.assertFalse(dir.has_branch())
54
66
def test_no_arg(self):
55
67
# location argument defaults to current directory
56
self.example_branch('a')
57
self.run_bzr('rmbranch', working_dir='a')
58
dir = bzrdir.BzrDir.open('a')
68
self.example_tree('a')
69
self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
71
self.run_bzr('rmbranch --force', working_dir='a')
72
dir = controldir.ControlDir.open('a')
59
73
self.assertFalse(dir.has_branch())
75
def test_remove_colo(self):
76
# Remove a colocated branch.
77
tree = self.example_tree('a')
78
tree.bzrdir.create_branch(name="otherbranch")
79
self.assertTrue(tree.bzrdir.has_branch('otherbranch'))
80
self.run_bzr('rmbranch %s,branch=otherbranch' % tree.bzrdir.user_url)
81
dir = controldir.ControlDir.open('a')
82
self.assertFalse(dir.has_branch('otherbranch'))
83
self.assertTrue(dir.has_branch())
85
def test_remove_colo_directory(self):
86
# Remove a colocated branch.
87
tree = self.example_tree('a')
88
tree.bzrdir.create_branch(name="otherbranch")
89
self.assertTrue(tree.bzrdir.has_branch('otherbranch'))
90
self.run_bzr('rmbranch otherbranch -d %s' % tree.bzrdir.user_url)
91
dir = controldir.ControlDir.open('a')
92
self.assertFalse(dir.has_branch('otherbranch'))
93
self.assertTrue(dir.has_branch())
95
def test_remove_active_colo_branch(self):
96
# Remove a colocated branch.
97
dir = self.make_repository('a').bzrdir
98
branch = dir.create_branch('otherbranch')
99
branch.create_checkout('a')
100
self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
101
'rmbranch otherbranch -d %s' % branch.bzrdir.user_url)
102
self.assertTrue(dir.has_branch('otherbranch'))
103
self.run_bzr('rmbranch --force otherbranch -d %s' % branch.bzrdir.user_url)
104
self.assertFalse(dir.has_branch('otherbranch'))
107
class TestSmartServerRemoveBranch(TestCaseWithTransport):
109
def test_simple_remove_branch(self):
110
self.setup_smart_server_with_call_log()
111
self.make_branch('branch')
112
self.reset_smart_call_log()
113
out, err = self.run_bzr(['rmbranch', self.get_url('branch')])
114
# This figure represent the amount of work to perform this use case. It
115
# is entirely ok to reduce this number if a test fails due to rpc_count
116
# being too low. If rpc_count increases, more network roundtrips have
117
# become necessary for this use case. Please do not adjust this number
118
# upwards without agreement from bzr's network support maintainers.
119
self.assertLength(5, self.hpss_calls)
120
self.assertLength(1, self.hpss_connections)
121
self.assertThat(self.hpss_calls, ContainsNoVfsCalls)