/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-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

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
from breezy.tests.matchers import ContainsNoVfsCalls
 
27
 
 
28
 
 
29
class TestRemoveBranch(TestCaseWithTransport):
 
30
 
 
31
    def example_tree(self, path='.', format=None):
 
32
        tree = self.make_branch_and_tree(path, format=format)
 
33
        self.build_tree_contents([(path + '/hello', b'foo')])
33
34
        tree.add('hello')
34
35
        tree.commit(message='setup')
35
 
        self.build_tree_contents([(path + '/goodbye', 'baz')])
 
36
        self.build_tree_contents([(path + '/goodbye', b'baz')])
36
37
        tree.add('goodbye')
37
38
        tree.commit(message='setup')
 
39
        return tree
38
40
 
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'],
 
45
                           'rmbranch a')
 
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')
47
51
 
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
 
        self.run_bzr_error(['Not a branch'],
52
 
            'rmbranch a')
 
55
        self.run_bzr_error(['Not a branch'], 'rmbranch a')
 
56
 
 
57
    def test_no_tree(self):
 
58
        # removing the active branch is possible if there is no tree
 
59
        tree = self.example_tree('a')
 
60
        tree.controldir.destroy_workingtree()
 
61
        self.run_bzr('rmbranch', working_dir='a')
 
62
        dir = controldir.ControlDir.open('a')
 
63
        self.assertFalse(dir.has_branch())
53
64
 
54
65
    def test_no_arg(self):
55
66
        # 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')
 
67
        self.example_tree('a')
 
68
        self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
 
69
                           'rmbranch a')
 
70
        self.run_bzr('rmbranch --force', working_dir='a')
 
71
        dir = controldir.ControlDir.open('a')
59
72
        self.assertFalse(dir.has_branch())
 
73
 
 
74
    def test_remove_colo(self):
 
75
        # Remove a colocated branch.
 
76
        tree = self.example_tree('a')
 
77
        tree.controldir.create_branch(name="otherbranch")
 
78
        self.assertTrue(tree.controldir.has_branch('otherbranch'))
 
79
        self.run_bzr('rmbranch %s,branch=otherbranch' %
 
80
                     tree.controldir.user_url)
 
81
        dir = controldir.ControlDir.open('a')
 
82
        self.assertFalse(dir.has_branch('otherbranch'))
 
83
        self.assertTrue(dir.has_branch())
 
84
 
 
85
    def test_remove_colo_directory(self):
 
86
        # Remove a colocated branch.
 
87
        tree = self.example_tree('a')
 
88
        tree.controldir.create_branch(name="otherbranch")
 
89
        self.assertTrue(tree.controldir.has_branch('otherbranch'))
 
90
        self.run_bzr('rmbranch otherbranch -d %s' % tree.controldir.user_url)
 
91
        dir = controldir.ControlDir.open('a')
 
92
        self.assertFalse(dir.has_branch('otherbranch'))
 
93
        self.assertTrue(dir.has_branch())
 
94
 
 
95
    def test_remove_active_colo_branch(self):
 
96
        # Remove a colocated branch.
 
97
        dir = self.make_repository('a').controldir
 
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.controldir.user_url)
 
102
        self.assertTrue(dir.has_branch('otherbranch'))
 
103
        self.run_bzr('rmbranch --force otherbranch -d %s' %
 
104
                     branch.controldir.user_url)
 
105
        self.assertFalse(dir.has_branch('otherbranch'))
 
106
 
 
107
 
 
108
class TestSmartServerRemoveBranch(TestCaseWithTransport):
 
109
 
 
110
    def test_simple_remove_branch(self):
 
111
        self.setup_smart_server_with_call_log()
 
112
        self.make_branch('branch')
 
113
        self.reset_smart_call_log()
 
114
        out, err = self.run_bzr(['rmbranch', self.get_url('branch')])
 
115
        # This figure represent the amount of work to perform this use case. It
 
116
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
117
        # being too low. If rpc_count increases, more network roundtrips have
 
118
        # become necessary for this use case. Please do not adjust this number
 
119
        # upwards without agreement from bzr's network support maintainers.
 
120
        self.assertLength(5, self.hpss_calls)
 
121
        self.assertLength(1, self.hpss_connections)
 
122
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)