~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2012-01-06 22:44:57 UTC
  • mfrom: (6436 +trunk)
  • mto: (6437.3.11 2.5)
  • mto: This revision was merged to the branch mainline in revision 6444.
  • Revision ID: jelmer@samba.org-20120106224457-re0pcy0fz31xob77
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2012 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,
28
29
    )
29
30
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
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
42
43
from bzrlib.workingtree import WorkingTree
43
44
 
44
45
 
45
 
class TestBranch(TestCaseWithTransport):
 
46
class TestBranch(tests.TestCaseWithTransport):
46
47
 
47
48
    def example_branch(self, path='.', format=None):
48
49
        tree = self.make_branch_and_tree(path, format=format)
78
79
        self.assertEqual('', out)
79
80
        self.assertEqual('Branched 2 revisions.\n', err)
80
81
        out, err = self.run_bzr('branches b')
81
 
        self.assertEqual(" thiswasa\n orig\n", out)
 
82
        self.assertEqual("  orig\n  thiswasa\n", out)
82
83
        self.assertEqual('', err)
83
84
        out,err = self.run_bzr('branch a file:b,branch=orig', retcode=3)
84
85
        self.assertEqual('', out)
85
 
        self.assertEqual('bzr: ERROR: Already a branch: "file:b,branch=orig".\n', err)
 
86
        self.assertEqual(
 
87
            'bzr: ERROR: Already a branch: "file:b,branch=orig".\n', err)
86
88
 
87
89
    def test_from_colocated(self):
88
90
        """Branch from a colocated branch into a regular branch."""
112
114
            else:
113
115
                corrupt = '\xFF'
114
116
            f.write(corrupt) # make sure we corrupt something
115
 
        self.run_bzr_error(['Corruption while decompressing repository file'], 
 
117
        self.run_bzr_error(['Corruption while decompressing repository file'],
116
118
                            'branch a b', retcode=3)
117
119
 
118
120
    def test_branch_switch_no_branch(self):
159
161
        #  => new branch will be created and checkout bound to the new branch
160
162
        self.example_branch('a')
161
163
        self.run_bzr('checkout a current')
162
 
        out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
 
164
        out, err = self.run_bzr('branch --switch ../a ../b',
 
165
                                working_dir='current')
163
166
        a = branch.Branch.open('a')
164
167
        b = branch.Branch.open('b')
165
168
        self.assertEqual(a.last_revision(), b.last_revision())
173
176
        #     the new branch
174
177
        self.example_branch('a')
175
178
        self.run_bzr('checkout --lightweight a current')
176
 
        out, err = self.run_bzr('branch --switch ../a ../b', working_dir='current')
 
179
        out, err = self.run_bzr('branch --switch ../a ../b',
 
180
                                working_dir='current')
177
181
        a = branch.Branch.open('a')
178
182
        b = branch.Branch.open('b')
179
183
        self.assertEqual(a.last_revision(), b.last_revision())
330
334
        builder = self.make_branch_builder('source')
331
335
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
332
336
        source.tags.set_tag('tag-a', 'rev-2')
333
 
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
337
        source.get_config_stack().set('branch.fetch_tags', True)
334
338
        # Now source has a tag not in its ancestry.  Make a branch from it.
335
339
        self.run_bzr('branch source new-branch')
336
340
        new_branch = branch.Branch.open('new-branch')
339
343
        new_branch.repository.get_revision('rev-2')
340
344
 
341
345
 
342
 
class TestBranchStacked(TestCaseWithTransport):
 
346
class TestBranchStacked(tests.TestCaseWithTransport):
343
347
    """Tests for branch --stacked"""
344
348
 
345
349
    def assertRevisionInRepository(self, repo_path, revid):
346
 
        """Check that a revision is in a repository, disregarding stacking."""
 
350
        """Check that a revision is in a repo, disregarding stacking."""
347
351
        repo = bzrdir.BzrDir.open(repo_path).open_repository()
348
352
        self.assertTrue(repo.has_revision(revid))
349
353
 
350
354
    def assertRevisionNotInRepository(self, repo_path, revid):
351
 
        """Check that a revision is not in a repository, disregarding stacking."""
 
355
        """Check that a revision is not in a repo, disregarding stacking."""
352
356
        repo = bzrdir.BzrDir.open(repo_path).open_repository()
353
357
        self.assertFalse(repo.has_revision(revid))
354
358
 
426
430
            trunk_tree.branch.base, err)
