~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2011-11-24 15:48:29 UTC
  • mfrom: (6289 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6337.
  • Revision ID: v.ladeuil+lp@free.fr-20111124154829-avowjpsxdl8yp2vz
merge trunk resolving conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
25
25
    controldir,
26
26
    errors,
27
27
    revision as _mod_revision,
28
 
    tests,
29
28
    )
30
29
from bzrlib.repofmt.knitrepo import RepositoryFormatKnit1
 
30
from bzrlib.tests import TestCaseWithTransport
31
31
from bzrlib.tests import (
32
32
    fixtures,
33
33
    test_server,
36
36
    HardlinkFeature,
37
37
    )
38
38
from bzrlib.tests.blackbox import test_switch
39
 
from bzrlib.tests.matchers import ContainsNoVfsCalls
40
39
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
41
40
from bzrlib.tests.script import run_script
42
41
from bzrlib.urlutils import local_path_to_url, strip_trailing_slash
43
42
from bzrlib.workingtree import WorkingTree
44
43
 
45
44
 
46
 
class TestBranch(tests.TestCaseWithTransport):
 
45
class TestBranch(TestCaseWithTransport):
47
46
 
48
47
    def example_branch(self, path='.', format=None):
49
48
        tree = self.make_branch_and_tree(path, format=format)
65
64
        self.assertFalse(b._transport.has('branch-name'))
66
65
        b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
67
66
 
68
 
    def test_branch_no_to_location(self):
69
 
        """The to_location is derived from the source branch name."""
70
 
        os.mkdir("something")
71
 
        a = self.example_branch('something/a').branch
72
 
        self.run_bzr('branch something/a')
73
 
        b = branch.Branch.open('a')
74
 
        self.assertEqual(b.last_revision_info(), a.last_revision_info())
75
 
 
76
67
    def test_into_colocated(self):
77
68
        """Branch from a branch into a colocated branch."""
78
69
        self.example_branch('a')
87
78
        self.assertEqual('', out)
88
79
        self.assertEqual('Branched 2 revisions.\n', err)
89
80
        out, err = self.run_bzr('branches b')
90
 
        self.assertEqual("  orig\n  thiswasa\n", out)
 
81
        self.assertEqual(" orig\n thiswasa\n", out)
91
82
        self.assertEqual('', err)
92
83
        out,err = self.run_bzr('branch a file:b,branch=orig', retcode=3)
93
84
        self.assertEqual('', out)
94
 
        self.assertEqual(
95
 
            'bzr: ERROR: Already a branch: "file:b,branch=orig".\n', err)
 
85
        self.assertEqual('bzr: ERROR: Already a branch: "file:b,branch=orig".\n', err)
96
86
 
97
87
    def test_from_colocated(self):
98
88
        """Branch from a colocated branch into a regular branch."""
122
112
            else:
123
113
                corrupt = '\xFF'
124
114
            f.write(corrupt) # make sure we corrupt something
