~bzr-pqm/bzr/bzr.dev

4991.1.1 by Jelmer Vernooij
Add rmbranch command.
1
# Copyright (C) 2010 Canonical Ltd
2
#
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.
7
#
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.
12
#
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
16
17
18
"""Black-box tests for bzr rmbranch."""
19
20
from bzrlib import (
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
21
    controldir,
4991.1.3 by Jelmer Vernooij
Name command remove-branch, rmbranch as alias.
22
    )
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
23
from bzrlib.tests import (
24
    TestCaseWithTransport,
4991.1.3 by Jelmer Vernooij
Name command remove-branch, rmbranch as alias.
25
    )
6352.2.3 by Jelmer Vernooij
s/NoVfsCalls/ContainsNoVfsCalls/.
26
from bzrlib.tests.matchers import ContainsNoVfsCalls
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
27
28
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
29
class TestRemoveBranch(TestCaseWithTransport):
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
30
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
31
    def example_tree(self, path='.', format=None):
6240.4.1 by Jelmer Vernooij
Support removing colocated branches in 'bzr rmbranch'.
32
        tree = self.make_branch_and_tree(path, format=format)
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
33
        self.build_tree_contents([(path + '/hello', 'foo')])
34
        tree.add('hello')
35
        tree.commit(message='setup')
36
        self.build_tree_contents([(path + '/goodbye', 'baz')])
37
        tree.add('goodbye')
38
        tree.commit(message='setup')
6240.4.1 by Jelmer Vernooij
Support removing colocated branches in 'bzr rmbranch'.
39
        return tree
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
40
41
    def test_remove_local(self):
4991.1.2 by Jelmer Vernooij
Fix comments
42
        # Remove a local branch.
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
43
        tree = self.example_tree('a')
6437.41.4 by Jelmer Vernooij
Clarify error message.
44
        self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
45
            'rmbranch a')
46
        self.run_bzr('rmbranch --force a')
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
47
        dir = controldir.ControlDir.open('a')
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
48
        self.assertFalse(dir.has_branch())
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
49
        self.assertPathExists('a/hello')
50
        self.assertPathExists('a/goodbye')
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
51
52
    def test_no_branch(self):
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
53
        # No branch in the current directory.
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
54
        self.make_repository('a')
55
        self.run_bzr_error(['Not a branch'],
56
            'rmbranch a')
57
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
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')
6472.2.6 by Jelmer Vernooij
merge bzr.dev.
63
        dir = controldir.ControlDir.open('a')
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
64
        self.assertFalse(dir.has_branch())
65
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
66
    def test_no_arg(self):
67
        # location argument defaults to current directory
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
68
        self.example_tree('a')
6437.41.4 by Jelmer Vernooij
Clarify error message.
69
        self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
70
            'rmbranch a')
71
        self.run_bzr('rmbranch --force', working_dir='a')
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
72
        dir = controldir.ControlDir.open('a')
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
73
        self.assertFalse(dir.has_branch())
6240.4.1 by Jelmer Vernooij
Support removing colocated branches in 'bzr rmbranch'.
74
75
    def test_remove_colo(self):
76
        # Remove a colocated branch.
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
77
        tree = self.example_tree('a')
6240.4.1 by Jelmer Vernooij
Support removing colocated branches in 'bzr rmbranch'.
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)
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
81
        dir = controldir.ControlDir.open('a')
6240.4.1 by Jelmer Vernooij
Support removing colocated branches in 'bzr rmbranch'.
82
        self.assertFalse(dir.has_branch('otherbranch'))
83
        self.assertTrue(dir.has_branch())
6240.4.5 by Martin Packman
Merge bzr.dev to resolve conflict in bb.test_rmbranch
84
6437.40.1 by Jelmer Vernooij
Support colocated branches in 'bzr rmbranch'.
85
    def test_remove_colo_directory(self):
86
        # Remove a colocated branch.
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
87
        tree = self.example_tree('a')
6437.40.1 by Jelmer Vernooij
Support colocated branches in 'bzr rmbranch'.
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)
6472.2.5 by Jelmer Vernooij
Fix import error.
91
        dir = controldir.ControlDir.open('a')
6437.40.1 by Jelmer Vernooij
Support colocated branches in 'bzr rmbranch'.
92
        self.assertFalse(dir.has_branch('otherbranch'))
93
        self.assertTrue(dir.has_branch())
94
6437.41.1 by Jelmer Vernooij
Add test.
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')
6437.41.4 by Jelmer Vernooij
Clarify error message.
100
        self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
6437.41.1 by Jelmer Vernooij
Add test.
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'))
105
6283.1.6 by Jelmer Vernooij
Add hpss call count for 'bzr rmbranch'.
106
107
class TestSmartServerRemoveBranch(TestCaseWithTransport):
108
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.
6437.40.1 by Jelmer Vernooij
Support colocated branches in 'bzr rmbranch'.
119
        self.assertLength(5, self.hpss_calls)
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
120
        self.assertLength(1, self.hpss_connections)
6352.2.3 by Jelmer Vernooij
s/NoVfsCalls/ContainsNoVfsCalls/.
121
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)