~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2012-02-20 12:19:29 UTC
  • mfrom: (6437.23.11 2.5)
  • mto: (6581.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6582.
  • Revision ID: jelmer@samba.org-20120220121929-7ni2psvjoatm1yp4
Merge bzr/2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
import os
22
22
 
 
23
from bzrlib.bzrdir import BzrDir
23
24
from bzrlib import (
24
25
        osutils,
25
26
        urlutils,
30
31
        TestCaseWithTransport,
31
32
        script,
32
33
        )
 
34
from bzrlib.tests.features import UnicodeFilenameFeature
33
35
from bzrlib.directory_service import directories
34
36
 
 
37
from bzrlib.tests.matchers import ContainsNoVfsCalls
 
38
 
35
39
 
36
40
class TestSwitch(TestCaseWithTransport):
37
41
 
152
156
        self.assertEqual(branchb_id, checkout.last_revision())
153
157
        self.assertEqual(tree2.branch.base, checkout.branch.get_bound_location())
154
158
 
 
159
    def test_switch_finds_relative_unicode_branch(self):
 
160
        """Switch will find 'foo' relative to the branch the checkout is of."""
 
161
        self.requireFeature(UnicodeFilenameFeature)
 
162
        self.build_tree(['repo/'])
 
163
        tree1 = self.make_branch_and_tree('repo/brancha')
 
164
        tree1.commit('foo')
 
165
        tree2 = self.make_branch_and_tree(u'repo/branch\xe9')
 
166
        tree2.pull(tree1.branch)
 
167
        branchb_id = tree2.commit('bar')
 
168
        checkout =  tree1.branch.create_checkout('checkout', lightweight=True)
 
169
        self.run_bzr(['switch', u'branch\xe9'], working_dir='checkout')
 
170
        self.assertEqual(branchb_id, checkout.last_revision())
 
171
        checkout = checkout.bzrdir.open_workingtree()
 
172
        self.assertEqual(tree2.branch.base, checkout.branch.base)
 
173
 
155
174
    def test_switch_revision(self):
156
175
        tree = self._create_sample_tree()
157
176
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
159
178
        self.assertPathExists('checkout/file-1')
160
179
        self.assertPathDoesNotExist('checkout/file-2')
161
180
 
 
181
    def test_switch_into_colocated(self):
 
182
        # Create a new colocated branch from an existing non-colocated branch.
 
183
        tree = self.make_branch_and_tree('.', format='development-colo')
 
184
        self.build_tree(['file-1', 'file-2'])
 
185
        tree.add('file-1')
 
186
        revid1 = tree.commit('rev1')
 
187
        tree.add('file-2')
 
188
        revid2 = tree.commit('rev2')
 
189
        self.run_bzr(['switch', '-b', 'anotherbranch'])
 
190
        self.assertEquals(
 
191
            set(['', 'anotherbranch']),
 
192
            set(tree.branch.bzrdir.get_branches().keys()))
 
193
 
 
194
    def test_switch_into_unrelated_colocated(self):
 
195
        # Create a new colocated branch from an existing non-colocated branch.
 
196
        tree = self.make_branch_and_tree('.', format='development-colo')
 
197
        self.build_tree(['file-1', 'file-2'])
 
198
        tree.add('file-1')
 
199
        revid1 = tree.commit('rev1')
 
200
        tree.add('file-2')
 
201
        revid2 = tree.commit('rev2')
 
202
        tree.bzrdir.create_branch(name='foo')
 
203
        self.run_bzr_error(['Cannot switch a branch, only a checkout.'],
 
204
            'switch foo')
 
205
        self.run_bzr(['switch', '--force', 'foo'])
 
206
 
 
207
    def test_switch_existing_colocated(self):
 
208
        # Create a branch branch-1 that initially is a checkout of 'foo'
 
209
        # Use switch to change it to 'anotherbranch'
 
210
        repo = self.make_repository('branch-1', format='development-colo')
 
211
        target_branch = repo.bzrdir.create_branch(name='foo')
 
212
        repo.bzrdir.set_branch_reference(target_branch)
 
213
        tree = repo.bzrdir.create_workingtree()
 
214
        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
 
215
        tree.add('file-1')
 
216
        revid1 = tree.commit('rev1')
 
217
        tree.add('file-2')
 
218
        revid2 = tree.commit('rev2')
 
219
        otherbranch = tree.bzrdir.create_branch(name='anotherbranch')
 
220
        otherbranch.generate_revision_history(revid1)
 
221
        self.run_bzr(['switch', 'anotherbranch'], working_dir='branch-1')
 
222
        tree = WorkingTree.open("branch-1")
 
223
        self.assertEquals(tree.last_revision(), revid1)
 
224
        self.assertEquals(tree.branch.control_url, otherbranch.control_url)
 
225
 
 
226
    def test_switch_new_colocated(self):
 
227
        # Create a branch branch-1 that initially is a checkout of 'foo'
 
228
        # Use switch to create 'anotherbranch' which derives from that
 
229
        repo = self.make_repository('branch-1', format='development-colo')
 
230
        target_branch = repo.bzrdir.create_branch(name='foo')
 
231
        repo.bzrdir.set_branch_reference(target_branch)
 
232
        tree = repo.bzrdir.create_workingtree()
 
233
        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
 
234
        tree.add('file-1')
 
235
        revid1 = tree.commit('rev1')
 
236
        self.run_bzr(['switch', '-b', 'anotherbranch'], working_dir='branch-1')
 
237
        bzrdir = BzrDir.open("branch-1")
 
238
        self.assertEquals(
 
239
            set([b.name for b in bzrdir.list_branches()]),
 
240
            set(["foo", "anotherbranch"]))
 
241
        self.assertEquals(bzrdir.open_branch().name, "anotherbranch")
 
242
        self.assertEquals(bzrdir.open_branch().last_revision(), revid1)
 
243
 
 
244
    def test_switch_new_colocated_unicode(self):
 
245
        # Create a branch branch-1 that initially is a checkout of 'foo'
 
246
        # Use switch to create 'branch\xe9' which derives from that
 
247
        self.requireFeature(UnicodeFilenameFeature)
 
248
        repo = self.make_repository('branch-1', format='development-colo')
 
249
        target_branch = repo.bzrdir.create_branch(name='foo')
 
250
        repo.bzrdir.set_branch_reference(target_branch)
 
251
        tree = repo.bzrdir.create_workingtree()
 
252
        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
 
253
        tree.add('file-1')
 
254
        revid1 = tree.commit('rev1')
 
255
        self.run_bzr(['switch', '-b', u'branch\xe9'], working_dir='branch-1')
 
256
        bzrdir = BzrDir.open("branch-1")
 
257
        self.assertEquals(
 
258
            set([b.name for b in bzrdir.list_branches()]),
 
259
            set(["foo", u"branch\xe9"]))
 
260
        self.assertEquals(bzrdir.open_branch().name, u"branch\xe9")
 
261
        self.assertEquals(bzrdir.open_branch().last_revision(), revid1)
 
262
 
162
263
    def test_switch_only_revision(self):
163
264
        tree = self._create_sample_tree()
164
265
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
352
453
        # This test should be cleaner to write, but see bug:
353
454
        #  https://bugs.launchpad.net/bzr/+bug/812295
354
455
        self.assertEqual(1, opened.count('master'))
 
456
 
 
457
 
 
458
class TestSmartServerSwitch(TestCaseWithTransport):
 
459
 
 
460
    def test_switch_lightweight(self):
 
461
        self.setup_smart_server_with_call_log()
 
462
        t = self.make_branch_and_tree('from')
 
463
        for count in range(9):
 
464
            t.commit(message='commit %d' % count)
 
465
        out, err = self.run_bzr(['checkout', '--lightweight', self.get_url('from'),
 
466
            'target'])
 
467
        self.reset_smart_call_log()
 
468
        self.run_bzr(['switch', self.get_url('from')], working_dir='target')
 
469
        # This figure represent the amount of work to perform this use case. It
 
470
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
471
        # being too low. If rpc_count increases, more network roundtrips have
 
472
        # become necessary for this use case. Please do not adjust this number
 
473
        # upwards without agreement from bzr's network support maintainers.
 
474
        self.assertLength(24, self.hpss_calls)
 
475
        self.assertLength(5, self.hpss_connections)
 
476
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)