~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Packman
  • Date: 2012-01-05 09:50:04 UTC
  • mfrom: (6424 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6426.
  • Revision ID: martin.packman@canonical.com-20120105095004-mia9xb7y0efmto0v
Merge bzr.dev to resolve conflicts in bzrlib.builtins

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_existing_colocated(self):
 
182
        # Create a branch branch-1 that initially is a checkout of 'foo'
 
183
        # Use switch to change it to 'anotherbranch'
 
184
        repo = self.make_repository('branch-1', format='development-colo')
 
185
        target_branch = repo.bzrdir.create_branch(name='foo')
 
186
        branch.BranchReferenceFormat().initialize(
 
187
            repo.bzrdir, target_branch=target_branch)
 
188
        tree = repo.bzrdir.create_workingtree()
 
189
        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
 
190
        tree.add('file-1')
 
191
        revid1 = tree.commit('rev1')
 
192
        tree.add('file-2')
 
193
        revid2 = tree.commit('rev2')
 
194
        otherbranch = tree.bzrdir.create_branch(name='anotherbranch')
 
195
        otherbranch.generate_revision_history(revid1)
 
196
        self.run_bzr(['switch', 'anotherbranch'], working_dir='branch-1')
 
197
        tree = WorkingTree.open("branch-1")
 
198
        self.assertEquals(tree.last_revision(), revid1)
 
199
        self.assertEquals(tree.branch.control_url, otherbranch.control_url)
 
200
 
 
201
    def test_switch_new_colocated(self):
 
202
        # Create a branch branch-1 that initially is a checkout of 'foo'
 
203
        # Use switch to create 'anotherbranch' which derives from that
 
204
        repo = self.make_repository('branch-1', format='development-colo')
 
205
        target_branch = repo.bzrdir.create_branch(name='foo')
 
206
        branch.BranchReferenceFormat().initialize(
 
207
            repo.bzrdir, target_branch=target_branch)
 
208
        tree = repo.bzrdir.create_workingtree()
 
209
        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
 
210
        tree.add('file-1')
 
211
        revid1 = tree.commit('rev1')
 
212
        self.run_bzr(['switch', '-b', 'anotherbranch'], working_dir='branch-1')
 
213
        bzrdir = BzrDir.open("branch-1")
 
214
        self.assertEquals(
 
215
            set([b.name for b in bzrdir.list_branches()]),
 
216
            set(["foo", "anotherbranch"]))
 
217
        self.assertEquals(bzrdir.open_branch().name, "anotherbranch")
 
218
        self.assertEquals(bzrdir.open_branch().last_revision(), revid1)
 
219
 
 
220
    def test_switch_new_colocated_unicode(self):
 
221
        # Create a branch branch-1 that initially is a checkout of 'foo'
 
222
        # Use switch to create 'branch\xe9' which derives from that
 
223
        self.requireFeature(UnicodeFilenameFeature)
 
224
        repo = self.make_repository('branch-1', format='development-colo')
 
225
        target_branch = repo.bzrdir.create_branch(name='foo')
 
226
        branch.BranchReferenceFormat().initialize(
 
227
            repo.bzrdir, target_branch=target_branch)
 
228
        tree = repo.bzrdir.create_workingtree()
 
229
        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
 
230
        tree.add('file-1')
 
231
        revid1 = tree.commit('rev1')
 
232
        self.run_bzr(['switch', '-b', u'branch\xe9'], working_dir='branch-1')
 
233
        bzrdir = BzrDir.open("branch-1")
 
234
        self.assertEquals(
 
235
            set([b.name for b in bzrdir.list_branches()]),
 
236
            set(["foo", u"branch\xe9"]))
 
237
        self.assertEquals(bzrdir.open_branch().name, u"branch\xe9")
 
238
        self.assertEquals(bzrdir.open_branch().last_revision(), revid1)
 
239
 
162
240
    def test_switch_only_revision(self):
163
241
        tree = self._create_sample_tree()
164
242
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
352
430
        # This test should be cleaner to write, but see bug:
353
431
        #  https://bugs.launchpad.net/bzr/+bug/812295
354
432
        self.assertEqual(1, opened.count('master'))
 
433
 
 
434
 
 
435
class TestSmartServerSwitch(TestCaseWithTransport):
 
436
 
 
437
    def test_switch_lightweight(self):
 
438
        self.setup_smart_server_with_call_log()
 
439
        t = self.make_branch_and_tree('from')
 
440
        for count in range(9):
 
441
            t.commit(message='commit %d' % count)
 
442
        out, err = self.run_bzr(['checkout', '--lightweight', self.get_url('from'),
 
443
            'target'])
 
444
        self.reset_smart_call_log()
 
445
        self.run_bzr(['switch', self.get_url('from')], working_dir='target')
 
446
        # This figure represent the amount of work to perform this use case. It
 
447
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
448
        # being too low. If rpc_count increases, more network roundtrips have
 
449
        # become necessary for this use case. Please do not adjust this number
 
450
        # upwards without agreement from bzr's network support maintainers.
 
451
        self.assertLength(24, self.hpss_calls)
 
452
        self.assertLength(5, self.hpss_connections)
 
453
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)