1
# Copyright (C) 2010 Canonical Ltd
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.
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.
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
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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
tree.commit(message='setup')
35
self.build_tree_contents([(path + '/goodbye', b'baz')])
37
tree.commit(message='setup')
40
def test_remove_local(self):
41
# Remove a local branch.
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')
47
self.assertFalse(dir.has_branch())
48
self.assertPathExists('a/hello')
49
self.assertPathExists('a/goodbye')
51
def test_no_branch(self):
52
# No branch in the current directory.
53
self.make_repository('a')
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())
64
def test_no_arg(self):
65
# location argument defaults to current directory
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')
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'))