~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge repository so I dont trample on myself.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
                           NotBranchError,
33
33
                           )
34
34
import bzrlib.repository as repository
35
 
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
 
35
from bzrlib.tests import (
 
36
                          ChrootedTestCase,
 
37
                          TestCase,
 
38
                          TestCaseWithTransport,
 
39
                          TestSkipped,
 
40
                          )
36
41
from bzrlib.trace import mutter
37
42
import bzrlib.transactions as transactions
38
43
import bzrlib.transport as transport
105
110
        self.assertNotEqual(dir.transport.base, target.transport.base)
106
111
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
107
112
    
 
113
    def test_clone_bzrdir_empty_force_new_ignored(self):
 
114
        # the force_new_repo parameter should have no effect on an empty
 
115
        # bzrdir's clone logic
 
116
        dir = self.make_bzrdir('source')
 
117
        target = dir.clone(self.get_url('target'), force_new_repo=True)
 
118
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
119
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
 
120
    
108
121
    def test_clone_bzrdir_repository(self):
109
122
        dir = self.make_bzrdir('source')
110
123
        repo = dir.create_repository()
118
131
        self.assertNotEqual(dir.transport.base, target.transport.base)
119
132
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
120
133
 
 
134
    def test_clone_bzrdir_repository_under_shared(self):
 
135
        dir = self.make_bzrdir('source')
 
136
        repo = dir.create_repository()
 
137
        # add some content to differentiate from an empty repository.
 
138
        repo.control_weaves.add_text('inventory',
 
139
                                     "A",
 
140
                                     [],
 
141
                                     [],
 
142
                                     repo.get_transaction())
 
143
        try:
 
144
            self.make_repository('target', shared=True)
 
145
        except errors.IncompatibleFormat:
 
146
            return
 
147
        target = dir.clone(self.get_url('target/child'))
 
148
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
149
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
 
150
        
 
151
    def test_clone_bzrdir_repository_under_shared_force_new_repo(self):
 
152
        dir = self.make_bzrdir('source')
 
153
        repo = dir.create_repository()
 
154
        # add some content to differentiate from an empty repository.
 
155
        repo.control_weaves.add_text('inventory',
 
156
                                     "A",
 
157
                                     [],
 
158
                                     [],
 
159
                                     repo.get_transaction())
 
160
        try:
 
161
            self.make_repository('target', shared=True)
 
162
        except errors.IncompatibleFormat:
 
163
            return
 
164
        target = dir.clone(self.get_url('target/child'), force_new_repo=True)
 
165
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
166
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
 
167
 
121
168
    def test_clone_bzrdir_repository_revision(self):
122
169
        # test for revision limiting, [smoke test, not corner case checks].
123
170
        # make a repository with some revisions,
150
197
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
151
198
                                    ['./.bzr/stat-cache', './.bzr/checkout/stat-cache'])
152
199
 
 
200
    def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
 
201
        # by default cloning into a shared repo uses the shared repo.
 
202
        tree = self.make_branch_and_tree('commit_tree')
 
203
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
204
        tree.add('foo')
 
205
        tree.commit('revision 1')
 
206
        source = self.make_branch('source')
 
207
        tree.bzrdir.open_repository().copy_content_into(source.repository)
 
208
        tree.bzrdir.open_branch().copy_content_into(source)
 
209
        try:
 
210
            self.make_repository('target', shared=True)
 
211
        except errors.IncompatibleFormat:
 
212
            return
 
213
        dir = source.bzrdir
 
214
        target = dir.clone(self.get_url('target/child'))
 
215
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
216
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
 
217
        self.assertEqual(source.revision_history(),
 
218
                         target.open_branch().revision_history())
 
219
 
 
220
    def test_clone_bzrdir_branch_and_repo_into_shared_repo_force_new_repo(self):
 
221
        # by default cloning into a shared repo uses the shared repo.
 
222
        tree = self.make_branch_and_tree('commit_tree')
 
