~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_switch.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2007 Canonical Ltd
2
2
# -*- coding: utf-8 -*-
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
 
19
19
"""Tests for the switch command of bzr."""
20
20
 
21
21
import os
22
22
 
23
 
from bzrlib.workingtree import WorkingTree
24
23
from bzrlib.tests.blackbox import ExternalBase
25
24
 
26
25
 
50
49
        self.assertContainsRe(err, 'Switched to branch: .*/branch2.\n')
51
50
        self.assertEqual('', out)
52
51
 
53
 
    def _test_switch_nick(self, lightweight):
54
 
        """Check that the nick gets switched too."""
55
 
        tree1 = self.make_branch_and_tree('branch1')
56
 
        tree2 = self.make_branch_and_tree('branch2')
57
 
        tree2.pull(tree1.branch)
58
 
        checkout =  tree1.branch.create_checkout('checkout',
59
 
            lightweight=lightweight)
60
 
        self.assertEqual(checkout.branch.nick, tree1.branch.nick)
61
 
        self.assertEqual(checkout.branch.get_config().has_explicit_nickname(),
62
 
            False)
63
 
        self.run_bzr('switch branch2', working_dir='checkout')
64
 
 
65
 
        # we need to get the tree again, otherwise we don't get the new branch
66
 
        checkout = WorkingTree.open('checkout')
67
 
        self.assertEqual(checkout.branch.nick, tree2.branch.nick)
68
 
        self.assertEqual(checkout.branch.get_config().has_explicit_nickname(),
69
 
            False)
70
 
 
71
 
    def test_switch_nick(self):
72
 
        self._test_switch_nick(lightweight=False)
73
 
 
74
 
    def test_switch_nick_lightweight(self):
75
 
        self._test_switch_nick(lightweight=True)
76
 
 
77
 
    def _test_switch_explicit_nick(self, lightweight):
78
 
        """Check that the nick gets switched too."""
79
 
        tree1 = self.make_branch_and_tree('branch1')
80
 
        tree2 = self.make_branch_and_tree('branch2')
81
 
        tree2.pull(tree1.branch)
82
 
        checkout =  tree1.branch.create_checkout('checkout',
83
 
            lightweight=lightweight)
84
 
        self.assertEqual(checkout.branch.nick, tree1.branch.nick)
85
 
        checkout.branch.nick = "explicit_nick"
86
 
        self.assertEqual(checkout.branch.nick, "explicit_nick")
87
 
        self.assertEqual(checkout.branch.get_config()._get_explicit_nickname(),
88
 
            "explicit_nick")
89
 
        self.run_bzr('switch branch2', working_dir='checkout')
90
 
 
91
 
        # we need to get the tree again, otherwise we don't get the new branch
92
 
        checkout = WorkingTree.open('checkout')
93
 
        self.assertEqual(checkout.branch.nick, tree2.branch.nick)
94
 
        self.assertEqual(checkout.branch.get_config()._get_explicit_nickname(),
95
 
            tree2.branch.nick)
96
 
 
97
 
    def test_switch_explicit_nick(self):
98
 
        self._test_switch_explicit_nick(lightweight=False)
99
 
 
100
 
    def test_switch_explicit_nick_lightweight(self):
101
 
        self._test_switch_explicit_nick(lightweight=True)
102
 
 
103
52
    def test_switch_finds_relative_branch(self):
104
 
        """Switch will find 'foo' relative to the branch the checkout is of."""
 
53
        """Switch will find 'foo' relative to the branch that the checkout is of."""
105
54
        self.build_tree(['repo/'])
106
55
        tree1 = self.make_branch_and_tree('repo/brancha')
107
56
        tree1.commit('foo')
113
62
        self.assertEqual(branchb_id, checkout.last_revision())
114
63
        checkout = checkout.bzrdir.open_workingtree()
115
64
        self.assertEqual(tree2.branch.base, checkout.branch.base)
