~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/bzrdir_implementations/test_bzrdir.py

  • Committer: Martin Pool
  • Date: 2007-04-04 01:22:11 UTC
  • mfrom: (2393.1.1 bzr.docs)
  • mto: This revision was merged to the branch mainline in revision 2397.
  • Revision ID: mbp@sourcefrog.net-20070404012211-sq269me6bai9m6xk
merge trunk and doc fix from elliot

Show diffs side-by-side

added added

removed removed

Lines of Context:
136
136
            raise TestSkipped("cannot make working tree with transport %r"
137
137
                              % a_bzrdir.transport)
138
138
 
139
 
    def sproutOrSkip(self, from_bzrdir, to_url, revision_id=None, basis=None,
 
139
    def sproutOrSkip(self, from_bzrdir, to_url, revision_id=None,
140
140
                     force_new_repo=False):
141
141
        """Sprout from_bzrdir into to_url, or raise TestSkipped.
142
142
        
145
145
        """
146
146
        try:
147
147
            target = from_bzrdir.sprout(to_url, revision_id=revision_id,
148
 
                                        basis=basis,
149
148
                                        force_new_repo=force_new_repo)
150
149
        except errors.NotLocalUrl:
151
150
            raise TestSkipped('Cannot sprout to remote bzrdirs.')
155
154
        dir = self.make_bzrdir('dir1')
156
155
        dir.create_repository()
157
156
        dir.create_branch()
158
 
        wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
 
157
        try:
 
158
            wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
 
159
        except errors.NotLocalUrl:
 
160
            raise TestSkipped("cannot make working tree with transport %r"
 
161
                              % dir.transport)
159
162
        self.assertEqual([], wt.get_parent_ids())
160
163
 
161
164
    def test_destroy_workingtree(self):
312
315
 
313
316
    def test_clone_bzrdir_branch_and_repo(self):
314
317
        tree = self.make_branch_and_tree('commit_tree')
315
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
318
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
316
319
        tree.add('foo')
317
320
        tree.commit('revision 1')
318
321
        source = self.make_branch('source')
319
 
        tree.bzrdir.open_repository().copy_content_into(source.repository)
320
 
        tree.bzrdir.open_branch().copy_content_into(source)
 
322
        tree.branch.repository.copy_content_into(source.repository)
 
323
        tree.branch.copy_content_into(source)
321
324
        dir = source.bzrdir
322
325
        target = dir.clone(self.get_url('target'))
323
326
        self.assertNotEqual(dir.transport.base, target.transport.base)
333
336
    def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
334
337
        # by default cloning into a shared repo uses the shared repo.
335
338
        tree = self.make_branch_and_tree('commit_tree')
336
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
339
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
337
340
        tree.add('foo')
338
341
        tree.commit('revision 1')
339
342
        source = self.make_branch('source')
340
 
        tree.bzrdir.open_repository().copy_content_into(source.repository)
341
 
        tree.bzrdir.open_branch().copy_content_into(source)
 
343
        tree.branch.repository.copy_content_into(source.repository)
 
344
        tree.branch.copy_content_into(source)
342
345
        try:
343
346
            self.make_repository('target', shared=True)
344
347
        except errors.IncompatibleFormat:
353
356
    def test_clone_bzrdir_branch_and_repo_into_shared_repo_force_new_repo(self):
354
357
        # by default cloning into a shared repo uses the shared repo.
355
358
        tree = self.make_branch_and_tree('commit_tree')
356
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
359
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
357
360
        tree.add('foo')
358
361
        tree.commit('revision 1')
359
362
        source = self.make_branch('source')
360
 
        tree.bzrdir.open_repository().copy_content_into(source.repository)
361
 
        tree.bzrdir.open_branch().copy_content_into(source)
 
363
        tree.branch.repository.copy_content_into(source.repository)
 
364
        tree.branch.copy_content_into(source)
362
365
        try:
363
366
            self.make_repository('target', shared=True)
364
367
        except errors.IncompatibleFormat:
398
401
        tree.commit('revision 1', rev_id='1')
399
402
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
400
403
        source = self.make_branch('source')
401
 
        tree.bzrdir.open_repository().copy_content_into(source.repository)
402
 
        tree.bzrdir.open_branch().copy_content_into(source)
 
404
        tree.branch.repository.copy_content_into(source.repository)
 
405
        tree.branch.copy_content_into(source)
403
406
        dir = source.bzrdir
404
407
        target = dir.clone(self.get_url('target'), revision_id='1')
405
408
        self.assertEqual('1', target.open_branch().last_revision())
490
493
        self.skipIfNoWorkingTree(target)
491
494
        self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
492
495
 
493
 
    def test_clone_bzrdir_incomplete_source_with_basis(self):
494
 
        # ensure that basis really does grab from the basis by having incomplete source
495
 
        tree = self.make_branch_and_tree('commit_tree')
496
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
497
 
        tree.add('foo')
498
 
        tree.commit('revision 1', rev_id='1')
499
 
        source = self.make_branch_and_tree('source')
500
 
        # this gives us an incomplete repository
501
 
        tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
502
 
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
503
 
        tree.bzrdir.open_branch().copy_content_into(source.branch)
504
 
        tree.copy_content_into(source)
505
 
        self.assertFalse(source.branch.repository.has_revision('2'))
506
 
        dir = source.bzrdir
507
 
        target = dir.clone(self.get_url('target'), basis=tree.bzrdir)
508
 
        self.assertEqual('2', target.open_branch().last_revision())
509
 
        try:
510
 
            self.assertEqual(['2'], target.open_workingtree().get_parent_ids())
511
 
        except errors.NoWorkingTree:
512
 
            # It should have a working tree if it's able to have one, so if
513
 
            # we're here make sure it really can't have one.
514
 
            self.assertRaises(errors.NotLocalUrl, target.create_workingtree)
515
 
        self.assertTrue(target.open_branch().repository.has_revision('2'))
516
 
 
517
496
    def test_sprout_bzrdir_empty(self):
518
497
        dir = self.make_bzrdir('source')
519
498
        target = self.sproutOrSkip(dir, self.get_url('target'))
874
853
            return
875
854
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
876
855
        tree = self.createWorkingTreeOrSkip(dir)
877
 
        tree.bzrdir.root_transport.mkdir('subdir')
 
856
        self.build_tree(['source/subdir/'])
878
857
        tree.add('subdir')
879
858
        target = self.sproutOrSkip(dir, self.get_url('target'))
880
859
        self.assertNotEqual(dir.transport.base, target.transport.base)
900
879
            return
901
880
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
902
881
        tree = self.createWorkingTreeOrSkip(dir)
903
 
        self.build_tree(['foo'], transport=dir.root_transport)
 
882
        self.build_tree(['source/foo'])
904
883
        tree.add('foo')
905
884
        tree.commit('revision 1', rev_id='1')
906
885
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
923
902
        # This smoke test just checks the revision-id is right. Tree specific
924
903
        # tests will check corner cases.
925
904
        tree = self.make_branch_and_tree('source')
926
 
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
 
905
        self.build_tree(['source/foo'])
927
906
        tree.add('foo')
928
907
        tree.commit('revision 1', rev_id='1')
929
908
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
931
910
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
932
911
        self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
933
912
 
934
 
    def test_sprout_bzrdir_incomplete_source_with_basis(self):
935
 
        # ensure that basis really does grab from the basis by having incomplete source
936
 
        tree = self.make_branch_and_tree('commit_tree')
937
 
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
938
 
        tree.add('foo')
939
 
        tree.commit('revision 1', rev_id='1')
940
 
        source = self.make_branch_and_tree('source')
941
 
        # this gives us an incomplete repository
942
 
        tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
943
 
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
944
 
        tree.bzrdir.open_branch().copy_content_into(source.branch)
945
 
        tree.copy_content_into(source)
946
 
        self.assertFalse(source.branch.repository.has_revision('2'))
947
 
        dir = source.bzrdir
948
 
        target = self.sproutOrSkip(dir, self.get_url('target'),
949
 
                                   basis=tree.bzrdir)
950
 
        self.assertEqual('2', target.open_branch().last_revision())
951
 
        self.assertEqual(['2'], target.open_workingtree().get_parent_ids())
952
 
        self.assertTrue(target.open_branch().repository.has_revision('2'))
953
 
 
954
913
    def test_format_initialize_find_open(self):
955
914
        # loopback test to check the current format initializes to itself.
956
915
        if not self.bzrdir_format.is_supported():
1018
977
        t = get_transport(self.get_url())
1019
978
        made_control = self.bzrdir_format.initialize(t.base)
1020
979
        made_repo = made_control.create_repository()
1021
 
        self.failUnless(isinstance(made_repo, repository.Repository))
 
980
        # Check that we have a repository object.
 
981
        made_repo.has_revision('foo')
1022
982
        self.assertEqual(made_control, made_repo.bzrdir)
1023
983
 
1024
984
    def test_create_repository_shared(self):
1103
1063
            # because the default open will not open them and
1104
1064
            # they may not be initializable.
1105
1065
            return
1106
 
        # this has to be tested with local access as we still support creating 
 
1066
        # this has to be tested with local access as we still support creating
1107
1067
        # format 6 bzrdirs
1108
 
        t = get_transport('.')
1109
 
        made_control = self.bzrdir_format.initialize(t.base)
1110
 
        made_repo = made_control.create_repository()
1111
 
        made_branch = made_control.create_branch()
1112
 
        made_tree = made_control.create_workingtree()
 
1068
        t = self.get_transport()
 
1069
        try:
 
1070
            made_control = self.bzrdir_format.initialize(t.base)
 
1071
            made_repo = made_control.create_repository()
 
1072
            made_branch = made_control.create_branch()
 
1073
            made_tree = made_control.create_workingtree()
 
1074
        except errors.NotLocalUrl:
 
1075
            raise TestSkipped("Can't initialize %r on transport %r"
 
1076
                              % (self.bzrdir_format, t))
1113
1077
        opened_tree = made_control.open_workingtree()
1114
1078
        self.assertEqual(made_control, opened_tree.bzrdir)
1115
1079
        self.failUnless(isinstance(opened_tree, made_tree.__class__))
1456
1420
            # they may not be initializable.
1457
1421
            return
1458
1422
        # supported formats must be able to init and open
1459
 
        url = self.get_url('subdir')
1460
 
        get_transport(self.get_url()).mkdir('subdir')
1461
 
        made_control = self.bzrdir_format.initialize(url)
 
1423
        # - do the vfs initialisation over the basic vfs transport
 
1424
        # XXX: TODO this should become a 'bzrdirlocation' api call.
 
1425
        url = self.get_vfs_only_url('subdir')
 
1426
        get_transport(self.get_vfs_only_url()).mkdir('subdir')
 
1427
        made_control = self.bzrdir_format.initialize(self.get_url('subdir'))
1462
1428
        try:
1463
1429
            repo = made_control.open_repository()
1464
1430
            # if there is a repository, then the format cannot ever hit this 
1466
1432
            return
1467
1433
        except errors.NoRepositoryPresent:
1468
1434
            pass
1469
 
        opened_control = bzrdir.BzrDir.open(self.get_readonly_url('subdir'))
 
1435
        made_control = bzrdir.BzrDir.open(self.get_readonly_url('subdir'))
1470
1436
        self.assertRaises(errors.NoRepositoryPresent,
1471
 
                          opened_control.find_repository)
 
1437
                          made_control.find_repository)
1472
1438