223
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
224
        tree.add('foo')
 
225
        tree.commit('revision 1')
 
226
        source = self.make_branch('source')
 
227
        tree.bzrdir.open_repository().copy_content_into(source.repository)
 
228
        tree.bzrdir.open_branch().copy_content_into(source)
 
229
        try:
 
230
            self.make_repository('target', shared=True)
 
231
        except errors.IncompatibleFormat:
 
232
            return
 
233
        dir = source.bzrdir
 
234
        target = dir.clone(self.get_url('target/child'), force_new_repo=True)
 
235
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
236
        target.open_repository()
 
237
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
 
238
 
153
239
    def test_clone_bzrdir_branch_reference(self):
154
240
        # cloning should preserve the reference status of the branch in a bzrdir
155
241
        referenced_branch = self.make_branch('referencced')
251
337
        target.open_repository()
252
338
        target.open_branch()
253
339
        target.open_workingtree()
 
340
 
 
341
    def test_sprout_bzrdir_empty_under_shared_repo(self):
 
342
        # sprouting an empty dir into a repo uses the repo
 
343
        dir = self.make_bzrdir('source')
 
344
        try:
 
345
            self.make_repository('target', shared=True)
 
346
        except errors.IncompatibleFormat:
 
347
            return
 
348
        target = dir.sprout(self.get_url('target/child'))
 
349
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
 
350
        target.open_branch()
 
351
        target.open_workingtree()
 
352
 
 
353
    def test_sprout_bzrdir_empty_under_shared_repo(self):
 
354
        # the force_new_repo parameter should force use of a new repo in an empty
 
355
        # bzrdir's sprout logic
 
356
        dir = self.make_bzrdir('source')
 
357
        try:
 
358
            self.make_repository('target', shared=True)
 
359
        except errors.IncompatibleFormat:
 
360
            return
 
361
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
 
362
        target.open_repository()
 
363
        target.open_branch()
 
364
        target.open_workingtree()
254
365
    
255
366
    def test_sprout_bzrdir_repository(self):
256
367
        dir = self.make_bzrdir('source')
265
376
        self.assertNotEqual(dir.transport.base, target.transport.base)
266
377
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
267
378
 
 
379
    def test_sprout_bzrdir_repository_under_shared(self):
 
380
        tree = self.make_branch_and_tree('commit_tree')
 
381
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
382
        tree.add('foo')
 
383
        tree.commit('revision 1', rev_id='1')
 
384
        tree.bzrdir.open_branch().set_revision_history([])
 
385
        tree.set_last_revision(None)
 
386
        tree.commit('revision 2', rev_id='2')
 
387
        source = self.make_repository('source')
 
388
        tree.bzrdir.open_repository().copy_content_into(source)
 
389
        dir = source.bzrdir
 
390
        try:
 
391
            shared_repo = self.make_repository('target', shared=True)
 
392
        except errors.IncompatibleFormat:
 
393
            return
 
394
        target = dir.sprout(self.get_url('target/child'))
 
395
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
396
        self.assertTrue(shared_repo.has_revision('1'))
 
397
 
 
398
    def test_sprout_bzrdir_repository_under_shared_force_new_repo(self):
 
399
        tree = self.make_branch_and_tree('commit_tree')
 
400
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
401
        tree.add('foo')
 
402
        tree.commit('revision 1', rev_id='1')
 
403
        tree.bzrdir.open_branch().set_revision_history([])
 
404
        tree.set_last_revision(None)
 
405
        tree.commit('revision 2', rev_id='2')
 
406
        source = self.make_repository('source')
 
407
        tree.bzrdir.open_repository().copy_content_into(source)
 
408
        dir = source.bzrdir
 
409
        try:
 
410
            shared_repo = self.make_repository('target', shared=True)
 
411
        except errors.IncompatibleFormat:
 
412
            return
 
413
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
 
