~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-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
    gpg,
26
26
    merge,
27
27
    urlutils,
28
 
    transactions,
29
28
    transport,
30
29
    remote,
31
30
    repository,
32
31
    revision,
33
32
    tests,
34
33
    )
35
 
from bzrlib.symbol_versioning import deprecated_in
36
34
from bzrlib.tests import (
37
 
    http_server,
38
35
    per_branch,
39
36
    )
40
37
from bzrlib.tests.http_server import HttpServer
187
184
        self.assertEqual(branch_b.get_parent(), branch_c.get_parent())
188
185
 
189
186
        # We can also set a specific parent, and it should be honored
190
 
        random_parent = 'http://bazaar-vcs.org/path/to/branch'
 
187
        random_parent = 'http://example.com/path/to/branch'
191
188
        branch_b.set_parent(random_parent)
192
189
        repo_d = self.make_repository('d')
193
190
        branch_b.repository.copy_content_into(repo_d)
310
307
        self.assertEqual(repo.get_signature_text('A'),
311
308
                         d2.open_repository().get_signature_text('A'))
312
309
 
313
 
    def test_missing_revisions(self):
314
 
        t1 = self.make_branch_and_tree('b1')
315
 
        rev1 = t1.commit('one')
316
 
        t2 = t1.bzrdir.sprout('b2').open_workingtree()
317
 
        rev2 = t1.commit('two')
318
 
        rev3 = t1.commit('three')
319
 
 
320
 
        self.assertEqual([rev2, rev3],
321
 
            self.applyDeprecated(deprecated_in((1, 6, 0)),
322
 
            t2.branch.missing_revisions, t1.branch))
323
 
 
324
 
        self.assertEqual([],
325
 
            self.applyDeprecated(deprecated_in((1, 6, 0)),
326
 
            t2.branch.missing_revisions, t1.branch, stop_revision=1))
327
 
        self.assertEqual([rev2],
328
 
            self.applyDeprecated(deprecated_in((1, 6, 0)),
329
 
            t2.branch.missing_revisions, t1.branch, stop_revision=2))
330
 
        self.assertEqual([rev2, rev3],
331
 
            self.applyDeprecated(deprecated_in((1, 6, 0)),
332
 
            t2.branch.missing_revisions, t1.branch, stop_revision=3))
333
 
 
334
 
        self.assertRaises(errors.NoSuchRevision,
335
 
            self.applyDeprecated, deprecated_in((1, 6, 0)),
336
 
            t2.branch.missing_revisions, t1.branch, stop_revision=4)
337
 
 
338
 
        rev4 = t2.commit('four')
339
 
        self.assertRaises(errors.DivergedBranches,
340
 
            self.applyDeprecated, deprecated_in((1, 6, 0)),
341
 
            t2.branch.missing_revisions, t1.branch)
342
 
 
343
310
    def test_nicks(self):
344
311
        """Test explicit and implicit branch nicknames.
345
312
 
347
314
        explicit nickname is set.  That is, an explicit nickname always
348
315
        overrides the implicit one.
349
316
        """
350
 
        t = transport.get_transport(self.get_url())
 
317
        t = self.get_transport()
351
318
        branch = self.make_branch('bzr.dev')
352
319
        # The nick will be 'bzr.dev', because there is no explicit nick set.
353
320
        self.assertEqual(branch.nick, 'bzr.dev')
497
464
        br.set_revision_history([])
498
465
        self.assertEquals(br.revision_history(), [])
499
466
 
 
467
    def test_heads_to_fetch(self):
 
468
        # heads_to_fetch is a method that returns a collection of revids that
 
469
        # need to be fetched to copy this branch into another repo.  At a
 
470
        # minimum this will include the tip.
 
471
        # (In native formats, this is the tip + tags, but other formats may
 
472
        # have other revs needed)
 
473
        tree = self.make_branch_and_tree('a')
 
474
        tree.commit('first commit', rev_id='rev1')
 
475
        tree.commit('second commit', rev_id='rev2')
 
476
        must_fetch, should_fetch = tree.branch.heads_to_fetch()
 
477
        self.assertTrue('rev2' in must_fetch)
 
478
 
 
479
    def test_heads_to_fetch_not_null_revision(self):
 
