~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_branch.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:
22
22
from bzrlib import (
23
23
    branch,
24
24
    bzrdir,
 
25
    controldir,
25
26
    errors,
26
27
    revision as _mod_revision,
27
28
    )
29
30
from bzrlib.tests import TestCaseWithTransport
30
31
from bzrlib.tests import (
31
32
    fixtures,
32
 
    script,
33
33
    test_server,
34
34
    )
35
35
from bzrlib.tests.features import (
36
36
    HardlinkFeature,
37
37
    )
38
38
from bzrlib.tests.blackbox import test_switch
 
39
from bzrlib.tests.matchers import ContainsNoVfsCalls
39
40
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
40
41
from bzrlib.tests.script import run_script
41
42
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
44
45
 
45
46
class TestBranch(TestCaseWithTransport):
46
47
 
47
 
    def example_branch(self, path='.'):
48
 
        tree = self.make_branch_and_tree(path)
 
48
    def example_branch(self, path='.', format=None):
 
49
        tree = self.make_branch_and_tree(path, format=format)
49
50
        self.build_tree_contents([(path + '/hello', 'foo')])
50
51
        tree.add('hello')
51
52
        tree.commit(message='setup')
52
53
        self.build_tree_contents([(path + '/goodbye', 'baz')])
53
54
        tree.add('goodbye')
54
55
        tree.commit(message='setup')
 
56
        return tree
55
57
 
56
58
    def test_branch(self):
57
59
        """Branch from one branch to another."""
63
65
        self.assertFalse(b._transport.has('branch-name'))
64
66
        b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
65
67
 
 
68
    def test_into_colocated(self):
 
69
        """Branch from a branch into a colocated branch."""
 
70
        self.example_branch('a')
 
71
        out, err = self.run_bzr(
 
72
            'init --format=development-colo file:b,branch=orig')
 
73
        self.assertEqual(
 
74
            """Created a lightweight checkout (format: development-colo)\n""",
 
75
            out)
 
76
        self.assertEqual('', err)
 
77
        out, err = self.run_bzr(
 
78
            'branch a file:b,branch=thiswasa')
 
79
        self.assertEqual('', out)
 
80
        self.assertEqual('Branched 2 revisions.\n', err)
 
81
        out, err = self.run_bzr('branches b')
 
82
        self.assertEqual("  orig\n  thiswasa\n", out)
 
83
        self.assertEqual('', err)
 
84
        out,err = self.run_bzr('branch a file:b,branch=orig', retcode=3)
 
85
        self.assertEqual('', out)
 
86
        self.assertEqual('bzr: ERROR: Already a branch: "file:b,branch=orig".\n', err)
 
87
 
 
88
    def test_from_colocated(self):
 
89
        """Branch from a colocated branch into a regular branch."""
 
90
        tree = self.example_branch('a', format='development-colo')
 
91
        tree.bzrdir.create_branch(name='somecolo')
 
92
        out, err = self.run_bzr('branch %s,branch=somecolo' %
 
93
            local_path_to_url('a'))
 
94
        self.assertEqual('', out)
 
95
        self.assertEqual('Branched 0 revisions.\n', err)
 
96
        self.assertPathExists("somecolo")
 
97
 
66
98
    def test_branch_broken_pack(self):
67
99
        """branching with a corrupted pack file."""
68
100
        self.example_branch('a')
69
 
        #now add some random corruption
70
 
        fname = 'a/.bzr/repository/packs/' + os.listdir('a/.bzr/repository/packs')[0]
 
101
        # add some corruption
 
102
        packs_dir = 'a/.bzr/repository/packs/'
 
103
        fname = packs_dir + os.listdir(packs_dir)[0]
71
104
        with open(fname, 'rb+') as f:
72
 
            f.seek(750)
73
 
            f.write("\xff")
 
105
            # Start from the end of the file to avoid choosing a place bigger
 
106
            # than the file itself.
 
107
            f.seek(-5, os.SEEK_END)
 
108
            c = f.read(1)
 
109
            f.seek(-5, os.SEEK_END)
 
110
            # Make sure we inject a value different than the one we just read
 
111
            if c == '\xFF':
 
112
                corrupt = '\x00'
 
113
            else:
 
114
                corrupt = '\xFF'
 
115
            f.write(corrupt) # make sure we corrupt something