414
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
415
        self.assertFalse(shared_repo.has_revision('1'))
 
416
 
268
417
    def test_sprout_bzrdir_repository_revision(self):
269
418
        # test for revision limiting, [smoke test, not corner case checks].
270
419
        # make a repository with some revisions,
296
445
        self.assertNotEqual(dir.transport.base, target.transport.base)
297
446
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
298
447
 
 
448
    def test_sprout_bzrdir_branch_and_repo_shared(self):
 
449
        # sprouting a branch with a repo into a shared repo uses the shared
 
450
        # repo
 
451
        tree = self.make_branch_and_tree('commit_tree')
 
452
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
453
        tree.add('foo')
 
454
        tree.commit('revision 1', rev_id='1')
 
455
        source = self.make_branch('source')
 
456
        tree.bzrdir.open_repository().copy_content_into(source.repository)
 
457
        tree.bzrdir.open_branch().copy_content_into(source)
 
458
        dir = source.bzrdir
 
459
        try:
 
460
            shared_repo = self.make_repository('target', shared=True)
 
461
        except errors.IncompatibleFormat:
 
462
            return
 
463
        target = dir.sprout(self.get_url('target/child'))
 
464
        self.assertTrue(shared_repo.has_revision('1'))
 
465
 
 
466
    def test_sprout_bzrdir_branch_and_repo_shared_force_new_repo(self):
 
467
        # sprouting a branch with a repo into a shared repo uses the shared
 
468
        # repo
 
469
        tree = self.make_branch_and_tree('commit_tree')
 
470
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
471
        tree.add('foo')
 
472
        tree.commit('revision 1', rev_id='1')
 
473
        source = self.make_branch('source')
 
474
        tree.bzrdir.open_repository().copy_content_into(source.repository)
 
475
        tree.bzrdir.open_branch().copy_content_into(source)
 
476
        dir = source.bzrdir
 
477
        try:
 
478
            shared_repo = self.make_repository('target', shared=True)
 
479
        except errors.IncompatibleFormat:
 
480
            return
 
481
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
 
482
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
483
        self.assertFalse(shared_repo.has_revision('1'))
 
484
 
299
485
    def test_sprout_bzrdir_branch_reference(self):
300
486
        # sprouting should create a repository if needed and a sprouted branch.
301
487
        referenced_branch = self.make_branch('referencced')
315
501
        # place
316
502
        target.open_repository()
317
503
 
 
504
    def test_sprout_bzrdir_branch_reference_shared(self):
 
505
        # sprouting should create a repository if needed and a sprouted branch.
 
506
        referenced_tree = self.make_branch_and_tree('referenced')
 
507
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
 
508
        dir = self.make_bzrdir('source')
 
509
        try:
 
510
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
 
511
                referenced_tree.branch)
 
512
        except errors.IncompatibleFormat:
 
513
            # this is ok too, not all formats have to support references.
 
514
            return
 
515
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
 
516
        try:
 
517
            shared_repo = self.make_repository('target', shared=True)
 
518
        except errors.IncompatibleFormat:
 
519
            return
 
520
        target = dir.sprout(self.get_url('target/child'))
 
521
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
522
        # we want target to have a branch that is in-place.
 
523
        self.assertEqual(target, target.open_branch().bzrdir)
 
524
        # and we want no repository as the target is shared
 
525
        self.assertRaises(errors.NoRepositoryPresent, 
 
526
                          target.open_repository)
 
527
        # and we want revision '1' in the shared repo
 
528
        self.assertTrue(shared_repo.has_revision('1'))
 
529
 
 
530
    def test_sprout_bzrdir_branch_reference_shared_force_new_repo(self):
 
531
        # sprouting should create a repository if needed and a sprouted branch.
 
532
        referenced_tree = self.make_branch_and_tree('referenced')
 
533
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
 
534
        dir = self.make_bzrdir('source')
 
535
        try:
 
536
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
 
537
                referenced_tree.branch)
 