480
        # NULL_REVISION does not appear in the result of heads_to_fetch, even
 
481
        # for an empty branch.
 
482
        tree = self.make_branch_and_tree('a')
 
483
        must_fetch, should_fetch = tree.branch.heads_to_fetch()
 
484
        self.assertFalse(revision.NULL_REVISION in must_fetch)
 
485
        self.assertFalse(revision.NULL_REVISION in should_fetch)
 
486
 
500
487
 
501
488
class TestBranchFormat(per_branch.TestCaseWithBranch):
502
489
 
682
669
            # they may not be initializable.
683
670
            return
684
671
        # supported formats must be able to init and open
685
 
        t = transport.get_transport(self.get_url())
 
672
        t = self.get_transport()
686
673
        readonly_t = transport.get_transport(self.get_readonly_url())
687
674
        made_branch = self.make_branch('.')
688
675
        self.failUnless(isinstance(made_branch, _mod_branch.Branch))
746
733
        except errors.UpgradeRequired:
747
734
            raise tests.TestNotApplicable('Format does not support binding')
748
735
 
 
736
    def test_unbind_clears_cached_master_branch(self):
 
737
        """b.unbind clears any cached value of b.get_master_branch."""
 
738
        master = self.make_branch('master')
 
739
        branch = self.make_branch('branch')
 
740
        try:
 
741
            branch.bind(master)
 
742
        except errors.UpgradeRequired:
 
743
            raise tests.TestNotApplicable('Format does not support binding')
 
744
        self.addCleanup(branch.lock_write().unlock)
 
745
        self.assertNotEqual(None, branch.get_master_branch())
 
746
        branch.unbind()
 
747
        self.assertEqual(None, branch.get_master_branch())
 
748
 
 
749
    def test_unlocked_does_not_cache_master_branch(self):
 
750
        """Unlocked branches do not cache the result of get_master_branch."""
 
751
        master = self.make_branch('master')
 
752
        branch1 = self.make_branch('branch')
 
753
        try:
 
754
            branch1.bind(master)
 
755
        except errors.UpgradeRequired:
 
756
            raise tests.TestNotApplicable('Format does not support binding')
 
757
        # Open branch1 again
 
758
        branch2 = branch1.bzrdir.open_branch()
 
759
        self.assertNotEqual(None, branch1.get_master_branch())
 
760
        # Unbind the branch via branch2.  branch1 isn't locked so will
 
761
        # immediately return the new value for get_master_branch.
 
762
        branch2.unbind()
 
763
        self.assertEqual(None, branch1.get_master_branch())
 
764
 
 
765
    def test_bind_clears_cached_master_branch(self):
 
766
        """b.bind clears any cached value of b.get_master_branch."""
 
767
        master1 = self.make_branch('master1')
 
768
        master2 = self.make_branch('master2')
 
769
        branch = self.make_branch('branch')
 
770
        try:
 
771
            branch.bind(master1)
 
772
        except errors.UpgradeRequired:
 
773
            raise tests.TestNotApplicable('Format does not support binding')
 
774
        self.addCleanup(branch.lock_write().unlock)
 
775
        self.assertNotEqual(None, branch.get_master_branch())
 
776
        branch.bind(master2)
 
777
        self.assertEqual('.', urlutils.relative_url(self.get_url('master2'),
 
778
                branch.get_master_branch().base))
 
779
 
 
780
    def test_set_bound_location_clears_cached_master_branch(self):
 
781
        """b.set_bound_location clears any cached value of b.get_master_branch.
 
782
        """
 
783
        master1 = self.make_branch('master1')
 
784
        master2 = self.make_branch('master2')
 
785
        branch = self.make_branch('branch')
 
786
        try:
 
787
            branch.bind(master1)
 
788
        except errors.UpgradeRequired:
 
789
            raise tests.TestNotApplicable('Format does not support binding')
 
790
        self.addCleanup(branch.lock_write().unlock)
 
791
        self.assertNotEqual(None, branch.get_master_branch())
 
792
        branch.set_bound_location(self.get_url('master2'))
 
793
        self.assertEqual('.', urlutils.relative_url(self.get_url('master2'),
 
794
                branch.get_master_branch().base))
 
795
 
749
796
 
750
797
class TestStrict(per_branch.TestCaseWithBranch):
751
798