~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

(gz) Remove bzrlib/util/elementtree/ package (Martin Packman)

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,
 
33
    test_server,
 
34
    )
 
35
from bzrlib.tests.features import (
32
36
    HardlinkFeature,
33
 
    script,
34
 
    test_server,
35
37
    )
36
38
from bzrlib.tests.blackbox import test_switch
 
39
from bzrlib.tests.matchers import ContainsNoVfsCalls
37
40
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
38
41
from bzrlib.tests.script import run_script
39
42
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
42
45
 
43
46
class TestBranch(TestCaseWithTransport):
44
47
 
45
 
    def example_branch(self, path='.'):
46
 
        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)
47
50
        self.build_tree_contents([(path + '/hello', 'foo')])
48
51
        tree.add('hello')
49
52
        tree.commit(message='setup')
50
53
        self.build_tree_contents([(path + '/goodbye', 'baz')])
51
54
        tree.add('goodbye')
52
55
        tree.commit(message='setup')
 
56
        return tree
53
57
 
54
58
    def test_branch(self):
55
59
        """Branch from one branch to another."""
61
65
        self.assertFalse(b._transport.has('branch-name'))
62
66
        b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
63
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
 
 
98
    def test_branch_broken_pack(self):
 
99
        """branching with a corrupted pack file."""
 
100
        self.example_branch('a')
 
101
        # add some corruption
 
102
        packs_dir = 'a/.bzr/repository/packs/'
 
103
        fname = packs_dir + os.listdir(packs_dir)[0]
 
104
        with open(fname, 'rb+') as f:
 
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
 
116
        self.run_bzr_error(['Corruption while decompressing repository file'], 
 
117
                            'branch a b', retcode=3)
 
118
 
64
119
    def test_branch_switch_no_branch(self):
65
120
        # No branch in the current directory:
66
121
        #  => new branch will be created, but switch fails
136
191
 
137
192
        def make_shared_tree(path):
138
193
            shared_repo.bzrdir.root_transport.mkdir(path)
139
 
            shared_repo.bzrdir.create_branch_convenience('repo/' + path)
 
194
            controldir.ControlDir.create_branch_convenience('repo/' + path)
140
195
            return WorkingTree.open('repo/' + path)
141
196
        tree_a = make_shared_tree('a')
142
197
        self.build_tree(['repo/a/file'])
276
331
        builder = self.make_branch_builder('source')
277
332
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
278
333
        source.tags.set_tag('tag-a', 'rev-2')
 
334
        source.get_config_stack().set('branch.fetch_tags', True)
279
335
        # Now source has a tag not in its ancestry.  Make a branch from it.
280
336
        self.run_bzr('branch source new-branch')
281
337
        new_branch = branch.Branch.open('new-branch')
320
376
        # mainline.
321
377
        out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
322
378
        self.assertEqual('', out)
323
 
        self.assertEqual('Branched 2 revision(s).\n',
 
379
        self.assertEqual('Branched 2 revisions.\n',
324
380
            err)
325
381
        # it should have preserved the branch format, and so it should be
326
382
        # capable of supporting stacking, but not actually have a stacked_on
427
483
        # being too low. If rpc_count increases, more network roundtrips have
428
484
        # become necessary for this use case. Please do not adjust this number
429
485
        # upwards without agreement from bzr's network support maintainers.
430
 
        self.assertLength(36, 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)
431
490
 
432
491
    def test_branch_from_trivial_branch_streaming_acceptance(self):
433
492
        self.setup_smart_server_with_call_log()
442
501
        # being too low. If rpc_count increases, more network roundtrips have
443
502
        # become necessary for this use case. Please do not adjust this number
444
503
        # upwards without agreement from bzr's network support maintainers.
445
 
        self.assertLength(9, self.hpss_calls)
 
504
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
505
        self.assertLength(10, self.hpss_calls)
 
506
        self.assertLength(1, self.hpss_connections)
446
507
 
447
508
    def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
448
509
        self.setup_smart_server_with_call_log()
462
523
        # being too low. If rpc_count increases, more network roundtrips have
463
524
        # become necessary for this use case. Please do not adjust this number
464
525
        # upwards without agreement from bzr's network support maintainers.
465
 
        self.assertLength(14, self.hpss_calls)
 
526
        self.assertLength(15, self.hpss_calls)
 
527
        self.assertLength(1, self.hpss_connections)
 
528
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
466
529
 
467
530
    def test_branch_from_branch_with_tags(self):
468
531
        self.setup_smart_server_with_call_log()
469
532
        builder = self.make_branch_builder('source')
470
533
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
534
        source.get_config_stack().set('branch.fetch_tags', True)
471
535
        source.tags.set_tag('tag-a', 'rev-2')
472
536
        source.tags.set_tag('tag-missing', 'missing-rev')
473
537
        # Now source has a tag not in its ancestry.  Make a branch from it.
478
542
        # being too low. If rpc_count increases, more network roundtrips have
479
543
        # become necessary for this use case. Please do not adjust this number
480
544
        # upwards without agreement from bzr's network support maintainers.
481
 
        self.assertLength(9, self.hpss_calls)
 
545
        self.assertLength(10, self.hpss_calls)
 
546
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
547
        self.assertLength(1, self.hpss_connections)
482
548
 
483
549
    def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
484
550
        self.setup_smart_server_with_call_log()
497
563
        readvs_of_rix_files = [
498
564
            c for c in self.hpss_calls
499
565
            if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
 
566
        self.assertLength(1, self.hpss_connections)
500
567
        self.assertLength(0, readvs_of_rix_files)
 
568
        self.expectFailure("branching to stacked requires VFS access",
 
569
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
501
570
 
502
571
 
503
572
class TestRemoteBranch(TestCaseWithSFTPServer):
546
615
                $ bzr checkout %(option)s repo/trunk checkout
547
616
                $ cd checkout
548
617
                $ bzr branch --switch ../repo/trunk ../repo/branched
549
 
                2>Branched 0 revision(s).
 
618
                2>Branched 0 revisions.
550
619
                2>Tree is up to date at revision 0.
551
620
                2>Switched to branch:...branched...
552
621
                $ cd ..