/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/blackbox/test_rmbranch.py

  • Committer: Jelmer Vernooij
  • Date: 2020-08-22 22:46:24 UTC
  • mfrom: (7490.40.105 work)
  • mto: This revision was merged to the branch mainline in revision 7521.
  • Revision ID: jelmer@jelmer.uk-20200822224624-om4a4idsr7cn8jew
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
 
"""Black-box tests for bzr rmbranch."""
19
 
 
20
 
from bzrlib import (
21
 
    bzrdir,
22
 
    )
23
 
from bzrlib.tests.blackbox import (
24
 
    ExternalBase,
25
 
    )
26
 
 
27
 
 
28
 
class TestRemoveBranch(ExternalBase):
29
 
 
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."""
 
19
 
 
20
from breezy import (
 
21
    controldir,
 
22
    )
 
23
from breezy.tests import (
 
24
    TestCaseWithTransport,
 
25
    )
 
26
 
 
27
 
 
28
class TestRemoveBranch(TestCaseWithTransport):
 
29
 
 
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')])
33
33
        tree.add('hello')
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')
 
38
        return tree
38
39
 
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'],
 
44
                           'rmbranch a')
 
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')
47
50
 
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'],
52
 
            'rmbranch a')
 
54
        self.run_bzr_error(['Not a branch'], 'rmbranch a')
 
55
 
 
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())
53
63
 
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'],
 
68
                           'rmbranch a')
 
69
        self.run_bzr('rmbranch --force', working_dir='a')
 
70
        dir = controldir.ControlDir.open('a')
59
71
        self.assertFalse(dir.has_branch())
 
72
 
 
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())
 
83
 
 
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())
 
93
 
 
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'))
 
105