~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2010-01-12 03:53:21 UTC
  • mfrom: (4948 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4964.
  • Revision ID: andrew.bennetts@canonical.com-20100112035321-hofpz5p10224ryj3
Merge lp:bzr, resolving conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for branch implementations - tests a branch format."""
18
18
 
24
24
    bzrdir,
25
25
    errors,
26
26
    gpg,
 
27
    merge,
27
28
    urlutils,
28
29
    transactions,
29
30
    remote,
42
43
import bzrlib.revision
43
44
from bzrlib.symbol_versioning import deprecated_in
44
45
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
45
 
from bzrlib.tests.branch_implementations import TestCaseWithBranch
46
46
from bzrlib.tests.http_server import HttpServer
 
47
from bzrlib.tests.per_branch import TestCaseWithBranch
47
48
from bzrlib.trace import mutter
48
49
from bzrlib.transport import get_transport
49
50
from bzrlib.transport.memory import MemoryServer
58
59
        self.assertIs(self.branch_format.__class__,
59
60
                      bzrdir_branch_format.__class__)
60
61
 
 
62
    def test_make_branch_gets_expected_format(self):
 
63
        branch = self.make_branch('.')
 
64
        self.assertIs(self.branch_format.__class__,
 
65
            branch._format.__class__)
 
66
 
61
67
 
62
68
class TestBranch(TestCaseWithBranch):
63
69
 
104
110
        wt.commit('lala!', rev_id='revision-1', allow_pointless=False)
105
111
 
106
112
        b2 = self.make_branch('b2')
107
 
        self.assertEqual((1, []), b2.fetch(b1))
 
113
        b2.fetch(b1)
108
114
 
109
115
        rev = b2.repository.get_revision('revision-1')
110
116
        tree = b2.repository.revision_tree('revision-1')
207
213
        self.assertEqual(branch.get_submit_branch(), 'sftp://example.com')
208
214
        branch.set_submit_branch('sftp://example.net')
209
215
        self.assertEqual(branch.get_submit_branch(), 'sftp://example.net')
210
 
        
 
216
 
211
217
    def test_public_branch(self):
212
218
        """public location can be queried and set"""
213
219
        branch = self.make_branch('branch')
253
259
                          None)
254
260
 
255
261
# TODO 20051003 RBC:
256
 
# compare the gpg-to-sign info for a commit with a ghost and 
 
262
# compare the gpg-to-sign info for a commit with a ghost and
257
263
#     an identical tree without a ghost
258
264
# fetch missing should rewrite the TOC of weaves to list newly available parents.
259
 
        
 
265
 
260
266
    def test_sign_existing_revision(self):
261
267
        wt = self.make_branch_and_tree('.')
262
268
        branch = wt.branch
347
353
 
348
354
    def test_nicks(self):
349
355
        """Test explicit and implicit branch nicknames.
350
 
        
 
356
 
351
357
        Nicknames are implicitly the name of the branch's directory, unless an
352
358
        explicit nickname is set.  That is, an explicit nickname always
353
359
        overrides the implicit one.
488
494
        self.assertEquals(br.revision_history(), [])
489
495
 
490
496
 
 
497
class TestBranchFormat(TestCaseWithBranch):
 
498
 
 
499
    def test_branch_format_network_name(self):
 
500
        br = self.make_branch('.')
 
501
        format = br._format
 
502
        network_name = format.network_name()
 
503
        self.assertIsInstance(network_name, str)
 
504
        # We want to test that the network_name matches the actual format on
 
505
        # disk. For local branches that means that using network_name as a key
 
506
        # in the registry gives back the same format. For remote branches we
 
507
        # check that the network_name of the RemoteBranchFormat we have locally
 
508
        # matches the actual format present on disk.
 
509
        if isinstance(format, remote.RemoteBranchFormat):
 
510
            br._ensure_real()
 
511
            real_branch = br._real_branch
 
512
            self.assertEqual(real_branch._format.network_name(), network_name)
 
513
        else:
 
514
            registry = branch.network_format_registry
 
515
            looked_up_format = registry.get(network_name)
 
516
            self.assertEqual(format.__class__, looked_up_format.__class__)
 
517
 
 
518
 
491
519
class ChrootedTests(TestCaseWithBranch):
492
520
    """A support class that provides readonly urls outside the local namespace.
493
521
 
597
625
        self.assertEqual('foo', branch.get_push_location())
598
626
 
599
627
 
 
628
class TestChildSubmitFormats(TestCaseWithBranch):
 
629
 
 
630
    def test_get_child_submit_format_default(self):
 
631
        self.assertEqual(None, self.get_branch().get_child_submit_format())
 
632
 
 
633
    def test_get_child_submit_format(self):
 
634
        branch = self.get_branch()
 
635
        branch.get_config().set_user_option('child_submit_format', '10')
 
636
        branch = self.get_branch()
 
637
        self.assertEqual('10', branch.get_child_submit_format())
 
638
 
 
639
 
600
640
class TestFormat(TestCaseWithBranch):
601
641
    """Tests for the format itself."""
602
642
 
725
765
        tree3.merge_from_branch(tree2.branch)
726
766
        tree3.commit('empty commit 6')
727
767
        tree2.pull(tree3.branch)
 
768
 
 
769
 
 
770
class TestIgnoreFallbacksParameter(TestCaseWithBranch):
 
771
 
 
772
    def make_branch_with_fallback(self):
 
773
        fallback = self.make_branch('fallback')
 
774
        if not fallback._format.supports_stacking():
 
775
            raise tests.TestNotApplicable("format does not support stacking")
 
776
        stacked = self.make_branch('stacked')
 
777
        stacked.set_stacked_on_url(fallback.base)
 
778
        return stacked
 
779
 
 
780
    def test_fallbacks_not_opened(self):
 
781
        stacked = self.make_branch_with_fallback()
 
782
        self.get_transport('').rename('fallback', 'moved')
 
783
        reopened = stacked.bzrdir.open_branch(ignore_fallbacks=True)
 
784
        self.assertEqual([], reopened.repository._fallback_repositories)
 
785
 
 
786
    def test_fallbacks_are_opened(self):
 
787
        stacked = self.make_branch_with_fallback()
 
788
        reopened = stacked.bzrdir.open_branch(ignore_fallbacks=False)
 
789
        self.assertLength(1, reopened.repository._fallback_repositories)
 
790
 
 
791
 
 
792
class TestReferenceLocation(TestCaseWithBranch):
 
793
 
 
794
    def test_reference_parent(self):
 
795
        tree = self.make_branch_and_tree('tree')
 
796
        subtree = self.make_branch_and_tree('tree/subtree')
 
797
        subtree.set_root_id('subtree-id')
 
798
        try:
 
799
            tree.add_reference(subtree)
 
800
        except bzrlib.errors.UnsupportedOperation:
 
801
            raise tests.TestNotApplicable('Tree cannot hold references.')
 
802
        reference_parent = tree.branch.reference_parent('subtree-id',
 
803
                                                        'subtree')
 
804
        self.assertEqual(subtree.branch.base, reference_parent.base)
 
805
 
 
806
    def test_reference_parent_accepts_possible_transports(self):
 
807
        tree = self.make_branch_and_tree('tree')
 
808
        subtree = self.make_branch_and_tree('tree/subtree')
 
809
        subtree.set_root_id('subtree-id')
 
810
        try:
 
811
            tree.add_reference(subtree)
 
812
        except bzrlib.errors.UnsupportedOperation:
 
813
            raise tests.TestNotApplicable('Tree cannot hold references.')
 
814
        reference_parent = tree.branch.reference_parent('subtree-id',
 
815
            'subtree', possible_transports=[subtree.bzrdir.root_transport])
 
816
 
 
817
    def test_get_reference_info(self):
 
818
        branch = self.make_branch('branch')
 
819
        try:
 
820
            path, loc = branch.get_reference_info('file-id')
 
821
        except bzrlib.errors.UnsupportedOperation:
 
822
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
823
        self.assertIs(None, path)
 
824
        self.assertIs(None, loc)
 
825
 
 
826
    def test_set_reference_info(self):
 
827
        branch = self.make_branch('branch')
 
828
        try:
 
829
            branch.set_reference_info('file-id', 'path/to/location',
 
830
                                      'path/to/file')
 
831
        except bzrlib.errors.UnsupportedOperation:
 
832
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
833
 
 
834
    def test_set_get_reference_info(self):
 
835
        branch = self.make_branch('branch')
 
836
        try:
 
837
            branch.set_reference_info('file-id', 'path/to/file',
 
838
                                      'path/to/location')
 
839
        except bzrlib.errors.UnsupportedOperation:
 
840
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
841
        # Create a new instance to ensure storage is permanent
 
842
        branch = Branch.open('branch')
 
843
        tree_path, branch_location = branch.get_reference_info('file-id')
 
844
        self.assertEqual('path/to/location', branch_location)
 
845
 
 
846
    def test_set_null_reference_info(self):
 
847
        branch = self.make_branch('branch')
 
848
        try:
 
849
            branch.set_reference_info('file-id', 'path/to/file',
 
850
                                      'path/to/location')
 
851
        except bzrlib.errors.UnsupportedOperation:
 
852
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
853
        branch.set_reference_info('file-id', None, None)
 
854
        tree_path, branch_location = branch.get_reference_info('file-id')
 
855
        self.assertIs(None, tree_path)
 
856
        self.assertIs(None, branch_location)
 
857
 
 
858
    def test_set_null_reference_info_when_null(self):
 
859
        branch = self.make_branch('branch')
 
860
        try:
 
861
            tree_path, branch_location = branch.get_reference_info('file-id')
 
862
        except bzrlib.errors.UnsupportedOperation:
 
863
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
864
        self.assertIs(None, tree_path)
 
865
        self.assertIs(None, branch_location)
 
866
        branch.set_reference_info('file-id', None, None)
 
867
 
 
868
    def test_set_null_requires_two_nones(self):
 
869
        branch = self.make_branch('branch')
 
870
        try:
 
871
            e = self.assertRaises(ValueError, branch.set_reference_info,
 
872
                                  'file-id', 'path', None)
 
873
        except bzrlib.errors.UnsupportedOperation:
 
874
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
875
        self.assertEqual('tree_path must be None when branch_location is'
 
876
                         ' None.', str(e))
 
877
        e = self.assertRaises(ValueError, branch.set_reference_info,
 
878
                              'file-id', None, 'location')
 
879
        self.assertEqual('branch_location must be None when tree_path is'
 
880
                         ' None.', str(e))
 
881
 
 
882
    def make_branch_with_reference(self, location, reference_location,
 
883
                                   file_id='file-id'):
 
884
        branch = self.make_branch(location)
 
885
        try:
 
886
            branch.set_reference_info(file_id, 'path/to/file',
 
887
                                      reference_location)
 
888
        except bzrlib.errors.UnsupportedOperation:
 
889
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
890
        return branch
 
891
 
 
892
    def test_reference_parent_from_reference_info_(self):
 
893
        referenced_branch = self.make_branch('reference_branch')
 
894
        branch = self.make_branch_with_reference('branch',
 
895
                                                 referenced_branch.base)
 
896
        parent = branch.reference_parent('file-id', 'path/to/file')
 
897
        self.assertEqual(parent.base, referenced_branch.base)
 
898
 
 
899
    def test_branch_relative_reference_location(self):
 
900
        branch = self.make_branch('branch')
 
901
        try:
 
902
            branch.set_reference_info('file-id', 'path/to/file',
 
903
            '../reference_branch')
 
904
        except bzrlib.errors.UnsupportedOperation:
 
905
            raise tests.TestNotApplicable('Branch cannot hold references.')
 
906
        referenced_branch = self.make_branch('reference_branch')
 
907
        parent = branch.reference_parent('file-id', 'path/to/file')
 
908
        self.assertEqual(parent.base, referenced_branch.base)
 
909
 
 
910
    def test_sprout_copies_reference_location(self):
 
911
        branch = self.make_branch_with_reference('branch', '../reference')
 
912
        new_branch = branch.bzrdir.sprout('new-branch').open_branch()
 
913
        self.assertEqual('../reference',
 
914
                         new_branch.get_reference_info('file-id')[1])
 
915
 
 
916
    def test_clone_copies_reference_location(self):
 
917
        branch = self.make_branch_with_reference('branch', '../reference')
 
918
        new_branch = branch.bzrdir.clone('new-branch').open_branch()
 
919
        self.assertEqual('../reference',
 
920
                         new_branch.get_reference_info('file-id')[1])
 
921
 
 
922
    def test_copied_locations_are_rebased(self):
 
923
        branch = self.make_branch_with_reference('branch', 'reference')
 
924
        new_branch = branch.bzrdir.sprout('branch/new-branch').open_branch()
 
925
        self.assertEqual('../reference',
 
926
                         new_branch.get_reference_info('file-id')[1])
 
927
 
 
928
    def test_update_references_retains_old_references(self):
 
929
        branch = self.make_branch_with_reference('branch', 'reference')
 
930
        new_branch = self.make_branch_with_reference(
 
931
            'new_branch', 'reference', 'file-id2')
 
932
        new_branch.update_references(branch)
 
933
        self.assertEqual('reference',
 
934
                         branch.get_reference_info('file-id')[1])
 
935
 
 
936
    def test_update_references_retains_known_references(self):
 
937
        branch = self.make_branch_with_reference('branch', 'reference')
 
938
        new_branch = self.make_branch_with_reference(
 
939
            'new_branch', 'reference2')
 
940
        new_branch.update_references(branch)
 
941
        self.assertEqual('reference',
 
942
                         branch.get_reference_info('file-id')[1])
 
943
 
 
944
    def test_update_references_skips_known_references(self):
 
945
        branch = self.make_branch_with_reference('branch', 'reference')
 
946
        new_branch = branch.bzrdir.sprout('branch/new-branch').open_branch()
 
947
        new_branch.set_reference_info('file-id', '../foo', '../foo')
 
948
        new_branch.update_references(branch)
 
949
        self.assertEqual('reference',
 
950
                         branch.get_reference_info('file-id')[1])
 
951
 
 
952
    def test_pull_updates_references(self):
 
953
        branch = self.make_branch_with_reference('branch', 'reference')
 
954
        new_branch = branch.bzrdir.sprout('branch/new-branch').open_branch()
 
955
        new_branch.set_reference_info('file-id2', '../foo', '../foo')
 
956
        branch.pull(new_branch)
 
957
        self.assertEqual('foo',
 
958
                         branch.get_reference_info('file-id2')[1])
 
959
 
 
960
    def test_push_updates_references(self):
 
961
        branch = self.make_branch_with_reference('branch', 'reference')
 
962
        new_branch = branch.bzrdir.sprout('branch/new-branch').open_branch()
 
963
        new_branch.set_reference_info('file-id2', '../foo', '../foo')
 
964
        new_branch.push(branch)
 
965
        self.assertEqual('foo',
 
966
                         branch.get_reference_info('file-id2')[1])
 
967
 
 
968
    def test_merge_updates_references(self):
 
969
        branch = self.make_branch_with_reference('branch', 'reference')
 
970
        tree = self.make_branch_and_tree('tree')
 
971
        tree.commit('foo')
 
972
        branch.pull(tree.branch)
 
973
        checkout = branch.create_checkout('checkout', lightweight=True)
 
974
        checkout.commit('bar')
 
975
        tree.lock_write()
 
976
        self.addCleanup(tree.unlock)
 
977
        merger = merge.Merger.from_revision_ids(None, tree,
 
978
                                                branch.last_revision(),
 
979
                                                other_branch=branch)
 
980
        merger.merge_type = merge.Merge3Merger
 
981
        merger.do_merge()
 
982
        self.assertEqual('../branch/reference',
 
983
                         tree.branch.get_reference_info('file-id')[1])