74
116
        self.run_bzr_error(['Corruption while decompressing repository file'], 
75
117
                            'branch a b', retcode=3)
76
118
 
149
191
 
150
192
        def make_shared_tree(path):
151
193
            shared_repo.bzrdir.root_transport.mkdir(path)
152
 
            shared_repo.bzrdir.create_branch_convenience('repo/' + path)
 
194
            controldir.ControlDir.create_branch_convenience('repo/' + path)
153
195
            return WorkingTree.open('repo/' + path)
154
196
        tree_a = make_shared_tree('a')
155
197
        self.build_tree(['repo/a/file'])
289
331
        builder = self.make_branch_builder('source')
290
332
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
291
333
        source.tags.set_tag('tag-a', 'rev-2')
292
 
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
334
        source.get_config_stack().set('branch.fetch_tags', True)
293
335
        # Now source has a tag not in its ancestry.  Make a branch from it.
294
336
        self.run_bzr('branch source new-branch')
295
337
        new_branch = branch.Branch.open('new-branch')
334
376
        # mainline.
335
377
        out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
336
378
        self.assertEqual('', out)
337
 
        self.assertEqual('Branched 2 revision(s).\n',
 
379
        self.assertEqual('Branched 2 revisions.\n',
338
380
            err)
339
381
        # it should have preserved the branch format, and so it should be
340
382
        # capable of supporting stacking, but not actually have a stacked_on
441
483
        # being too low. If rpc_count increases, more network roundtrips have
442
484
        # become necessary for this use case. Please do not adjust this number
443
485
        # upwards without agreement from bzr's network support maintainers.
444
 
        self.assertLength(37, self.hpss_calls)
 
486
        self.assertLength(2, self.hpss_connections)
 
487
        self.assertLength(33, self.hpss_calls)
 
488
        self.expectFailure("branching to the same branch requires VFS access",
 
489
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
445
490
 
446
491
    def test_branch_from_trivial_branch_streaming_acceptance(self):
447
492
        self.setup_smart_server_with_call_log()
456
501
        # being too low. If rpc_count increases, more network roundtrips have
457
502
        # become necessary for this use case. Please do not adjust this number
458
503
        # upwards without agreement from bzr's network support maintainers.
 
504
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
459
505
        self.assertLength(10, self.hpss_calls)
 
506
        self.assertLength(1, self.hpss_connections)
460
507
 
461
508
    def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
462
509
        self.setup_smart_server_with_call_log()
477
524
        # become necessary for this use case. Please do not adjust this number
478
525
        # upwards without agreement from bzr's network support maintainers.
479
526
        self.assertLength(15, self.hpss_calls)
 
527
        self.assertLength(1, self.hpss_connections)
 
528
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
480
529
 
481
530
    def test_branch_from_branch_with_tags(self):
482
531
        self.setup_smart_server_with_call_log()
483
532
        builder = self.make_branch_builder('source')
484
533
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
485
 
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
534
        source.get_config_stack().set('branch.fetch_tags', True)
486
535
        source.tags.set_tag('tag-a', 'rev-2')
487
536
        source.tags.set_tag('tag-missing', 'missing-rev')
488
537
        # Now source has a tag not in its ancestry.  Make a branch from it.
494
543
        # become necessary for this use case. Please do not adjust this number
495
544
        # upwards without agreement from bzr's network support maintainers.
496
545
        self.assertLength(10, self.hpss_calls)
 
546
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
547
        self.assertLength(1, self.hpss_connections)
497
548
 
498
549
    def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
499
550
        self.setup_smart_server_with_call_log()
512
563
        readvs_of_rix_files = [
513
564
            c for c in self.hpss_calls
514
565
            if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
 
566
        self.assertLength(1, self.hpss_connections)
515
567
        self.assertLength(0, readvs_of_rix_files)
 
568
        self.expectFailure("branching to stacked requires VFS access",
 
569
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
516
570
 
517
571
 
518
572
class TestRemoteBranch(TestCaseWithSFTPServer):
561
615
                $ bzr checkout %(option)s repo/trunk checkout
562
616
                $ cd checkout
563
617
                $ bzr branch --switch ../repo/trunk ../repo/branched
564
 
                2>Branched 0 revision(s).
 
618
                2>Branched 0 revisions.
565
619
                2>Tree is up to date at revision 0.
566
620
                2>Switched to branch:...branched...
567
621
                $ cd ..