/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
6622.1.29 by Jelmer Vernooij
Fix some more tests.
18
"""Black-box tests for brz rmbranch."""
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
19
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
20
from breezy 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
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
23
from breezy.tests import (
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
24
    TestCaseWithTransport,
4991.1.3 by Jelmer Vernooij
Name command remove-branch, rmbranch as alias.
25
    )
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
26
27
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
28
class TestRemoveBranch(TestCaseWithTransport):
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
29
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
30
    def example_tree(self, path='.', format=None):
6240.4.1 by Jelmer Vernooij
Support removing colocated branches in 'bzr rmbranch'.
31
        tree = self.make_branch_and_tree(path, format=format)
6855.4.1 by Jelmer Vernooij
Yet more bees.
32
        self.build_tree_contents([(path + '/hello', b'foo')])
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
33
        tree.add('hello')
34
        tree.commit(message='setup')
6855.4.1 by Jelmer Vernooij
Yet more bees.
35
        self.build_tree_contents([(path + '/goodbye', b'baz')])
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
36
        tree.add('goodbye')
37
        tree.commit(message='setup')
6240.4.1 by Jelmer Vernooij
Support removing colocated branches in 'bzr rmbranch'.
38
        return tree
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
39
40
    def test_remove_local(self):
4991.1.2 by Jelmer Vernooij
Fix comments
41
        # Remove a local branch.
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
42
        tree = self.example_tree('a')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
43
        self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
44
                           'rmbranch a')
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
45
        self.run_bzr('rmbranch --force a')
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
46
        dir = controldir.ControlDir.open('a')
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
47
        self.assertFalse(dir.has_branch())
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
48
        self.assertPathExists('a/hello')
49
        self.assertPathExists('a/goodbye')
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
50
51
    def test_no_branch(self):
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
52
        # No branch in the current directory.
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
53
        self.make_repository('a')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
54
        self.run_bzr_error(['Not a branch'], 'rmbranch a')
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
55
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
56
    def test_no_tree(self):
57
        # removing the active branch is possible if there is no tree
58
        tree = self.example_tree('a')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
59
        tree.controldir.destroy_workingtree()
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
60
        self.run_bzr('rmbranch', working_dir='a')
6472.2.6 by Jelmer Vernooij
merge bzr.dev.
61
        dir = controldir.ControlDir.open('a')
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
62
        self.assertFalse(dir.has_branch())
63
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
64
    def test_no_arg(self):
65
        # location argument defaults to current directory
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
66
        self.example_tree('a')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
67
        self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
68
                           'rmbranch a')
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
69
        self.run_bzr('rmbranch --force', working_dir='a')
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
70
        dir = controldir.ControlDir.open('a')
4991.1.1 by Jelmer Vernooij
Add rmbranch command.
71
        self.assertFalse(dir.has_branch())
6240.4.1 by Jelmer Vernooij
Support removing colocated branches in 'bzr rmbranch'.
72
73
    def test_remove_colo(self):
74
        # Remove a colocated branch.
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
75
        tree = self.example_tree('a')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
76
        tree.controldir.create_branch(name="otherbranch")
77
        self.assertTrue(tree.controldir.has_branch('otherbranch'))
7143.15.2 by Jelmer Vernooij
Run autopep8.
78
        self.run_bzr('rmbranch %s,branch=otherbranch' %
79
                     tree.controldir.user_url)
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
80
        dir = controldir.ControlDir.open('a')
6240.4.1 by Jelmer Vernooij
Support removing colocated branches in 'bzr rmbranch'.
81
        self.assertFalse(dir.has_branch('otherbranch'))
82
        self.assertTrue(dir.has_branch())
6240.4.5 by Martin Packman
Merge bzr.dev to resolve conflict in bb.test_rmbranch
83
6437.40.1 by Jelmer Vernooij
Support colocated branches in 'bzr rmbranch'.
84
    def test_remove_colo_directory(self):
85
        # Remove a colocated branch.
6437.41.2 by Jelmer Vernooij
rmbranch now refuses removing active branches.
86
        tree = self.example_tree('a')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
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)
6472.2.5 by Jelmer Vernooij
Fix import error.
90
        dir = controldir.ControlDir.open('a')
6437.40.1 by Jelmer Vernooij
Support colocated branches in 'bzr rmbranch'.
91
        self.assertFalse(dir.has_branch('otherbranch'))
92
        self.assertTrue(dir.has_branch())
93
6437.41.1 by Jelmer Vernooij
Add test.
94
    def test_remove_active_colo_branch(self):
95
        # Remove a colocated branch.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
96
        dir = self.make_repository('a').controldir
6437.41.1 by Jelmer Vernooij
Add test.
97
        branch = dir.create_branch('otherbranch')
98
        branch.create_checkout('a')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
99
        self.run_bzr_error(['Branch is active. Use --force to remove it.\n'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
100
                           'rmbranch otherbranch -d %s' % branch.controldir.user_url)
6437.41.1 by Jelmer Vernooij
Add test.
101
        self.assertTrue(dir.has_branch('otherbranch'))
7143.15.2 by Jelmer Vernooij
Run autopep8.
102
        self.run_bzr('rmbranch --force otherbranch -d %s' %
103
                     branch.controldir.user_url)
6437.41.1 by Jelmer Vernooij
Add test.
104
        self.assertFalse(dir.has_branch('otherbranch'))
105