427
431
        self.assertRevisionNotInRepository('newbranch', original_revid)
428
432
        new_branch = branch.Branch.open('newbranch')
429
 
        self.assertEqual(trunk_tree.branch.base, new_branch.get_stacked_on_url())
 
433
        self.assertEqual(trunk_tree.branch.base,
 
434
                         new_branch.get_stacked_on_url())
430
435
 
431
436
    def test_branch_stacked_from_smart_server(self):
432
437
        # We can branch stacking on a smart server
467
472
            err)
468
473
 
469
474
 
470
 
class TestSmartServerBranching(TestCaseWithTransport):
 
475
class TestSmartServerBranching(tests.TestCaseWithTransport):
471
476
 
472
477
    def test_branch_from_trivial_branch_to_same_server_branch_acceptance(self):
473
478
        self.setup_smart_server_with_call_log()
482
487
        # being too low. If rpc_count increases, more network roundtrips have
483
488
        # become necessary for this use case. Please do not adjust this number
484
489
        # upwards without agreement from bzr's network support maintainers.
485
 
        self.assertLength(40, self.hpss_calls)
 
490
        self.assertLength(2, self.hpss_connections)
 
491
        self.assertLength(33, self.hpss_calls)
 
492
        self.expectFailure("branching to the same branch requires VFS access",
 
493
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
486
494
 
487
495
    def test_branch_from_trivial_branch_streaming_acceptance(self):
488
496
        self.setup_smart_server_with_call_log()
497
505
        # being too low. If rpc_count increases, more network roundtrips have
498
506
        # become necessary for this use case. Please do not adjust this number
499
507
        # upwards without agreement from bzr's network support maintainers.
 
508
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
500
509
        self.assertLength(10, self.hpss_calls)
 
510
        self.assertLength(1, self.hpss_connections)
501
511
 
502
512
    def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
503
513
        self.setup_smart_server_with_call_log()
518
528
        # become necessary for this use case. Please do not adjust this number
519
529
        # upwards without agreement from bzr's network support maintainers.
520
530
        self.assertLength(15, self.hpss_calls)
 
531
        self.assertLength(1, self.hpss_connections)
 
532
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
521
533
 
522
534
    def test_branch_from_branch_with_tags(self):
523
535
        self.setup_smart_server_with_call_log()
524
536
        builder = self.make_branch_builder('source')
525
537
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
526
 
        source.get_config().set_user_option('branch.fetch_tags', 'True')
 
538
        source.get_config_stack().set('branch.fetch_tags', True)
527
539
        source.tags.set_tag('tag-a', 'rev-2')
528
540
        source.tags.set_tag('tag-missing', 'missing-rev')
529
541
        # Now source has a tag not in its ancestry.  Make a branch from it.
535
547
        # become necessary for this use case. Please do not adjust this number
536
548
        # upwards without agreement from bzr's network support maintainers.
537
549
        self.assertLength(10, self.hpss_calls)
 
550
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
551
        self.assertLength(1, self.hpss_connections)
538
552
 
539
553
    def test_branch_to_stacked_from_trivial_branch_streaming_acceptance(self):
540
554
        self.setup_smart_server_with_call_log()
553
567
        readvs_of_rix_files = [
554
568
            c for c in self.hpss_calls
555
569
            if c.call.method == 'readv' and c.call.args[-1].endswith('.rix')]
 
570
        self.assertLength(1, self.hpss_connections)
556
571
        self.assertLength(0, readvs_of_rix_files)
 
572
        self.expectFailure("branching to stacked requires VFS access",
 
573
            self.assertThat, self.hpss_calls, ContainsNoVfsCalls)
557
574
 
558
575
 
559
576
class TestRemoteBranch(TestCaseWithSFTPServer):
580
597
        self.assertFalse(t.has('remote/file'))
581
598
 
582
599
 
583
 
class TestDeprecatedAliases(TestCaseWithTransport):
 
600
class TestDeprecatedAliases(tests.TestCaseWithTransport):
584
601
 
585
602
    def test_deprecated_aliases(self):
586
 
        """bzr branch can be called clone or get, but those names are deprecated.
 
603
        """bzr branch can be called clone or get, but those names are
 
604
        deprecated.
587
605
 
588
606
        See bug 506265.
589
607
        """