116
 
 
117
 
    def test_switch_finds_relative_bound_branch(self):
118
 
        """Using switch on a heavy checkout should find master sibling
119
 
 
120
 
        The behaviour of lighweight and heavy checkouts should be
121
 
        consistentwhen using the convenient "switch to sibling" feature
122
 
        Both should switch to a sibling of the branch
123
 
        they are bound to, and not a sibling of themself"""
124
 
 
125
 
        self.build_tree(['repo/',
126
 
                         'heavyco/'])
127
 
        tree1 = self.make_branch_and_tree('repo/brancha')
128
 
        tree1.commit('foo')
129
 
        tree2 = self.make_branch_and_tree('repo/branchb')
130
 
        tree2.pull(tree1.branch)
131
 
        branchb_id = tree2.commit('bar')
132
 
        checkout = tree1.branch.create_checkout('heavyco/a', lightweight=False)
133
 
        self.run_bzr(['switch', 'branchb'], working_dir='heavyco/a')
134
 
        self.assertEqual(branchb_id, checkout.last_revision())
135
 
        self.assertEqual(tree2.branch.base, checkout.branch.get_bound_location())
136
 
 
137
 
    def prepare_lightweight_switch(self):
138
 
        branch = self.make_branch('branch')
139
 
        branch.create_checkout('tree', lightweight=True)
140
 
        os.rename('branch', 'branch1')
141
 
 
142
 
    def test_switch_lightweight_after_branch_moved(self):
143
 
        self.prepare_lightweight_switch()
144
 
        self.run_bzr('switch --force ../branch1', working_dir='tree')
145
 
        branch_location = WorkingTree.open('tree').branch.base
146
 
        self.assertEndsWith(branch_location, 'branch1/')
147
 
 
148
 
    def test_switch_lightweight_after_branch_moved_relative(self):
149
 
        self.prepare_lightweight_switch()
150
 
        self.run_bzr('switch --force branch1', working_dir='tree')
151
 
        branch_location = WorkingTree.open('tree').branch.base
152
 
        self.assertEndsWith(branch_location, 'branch1/')
153
 
 
154
 
    def test_create_branch_no_branch(self):
155
 
        self.prepare_lightweight_switch()
156
 
        self.run_bzr_error(['cannot create branch without source branch'],
157
 
            'switch --create-branch ../branch2', working_dir='tree')
158
 
 
159
 
    def test_create_branch(self):
160
 
        branch = self.make_branch('branch')
161
 
        tree = branch.create_checkout('tree', lightweight=True)
162
 
        tree.commit('one', rev_id='rev-1')
163
 
        self.run_bzr('switch --create-branch ../branch2', working_dir='tree')
164
 
        tree = WorkingTree.open('tree')
165
 
        self.assertEndsWith(tree.branch.base, '/branch2/')
166
 
 
167
 
    def test_create_branch_local(self):
168
 
        branch = self.make_branch('branch')
169
 
        tree = branch.create_checkout('tree', lightweight=True)
170
 
        tree.commit('one', rev_id='rev-1')
171
 
        self.run_bzr('switch --create-branch branch2', working_dir='tree')
172
 
        tree = WorkingTree.open('tree')
173
 
        # The new branch should have been created at the same level as
174
 
        # 'branch', because we did not have a '/' segment
175
 
        self.assertEqual(branch.base[:-1] + '2/', tree.branch.base)
176
 
 
177
 
    def test_create_branch_short_name(self):
178
 
        branch = self.make_branch('branch')
179
 
        tree = branch.create_checkout('tree', lightweight=True)
180
 
        tree.commit('one', rev_id='rev-1')
181
 
        self.run_bzr('switch -b branch2', working_dir='tree')
182
 
        tree = WorkingTree.open('tree')
183
 
        # The new branch should have been created at the same level as
184
 
        # 'branch', because we did not have a '/' segment
185
 
        self.assertEqual(branch.base[:-1] + '2/', tree.branch.base)
 
65