125
 
        self.run_bzr_error(['Corruption while decompressing repository file'],
 
115
        self.run_bzr_error(['Corruption while decompressing repository file'], 
126
116
                            'branch a b', retcode=3)
127
117
 
128
118
    def test_branch_switch_no_branch(self):
155
145
        #  => new branch will be created, but switch fails and the current
156
146
        #     branch is unmodified
157
147
        self.example_branch('a')
158
 
        tree = self.make_branch_and_tree('current')
159
 
        c1 = tree.commit('some diverged change')
 
148
        self.make_branch_and_tree('current')
160
149
        self.run_bzr_error(['Cannot switch a branch, only a checkout'],
161
150
            'branch --switch ../a ../b', working_dir='current')
162
151
        a = branch.Branch.open('a')
163
152
        b = branch.Branch.open('b')
164
153
        self.assertEqual(a.last_revision(), b.last_revision())
165
154
        work = branch.Branch.open('current')
166
 
        self.assertEqual(work.last_revision(), c1)
167
 
 
168
 
    def test_branch_into_empty_dir(self):
169
 
        t = self.example_branch('source')
170
 
        self.make_bzrdir('target')
171
 
        self.run_bzr("branch source target")
172
 
        self.assertEqual(2, len(t.branch.repository.all_revision_ids()))
 
155
        self.assertEqual(work.last_revision(), _mod_revision.NULL_REVISION)
173
156
 
174
157
    def test_branch_switch_checkout(self):
175
158
        # Checkout in the current directory:
176
159
        #  => new branch will be created and checkout bound to the new branch
177
160
        self.example_branch('a')
178
161
        self.run_bzr('checkout a current')
179
 
        out, err = self.run_bzr('branch --switch ../a ../b',
180
 
                                working_dir='current')
 
162
        out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
181
163
        a = branch.Branch.open('a')
182
164
        b = branch.Branch.open('b')
183
165
        self.assertEqual(a.last_revision(), b.last_revision())
191
173
        #     the new branch
192
174
        self.example_branch('a')
193
175
        self.run_bzr('checkout --lightweight a current')
194
 
        out, err = self.run_bzr('branch --switch ../a ../b',
195
 
                                working_dir='current')
 
176
        out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
196
177
        a = branch.Branch.open('a')
197
178
        b = branch.Branch.open('b')
198
179
        self.assertEqual(a.last_revision(), b.last_revision())
349
330
        builder = self.make_branch_builder('source')
350
331
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
351
332
        source.tags.set_tag('tag-a', 'rev-2')
352
 
        source.get_config_stack().set('branch.fetch_tags', True)
 
333
        source.get_config().set_user_option('branch.fetch_tags', 'True')
353
334
        # Now source has a tag not in its ancestry.  Make a branch from it.
354
335
        self.run_bzr('branch source new-branch')
355
336
        new_branch = branch.Branch.open('new-branch')
358
339
        new_branch.repository.get_revision('rev-2')
359
340
 
360
341
 
361
 
class TestBranchStacked(tests.TestCaseWithTransport):
 
342
class TestBranchStacked(TestCaseWithTransport):
362
343
    """Tests for branch --stacked"""
363
344
 
364
345
    def assertRevisionInRepository(self, repo_path, revid):
365
 
        """Check that a revision is in a repo, disregarding stacking."""
366
 
        repo = controldir.ControlDir.open(repo_path).open_repository()
 
346
        """Check that a revision is in a repository, disregarding stacking."""
 
347
        repo = bzrdir.BzrDir.open(repo_path).open_repository()
367
348
        self.assertTrue(repo.has_revision(revid))
368
349
 
369
350
    def assertRevisionNotInRepository(self, repo_path, revid):
370
 
        """Check that a revision is not in a repo, disregarding stacking."""
371
 
        repo = controldir.ControlDir.open(repo_path).open_repository()
 
351
        """Check that a revision is not in a repository, disregarding stacking."""
 
352
        repo = bzrdir.BzrDir.open(repo_path).open_repository()
372
353
        self.assertFalse(repo.has_revision(revid))
373
354
 
374
355
    def assertRevisionsInBranchRepository(self, revid_list, branch_path):
400
381
        # capable of supporting stacking, but not actually have a stacked_on
401
382
        # branch configured
402
383
        self.assertRaises(errors.NotStacked,
403
 
            controldir.ControlDir.open('newbranch').open_branch().get_stacked_on_url)
 
384
            bzrdir.BzrDir.open('newbranch').open_branch().get_stacked_on_url)
404
385
 
405
386
    def test_branch_stacked_branch_stacked(self):
406
387
        """Asking to stack on a stacked branch does work"""
445
426
            trunk_tree.branch.base, err)
446
427
        self.assertRevisionNotInRepository('newbranch', original_revid)
447
428
        new_branch = branch.Branch.open('newbranch')
