~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

(gz) Fix deprecations of win32utils path function unicode wrappers (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(" thiswasa\n orig\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
 
64
98
    def test_branch_broken_pack(self):
65
99
        """branching with a corrupted pack file."""
66
100
        self.example_branch('a')
67
 
        #now add some random corruption
68
 
        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]
69
104
        with open(fname, 'rb+') as f:
70
 
            f.seek(750)
71
 
            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
72
116
        self.run_bzr_error(['Corruption while decompressing repository file'], 
73
117
                            'branch a b', retcode=3)
74
118
 
147
191
 
148
192
        def make_shared_tree(path):
149
193
            shared_repo.bzrdir.root_transport.mkdir(path)
150
 
            shared_repo.bzrdir.create_branch_convenience('repo/' + path)
 
194
            controldir.ControlDir.create_branch_convenience('repo/' + path)
151
195
            return WorkingTree.open('repo/' + path)
152
196
        tree_a = make_shared_tree('a')
153
197
        self.build_tree(['repo/a/file'])
287
331
        builder = self.make_branch_builder('source')
288
332
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
289
333
        source.tags.set_tag('tag-a', 'rev-2')
 
334
        source.get_config().set_user_option('branch.fetch_tags', 'True')
290
335
        # Now source has a tag not in its ancestry.  Make a branch from it.
291
336
        self.run_bzr('branch source new-branch')
292
337
        new_branch = branch.Branch.open('new-branch')
331
376
        # mainline.
332
377
        out, err = self.run_bzr(['branch', 'branch', 'newbranch'])
333
378
        self.assertEqual('', out)
334
 
        self.assertEqual('Branched 2 revision(s).\n',
 
379
        self.assertEqual('Branched 2 revisions.\n',
335
380
            err)
336
381
        # it should have preserved the branch format, and so it should be
337
382
        # capable of supporting stacking, but not actually have a stacked_on
438
483
        # being too low. If rpc_count increases, more network roundtrips have
439
484
        # become necessary for this use case. Please do not adjust this number
440
485
        # upwards without agreement from bzr's network support maintainers.
441
 
        self.assertLength(36, self.hpss_calls)
 
486
        self.assertLength(33, self.hpss_calls)
 
487
        self.expectFailure("branching to the same branch requires VFS access",
 
488
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
442
489
 
443
490
    def test_branch_from_trivial_branch_streaming_acceptance(self):
444
491
        self.setup_smart_server_with_call_log()
453
500
        # being too low. If rpc_count increases, more network roundtrips have
454
501
        # become necessary for this use case. Please do not adjust this number
455
502
        # upwards without agreement from bzr's network support maintainers.
456
 
        self.assertLength(9, self.hpss_calls)
 
503
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
504
        self.assertLength(10, self.hpss_calls)
457
505
 
458
506
    def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
459
507
        self.setup_smart_server_with_call_log()
473
521
        # being too low. If rpc_count increases, more network roundtrips have
474
522
        # become necessary for this use case. Please do not adjust this number
475
523
        # upwards without agreement from bzr's network support maintainers.
476
 
        self.assertLength(14, self.hpss_calls)
 
524
        self.assertLength(15, self.hpss_calls)
 
525
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
477
526
 
478
527
    def test_branch_from_branch_with_tags(self):
479
528
        self.setup_smart_server_with_call_log()
480
529
        builder = self.make_branch_builder('source')
481
530
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
 
531
        source.get_config().set_user_option('branch.fetch_tags', 'True')
482
532
        source.tags.set_tag('tag-a', 'rev-2')
483
533
        source.tags.set_tag('tag-missing', 'missing-rev')
484
534
        # Now source has a tag not in its ancestry.  Make a branch from it.
489
539
        # being too low. If rpc_count increases, more network roundtrips have
490
540
        # become necessary for this use case. Please do not adjust this number
491
541
        # upwards without agreement from bzr's network support maintainers.
492
 
        self.assertLength(9, self.hpss_calls)
 
542
        self.assertLength(10, self.hpss_calls)
 
543
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
493
544
 
494
545
    def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
495
546
        self.setup_smart_server_with_call_log()
509
560
            c for c in self.hpss_calls
510
561
            if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
511
562
        self.assertLength(0, readvs_of_rix_files)
 
563
        self.expectFailure("branching to stacked requires VFS access",
 
564
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
512
565
 
513
566
 
514
567
class TestRemoteBranch(TestCaseWithSFTPServer):
557
610
                $ bzr checkout %(option)s repo/trunk checkout
558
611
                $ cd checkout
559
612
                $ bzr branch --switch ../repo/trunk ../repo/branched
560
 
                2>Branched 0 revision(s).
 
613
                2>Branched 0 revisions.
561
614
                2>Tree is up to date at revision 0.
562
615
                2>Switched to branch:...branched...
563
616
                $ cd ..