~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Mark Hammond
  • Date: 2009-01-12 01:55:34 UTC
  • mto: (3995.8.2 prepare-1.12)
  • mto: This revision was merged to the branch mainline in revision 4007.
  • Revision ID: mhammond@skippinet.com.au-20090112015534-yfxg50p7mpds9j4v
Include all .html files from the tortoise doc directory.

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."""
22
22
 
23
23
from bzrlib.workingtree import WorkingTree
24
24
from bzrlib.tests.blackbox import ExternalBase
25
 
from bzrlib.directory_service import directories
26
25
 
27
26
 
28
27
class TestSwitch(ExternalBase):
29
28
 
30
 
    def _create_sample_tree(self):
31
 
        tree = self.make_branch_and_tree('branch-1')
32
 
        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
33
 
        tree.add('file-1')
34
 
        tree.commit('rev1')
35
 
        tree.add('file-2')
36
 
        tree.commit('rev2')
37
 
        return tree
38
 
 
39
29
    def test_switch_up_to_date_light_checkout(self):
40
30
        self.make_branch_and_tree('branch')
41
31
        self.run_bzr('branch branch branch2')
127
117
    def test_switch_finds_relative_bound_branch(self):
128
118
        """Using switch on a heavy checkout should find master sibling
129
119
 
130
 
        The behaviour of lighweight and heavy checkouts should be
 
120
        The behaviour of lighweight and heavy checkouts should be 
131
121
        consistentwhen using the convenient "switch to sibling" feature
132
122
        Both should switch to a sibling of the branch
133
123
        they are bound to, and not a sibling of themself"""
143
133
        self.run_bzr(['switch', 'branchb'], working_dir='heavyco/a')
144
134
        self.assertEqual(branchb_id, checkout.last_revision())
145
135
        self.assertEqual(tree2.branch.base, checkout.branch.get_bound_location())
146
 
 
147
 
    def test_switch_revision(self):
148
 
        tree = self._create_sample_tree()
149
 
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
150
 
        self.run_bzr(['switch', 'branch-1', '-r1'], working_dir='checkout')
151
 
        self.failUnlessExists('checkout/file-1')
152
 
        self.failIfExists('checkout/file-2')
153
 
 
154
 
    def test_switch_only_revision(self):
155
 
        tree = self._create_sample_tree()
156
 
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
157
 
        self.failUnlessExists('checkout/file-1')
158
 
        self.failUnlessExists('checkout/file-2')
159
 
        self.run_bzr(['switch', '-r1'], working_dir='checkout')
160
 
        self.failUnlessExists('checkout/file-1')
161
 
        self.failIfExists('checkout/file-2')
162
 
        # Check that we don't accept a range
163
 
        self.run_bzr_error(
164
 
            ['bzr switch --revision takes exactly one revision identifier'],
165
 
            ['switch', '-r0..2'], working_dir='checkout')
166
 
 
167
 
    def prepare_lightweight_switch(self):
168
 
        branch = self.make_branch('branch')
169
 
        branch.create_checkout('tree', lightweight=True)
170
 
        os.rename('branch', 'branch1')
171
 
 
172
 
    def test_switch_lightweight_after_branch_moved(self):
173
 
        self.prepare_lightweight_switch()
174
 
        self.run_bzr('switch --force ../branch1', working_dir='tree')
175
 
        branch_location = WorkingTree.open('tree').branch.base
176
 
        self.assertEndsWith(branch_location, 'branch1/')
177
 
 
178
 
    def test_switch_lightweight_after_branch_moved_relative(self):
179
 
        self.prepare_lightweight_switch()
180
 
        self.run_bzr('switch --force branch1', working_dir='tree')
181
 
        branch_location = WorkingTree.open('tree').branch.base
182
 
        self.assertEndsWith(branch_location, 'branch1/')
183
 
 
184
 
    def test_create_branch_no_branch(self):
185
 
        self.prepare_lightweight_switch()
186
 
        self.run_bzr_error(['cannot create branch without source branch'],
187
 
            'switch --create-branch ../branch2', working_dir='tree')
188
 
 
189
 
    def test_create_branch(self):
190
 
        branch = self.make_branch('branch')
191
 
        tree = branch.create_checkout('tree', lightweight=True)
192
 
        tree.commit('one', rev_id='rev-1')
193
 
        self.run_bzr('switch --create-branch ../branch2', working_dir='tree')
194
 
        tree = WorkingTree.open('tree')
195
 
        self.assertEndsWith(tree.branch.base, '/branch2/')
196
 
 
197
 
    def test_create_branch_local(self):
198
 
        branch = self.make_branch('branch')
199
 
        tree = branch.create_checkout('tree', lightweight=True)
200
 
        tree.commit('one', rev_id='rev-1')
201
 
        self.run_bzr('switch --create-branch branch2', working_dir='tree')
202
 
        tree = WorkingTree.open('tree')
203
 
        # The new branch should have been created at the same level as
204
 
        # 'branch', because we did not have a '/' segment
205
 
        self.assertEqual(branch.base[:-1] + '2/', tree.branch.base)
206
 
 
207
 
    def test_create_branch_short_name(self):
208
 
        branch = self.make_branch('branch')
209
 
        tree = branch.create_checkout('tree', lightweight=True)
210
 
        tree.commit('one', rev_id='rev-1')
211
 
        self.run_bzr('switch -b branch2', working_dir='tree')
212
 
        tree = WorkingTree.open('tree')
213
 
        # The new branch should have been created at the same level as
214
 
        # 'branch', because we did not have a '/' segment
215
 
        self.assertEqual(branch.base[:-1] + '2/', tree.branch.base)
216
 
 
217
 
    def test_create_branch_directory_services(self):
218
 
        branch = self.make_branch('branch')
219
 
        tree = branch.create_checkout('tree', lightweight=True)
220
 
        class FooLookup(object):
221
 
            def look_up(self, name, url):
222
 
                return 'foo-'+name
223
 
        directories.register('foo:', FooLookup, 'Create branches named foo-')
224
 
        self.addCleanup(directories.remove, 'foo:')
225
 
        self.run_bzr('switch -b foo:branch2', working_dir='tree')
226
 
        tree = WorkingTree.open('tree')
227
 
        self.assertEndsWith(tree.branch.base, 'foo-branch2/')