15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Black-box tests for bzr rmbranch."""
23
from bzrlib.tests.blackbox import (
28
class TestRemoveBranch(ExternalBase):
30
def example_branch(self, path='.'):
31
tree = self.make_branch_and_tree(path)
32
self.build_tree_contents([(path + '/hello', 'foo')])
18
"""Black-box tests for brz rmbranch."""
23
from breezy.tests import (
24
TestCaseWithTransport,
28
class TestRemoveBranch(TestCaseWithTransport):
30
def example_tree(self, path='.', format=None):
31
tree = self.make_branch_and_tree(path, format=format)
32
self.build_tree_contents([(path + '/hello', b'foo')])
34
34
tree.commit(message='setup')
35
self.build_tree_contents([(path + '/goodbye', 'baz')])
35
self.build_tree_contents([(path + '/goodbye', b'baz')])
36
36
tree.add('goodbye')
37
37
tree.commit(message='setup')
39
40
def test_remove_local(self):
40
41
# Remove a local branch.
41
self.example_branch('a')
42
self.run_bzr('rmbranch a')
43
dir = bzrdir.BzrDir.open('a')
42
tree = self.example_tree('a')
43
self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
45
self.run_bzr('rmbranch --force a')
46
dir = controldir.ControlDir.open('a')
44
47
self.assertFalse(dir.has_branch())
45
self.failUnlessExists('a/hello')
46
self.failUnlessExists('a/goodbye')
48
self.assertPathExists('a/hello')
49
self.assertPathExists('a/goodbye')
48
51
def test_no_branch(self):
49
# No branch in the current directory.
52
# No branch in the current directory.
50
53
self.make_repository('a')
51
self.run_bzr_error(['Not a branch'],
54
self.run_bzr_error(['Not a branch'], 'rmbranch a')
56
def test_no_tree(self):
57
# removing the active branch is possible if there is no tree
58
tree = self.example_tree('a')
59
tree.controldir.destroy_workingtree()
60
self.run_bzr('rmbranch', working_dir='a')
61
dir = controldir.ControlDir.open('a')
62
self.assertFalse(dir.has_branch())
54
64
def test_no_arg(self):
55
65
# 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')
66
self.example_tree('a')
67
self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
69
self.run_bzr('rmbranch --force', working_dir='a')
70
dir = controldir.ControlDir.open('a')
59
71
self.assertFalse(dir.has_branch())
73
def test_remove_colo(self):
74
# Remove a colocated branch.
75
tree = self.example_tree('a')
76
tree.controldir.create_branch(name="otherbranch")
77
self.assertTrue(tree.controldir.has_branch('otherbranch'))
78
self.run_bzr('rmbranch %s,branch=otherbranch' %
79
tree.controldir.user_url)
80
dir = controldir.ControlDir.open('a')
81
self.assertFalse(dir.has_branch('otherbranch'))
82
self.assertTrue(dir.has_branch())
84
def test_remove_colo_directory(self):
85
# Remove a colocated branch.
86
tree = self.example_tree('a')
87
tree.controldir.create_branch(name="otherbranch")
88
self.assertTrue(tree.controldir.has_branch('otherbranch'))
89
self.run_bzr('rmbranch otherbranch -d %s' % tree.controldir.user_url)
90
dir = controldir.ControlDir.open('a')
91
self.assertFalse(dir.has_branch('otherbranch'))
92
self.assertTrue(dir.has_branch())
94
def test_remove_active_colo_branch(self):
95
# Remove a colocated branch.
96
dir = self.make_repository('a').controldir
97
branch = dir.create_branch('otherbranch')
98
branch.create_checkout('a')
99
self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
100
'rmbranch otherbranch -d %s' % branch.controldir.user_url)
101
self.assertTrue(dir.has_branch('otherbranch'))
102
self.run_bzr('rmbranch --force otherbranch -d %s' %
103
branch.controldir.user_url)
104
self.assertFalse(dir.has_branch('otherbranch'))