538
        except errors.IncompatibleFormat:
 
539
            # this is ok too, not all formats have to support references.
 
540
            return
 
541
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
 
542
        try:
 
543
            shared_repo = self.make_repository('target', shared=True)
 
544
        except errors.IncompatibleFormat:
 
545
            return
 
546
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
 
547
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
548
        # we want target to have a branch that is in-place.
 
549
        self.assertEqual(target, target.open_branch().bzrdir)
 
550
        # and we want revision '1' in the new repo
 
551
        self.assertTrue(target.open_repository().has_revision('1'))
 
552
        # but not the shared one
 
553
        self.assertFalse(shared_repo.has_revision('1'))
 
554
 
318
555
    def test_sprout_bzrdir_branch_revision(self):
319
556
        # test for revision limiting, [smoke test, not corner case checks].
320
557
        # make a repository with some revisions,
458
695
                          get_transport(self.get_readonly_url()))
459
696
 
460
697
    def test_create_branch(self):
461
 
        # a bzrdir can construct a repository for itself.
 
698
        # a bzrdir can construct a branch and repository for itself.
462
699
        if not self.bzrdir_format.is_supported():
463
700
            # unsupported formats are not loopback testable
464
701
            # because the default open will not open them and
628
865
        self.assertEqual(dir.root_transport.base,
629
866
                         get_transport(self.get_url('.')).base)
630
867
 
 
868
    def test_find_repository_no_repo_under_standalone_branch(self):
 
869
        # finding a repo stops at standalone branches even if there is a
 
870
        # higher repository available.
 
871
        try:
 
872
            repo = self.make_repository('.', shared=True)
 
873
        except errors.IncompatibleFormat:
 
874
            # need a shared repository to test this.
 
875
            return
 
876
        url = self.get_url('intermediate')
 
877
        get_transport(self.get_url()).mkdir('intermediate')
 
878
        get_transport(self.get_url()).mkdir('intermediate/child')
 
879
        made_control = self.bzrdir_format.initialize(url)
 
880
        made_control.create_repository()
 
881
        innermost_control = self.bzrdir_format.initialize(
 
882
            self.get_url('intermediate/child'))
 
883
        try:
 
884
            child_repo = innermost_control.open_repository()
 
885
            # if there is a repository, then the format cannot ever hit this 
 
886
            # code path.
 
887
            return
 
888
        except errors.NoRepositoryPresent:
 
889
            pass
 
890
        self.assertRaises(errors.NoRepositoryPresent,
 
891
                          innermost_control.find_repository)
 
892
 
 
893
    def test_find_repository_containing_shared_repository(self):
 
894
        # find repo inside a shared repo with an empty control dir
 
895
        # returns the shared repo.
 
896
        try:
 
897
            repo = self.make_repository('.', shared=True)
 
898
        except errors.IncompatibleFormat:
 
899
            # need a shared repository to test this.
 
900
            return
 
901
        url = self.get_url('childbzrdir')
 
902
        get_transport(self.get_url()).mkdir('childbzrdir')
 
903
        made_control = self.bzrdir_format.initialize(url)
 
904
        try:
 
905
            child_repo = made_control.open_repository()
 
906
            # if there is a repository, then the format cannot ever hit this 
 
907
            # code path.
 
908
            return
 
909
        except errors.NoRepositoryPresent:
 
910
            pass
 
911
        found_repo = made_control.find_repository()
 
912
        self.assertEqual(repo.bzrdir.root_transport.base,
 
913
                         found_repo.bzrdir.root_transport.base)
 
914
        
 
915
    def test_find_repository_standalone_with_containing_shared_repository(self):
 
916
        # find repo inside a standalone repo inside a shared repo finds the standalone repo
 
917
        try:
 
918
            containing_repo = self.make_repository('.', shared=True)
 
919
        except errors.IncompatibleFormat:
 
920
            # need a shared repository to test this.
 