448
 
        self.assertEqual(trunk_tree.branch.base,
449
 
                         new_branch.get_stacked_on_url())
 
429
        self.assertEqual(trunk_tree.branch.base, new_branch.get_stacked_on_url())
450
430
 
451
431
    def test_branch_stacked_from_smart_server(self):
452
432
        # We can branch stacking on a smart server
487
467
            err)
488
468
 
489
469
 
490
 
class TestSmartServerBranching(tests.TestCaseWithTransport):
 
470
class TestSmartServerBranching(TestCaseWithTransport):
491
471
 
492
472
    def test_branch_from_trivial_branch_to_same_server_branch_acceptance(self):
493
473
        self.setup_smart_server_with_call_log()
502
482
        # being too low. If rpc_count increases, more network roundtrips have
503
483
        # become necessary for this use case. Please do not adjust this number
504
484
        # upwards without agreement from bzr's network support maintainers.
505
 
        self.assertLength(2, self.hpss_connections)
506
 
        self.assertLength(33, self.hpss_calls)
507
 
        self.expectFailure("branching to the same branch requires VFS access",
508
 
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
 
485
        self.assertLength(40, self.hpss_calls)
509
486
 
510
487
    def test_branch_from_trivial_branch_streaming_acceptance(self):
511
488
        self.setup_smart_server_with_call_log()
520
497
        # being too low. If rpc_count increases, more network roundtrips have
521
498
        # become necessary for this use case. Please do not adjust this number
522
499
        # upwards without agreement from bzr's network support maintainers.
523
 
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
524
500
        self.assertLength(10, self.hpss_calls)
525
 
        self.assertLength(1, self.hpss_connections)
526
501
 
527
502
    def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
528
503
        self.setup_smart_server_with_call_log()
543
518
        # become necessary for this use case. Please do not adjust this number
544
519
        # upwards without agreement from bzr's network support maintainers.
545
520
        self.assertLength(15, self.hpss_calls)
546
 
        self.assertLength(1, self.hpss_connections)
547
 
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
548
521
 
549
522
    def test_branch_from_branch_with_tags(self):
550
523
        self.setup_smart_server_with_call_log()
551
524
        builder = self.make_branch_builder('source')
552
525
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
553
 
        source.get_config_stack().set('branch.fetch_tags', True)
 
526
        source.get_config().set_user_option('branch.fetch_tags', 'True')
554
527
        source.tags.set_tag('tag-a', 'rev-2')
555
528
        source.tags.set_tag('tag-missing', 'missing-rev')
556
529
        # Now source has a tag not in its ancestry.  Make a branch from it.
562
535
        # become necessary for this use case. Please do not adjust this number
563
536
        # upwards without agreement from bzr's network support maintainers.
564
537
        self.assertLength(10, self.hpss_calls)
565
 
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
566
 
        self.assertLength(1, self.hpss_connections)
567
538
 
568
539
    def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
569
540
        self.setup_smart_server_with_call_log()
582
553
        readvs_of_rix_files = [
583
554
            c for c in self.hpss_calls
584
555
            if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
585
 
        self.assertLength(1, self.hpss_connections)
586
556
        self.assertLength(0, readvs_of_rix_files)
587
 
        self.expectFailure("branching to stacked requires VFS access",
588
 
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
589
557
 
590
558
 
591
559
class TestRemoteBranch(TestCaseWithSFTPServer):
612
580
        self.assertFalse(t.has('remote/file'))
613
581
 
614
582
 
615
 
class TestDeprecatedAliases(tests.TestCaseWithTransport):
 
583
class TestDeprecatedAliases(TestCaseWithTransport):
616
584
 
617
585
    def test_deprecated_aliases(self):
618
 
        """bzr branch can be called clone or get, but those names are
619
 
        deprecated.
 
586
        """bzr branch can be called clone or get, but those names are deprecated.
620
587
 
621
588
        See bug 506265.
622
589
        """