921
            return
 
922
        child_repo = self.make_repository('childrepo')
 
923
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
 
924
        found_repo = opened_control.find_repository()
 
925
        self.assertEqual(child_repo.bzrdir.root_transport.base,
 
926
                         found_repo.bzrdir.root_transport.base)
 
927
 
 
928
    def test_find_repository_shared_within_shared_repository(self):
 
929
        # find repo at a shared repo inside a shared repo finds the inner repo
 
930
        try:
 
931
            containing_repo = self.make_repository('.', shared=True)
 
932
        except errors.IncompatibleFormat:
 
933
            # need a shared repository to test this.
 
934
            return
 
935
        url = self.get_url('childrepo')
 
936
        get_transport(self.get_url()).mkdir('childrepo')
 
937
        child_control = self.bzrdir_format.initialize(url)
 
938
        child_repo = child_control.create_repository(shared=True)
 
939
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
 
940
        found_repo = opened_control.find_repository()
 
941
        self.assertEqual(child_repo.bzrdir.root_transport.base,
 
942
                         found_repo.bzrdir.root_transport.base)
 
943
        self.assertNotEqual(child_repo.bzrdir.root_transport.base,
 
944
                            containing_repo.bzrdir.root_transport.base)
 
945
 
 
946
    def test_find_repository_with_nested_dirs_works(self):
 
947
        # find repo inside a bzrdir inside a bzrdir inside a shared repo 
 
948
        # finds the outer shared repo.
 
949
        try:
 
950
            repo = self.make_repository('.', shared=True)
 
951
        except errors.IncompatibleFormat:
 
952
            # need a shared repository to test this.
 
953
            return
 
954
        url = self.get_url('intermediate')
 
955
        get_transport(self.get_url()).mkdir('intermediate')
 
956
        get_transport(self.get_url()).mkdir('intermediate/child')
 
957
        made_control = self.bzrdir_format.initialize(url)
 
958
        try:
 
959
            child_repo = made_control.open_repository()
 
960
            # if there is a repository, then the format cannot ever hit this 
 
961
            # code path.
 
962
            return
 
963
        except errors.NoRepositoryPresent:
 
964
            pass
 
965
        innermost_control = self.bzrdir_format.initialize(
 
966
            self.get_url('intermediate/child'))
 
967
        try:
 
968
            child_repo = innermost_control.open_repository()
 
969
            # if there is a repository, then the format cannot ever hit this 
 
970
            # code path.
 
971
            return
 
972
        except errors.NoRepositoryPresent:
 
973
            pass
 
974
        found_repo = innermost_control.find_repository()
 
975
        self.assertEqual(repo.bzrdir.root_transport.base,
 
976
                         found_repo.bzrdir.root_transport.base)
 
977
        
 
978
 
 
979
 
 
980
class ChrootedBzrDirTests(ChrootedTestCase):
 
981
 
 
982
    def test_find_repository_no_repository(self):
 
983
        # loopback test to check the current format fails to find a 
 
984
        # share repository correctly.
 
985
        if not self.bzrdir_format.is_supported():
 
986
            # unsupported formats are not loopback testable
 
987
            # because the default open will not open them and
 
988
            # they may not be initializable.
 
989
            return
 
990
        # supported formats must be able to init and open
 
991
        url = self.get_url('subdir')
 
992
        get_transport(self.get_url()).mkdir('subdir')
 
993
        made_control = self.bzrdir_format.initialize(url)
 
994
        try:
 
995
            repo = made_control.open_repository()
 
996
            # if there is a repository, then the format cannot ever hit this 
 
997
            # code path.
 
998
            return
 
999
        except errors.NoRepositoryPresent:
 
1000
            pass
 
1001
        opened_control = bzrdir.BzrDir.open(self.get_readonly_url('subdir'))
 
1002
        self.assertRaises(errors.NoRepositoryPresent,
 
1003
                          opened_control.find_repository)
 
1004