~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
from bzrlib.trace import mutter
52
52
from bzrlib.transport import get_transport
53
53
from bzrlib.upgrade import upgrade
 
54
from bzrlib.remote import RemoteBzrDir
54
55
from bzrlib.repofmt import weaverepo
55
56
 
56
57
 
231
232
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
232
233
 
233
234
    def test_clone_bzrdir_repository_branch_both_under_shared(self):
 
235
        # Create a shared repository
234
236
        try:
235
237
            shared_repo = self.make_repository('shared', shared=True)
236
238
        except errors.IncompatibleFormat:
237
239
            return
 
240
        # Make a branch, 'commit_tree', and working tree outside of the shared
 
241
        # repository, and commit some revisions to it.
238
242
        tree = self.make_branch_and_tree('commit_tree')
239
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
243
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
240
244
        tree.add('foo')
241
245
        tree.commit('revision 1', rev_id='1')
242
246
        tree.bzrdir.open_branch().set_revision_history([])
243
247
        tree.set_parent_trees([])
244
248
        tree.commit('revision 2', rev_id='2')
245
 
        tree.bzrdir.open_repository().copy_content_into(shared_repo)
 
249
        # Copy the content (i.e. revisions) from the 'commit_tree' branch's
 
250
        # repository into the shared repository.
 
251
        tree.branch.repository.copy_content_into(shared_repo)
 
252
        # Make a branch 'source' inside the shared repository.
246
253
        dir = self.make_bzrdir('shared/source')
247
254
        dir.create_branch()
 
255
        # Clone 'source' to 'target', also inside the shared repository.
248
256
        target = dir.clone(self.get_url('shared/target'))
 
257
        # 'source', 'target', and the shared repo all have distinct bzrdirs.
249
258
        self.assertNotEqual(dir.transport.base, target.transport.base)
250
259
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
 
260
        # The shared repository will contain revisions from the 'commit_tree'
 
261
        # repository, even revisions that are not part of the history of the
 
262
        # 'commit_tree' branch.
251
263
        self.assertTrue(shared_repo.has_revision('1'))
252
264
 
253
265
    def test_clone_bzrdir_repository_branch_only_source_under_shared(self):
256
268
        except errors.IncompatibleFormat:
257
269
            return
258
270
        tree = self.make_branch_and_tree('commit_tree')
259
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
271
        self.build_tree(['commit_tree/foo'])
260
272
        tree.add('foo')
261
273
        tree.commit('revision 1', rev_id='1')
262
 
        tree.bzrdir.open_branch().set_revision_history([])
 
274
        tree.branch.bzrdir.open_branch().set_revision_history([])
263
275
        tree.set_parent_trees([])
264
276
        tree.commit('revision 2', rev_id='2')
265
 
        tree.bzrdir.open_repository().copy_content_into(shared_repo)
266
 
        shared_repo.set_make_working_trees(False)
267
 
        self.assertFalse(shared_repo.make_working_trees())
 
277
        tree.branch.repository.copy_content_into(shared_repo)
 
278
        if shared_repo.make_working_trees():
 
279
            shared_repo.set_make_working_trees(False)
 
280
            self.assertFalse(shared_repo.make_working_trees())
268
281
        self.assertTrue(shared_repo.has_revision('1'))
269
282
        dir = self.make_bzrdir('shared/source')
270
283
        dir.create_branch()
278
291
        
279
292
    def test_clone_bzrdir_repository_under_shared_force_new_repo(self):
280
293
        tree = self.make_branch_and_tree('commit_tree')
281
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
294
        self.build_tree(['commit_tree/foo'])
282
295
        tree.add('foo')
283
296
        tree.commit('revision 1', rev_id='1')
284
297
        dir = self.make_bzrdir('source')
301
314
        # and clone it with a revision limit.
302
315
        # 
303
316
        tree = self.make_branch_and_tree('commit_tree')
304
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
317
        self.build_tree(['commit_tree/foo'])
305
318
        tree.add('foo')
306
319
        tree.commit('revision 1', rev_id='1')
307
 
        tree.bzrdir.open_branch().set_revision_history([])
 
320
        tree.branch.bzrdir.open_branch().set_revision_history([])
308
321
        tree.set_parent_trees([])
309
322
        tree.commit('revision 2', rev_id='2')
310
323
        source = self.make_repository('source')
311
 
        tree.bzrdir.open_repository().copy_content_into(source)
 
324
        tree.branch.repository.copy_content_into(source)
312
325
        dir = source.bzrdir
313
326
        target = dir.clone(self.get_url('target'), revision_id='2')
314
327
        raise TestSkipped('revision limiting not strict yet')
315
328
 
316
329
    def test_clone_bzrdir_branch_and_repo(self):
317
330
        tree = self.make_branch_and_tree('commit_tree')
318
 
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
 
331
        self.build_tree(['commit_tree/foo'])
319
332
        tree.add('foo')
320
333
        tree.commit('revision 1')
321
334
        source = self.make_branch('source')
336
349
    def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
337
350
        # by default cloning into a shared repo uses the shared repo.
338
351
        tree = self.make_branch_and_tree('commit_tree')
339
 
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
 
352
        self.build_tree(['commit_tree/foo'])
340
353
        tree.add('foo')
341
354
        tree.commit('revision 1')
342
355
        source = self.make_branch('source')
356
369
    def test_clone_bzrdir_branch_and_repo_into_shared_repo_force_new_repo(self):
357
370
        # by default cloning into a shared repo uses the shared repo.
358
371
        tree = self.make_branch_and_tree('commit_tree')
359
 
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
 
372
        self.build_tree(['commit_tree/foo'])
360
373
        tree.add('foo')
361
374
        tree.commit('revision 1')
362
375
        source = self.make_branch('source')
396
409
        # and clone it with a revision limit.
397
410
        # 
398
411
        tree = self.make_branch_and_tree('commit_tree')
399
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
412
        self.build_tree(['commit_tree/foo'])
400
413
        tree.add('foo')
401
414
        tree.commit('revision 1', rev_id='1')
402
415
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
408
421
        self.assertEqual('1', target.open_branch().last_revision())
409
422
        
410
423
    def test_clone_bzrdir_tree_branch_repo(self):
411
 
        tree = self.make_branch_and_tree('sourcce')
412
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
424
        tree = self.make_branch_and_tree('source')
 
425
        self.build_tree(['source/foo'])
413
426
        tree.add('foo')
414
427
        tree.commit('revision 1')
415
428
        dir = tree.bzrdir
428
441
        target.open_workingtree().revert([])
429
442
 
430
443
    def test_revert_inventory(self):
431
 
        tree = self.make_branch_and_tree('sourcce')
432
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
444
        tree = self.make_branch_and_tree('source')
 
445
        self.build_tree(['source/foo'])
433
446
        tree.add('foo')
434
447
        tree.commit('revision 1')
435
448
        dir = tree.bzrdir
484
497
        # This smoke test just checks the revision-id is right. Tree specific
485
498
        # tests will check corner cases.
486
499
        tree = self.make_branch_and_tree('source')
487
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
500
        self.build_tree(['source/foo'])
488
501
        tree.add('foo')
489
502
        tree.commit('revision 1', rev_id='1')
490
503
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
493
506
        self.skipIfNoWorkingTree(target)
494
507
        self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
495
508
 
 
509
    def test_get_branch_reference_on_reference(self):
 
510
        """get_branch_reference should return the right url."""
 
511
        referenced_branch = self.make_branch('referenced')
 
512
        dir = self.make_bzrdir('source')
 
513
        try:
 
514
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
 
515
                referenced_branch)
 
516
        except errors.IncompatibleFormat:
 
517
            # this is ok too, not all formats have to support references.
 
518
            return
 
519
        self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
 
520
            dir.get_branch_reference())
 
521
 
 
522
    def test_get_branch_reference_on_non_reference(self):
 
523
        """get_branch_reference should return None for non-reference branches."""
 
524
        branch = self.make_branch('referenced')
 
525
        self.assertEqual(None, branch.bzrdir.get_branch_reference())
 
526
 
 
527
    def test_get_branch_reference_no_branch(self):
 
528
        """get_branch_reference should not mask NotBranchErrors."""
 
529
        dir = self.make_bzrdir('source')
 
530
        if dir.has_branch():
 
531
            # this format does not support branchless bzrdirs.
 
532
            return
 
533
        self.assertRaises(errors.NotBranchError, dir.get_branch_reference)
 
534
 
496
535
    def test_sprout_bzrdir_empty(self):
497
536
        dir = self.make_bzrdir('source')
498
537
        target = self.sproutOrSkip(dir, self.get_url('target'))
512
551
        target = self.sproutOrSkip(dir, self.get_url('target/child'))
513
552
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
514
553
        target.open_branch()
515
 
        target.open_workingtree()
 
554
        try:
 
555
            target.open_workingtree()
 
556
        except errors.NotLocalUrl:
 
557
            # bzrdir's that test against non-local urls are allowed to pass:
 
558
            # whitelist them for now
 
559
            self.assertIsInstance(target, RemoteBzrDir)
516
560
 
517
561
    def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
518
562
        # the force_new_repo parameter should force use of a new repo in an empty
566
610
 
567
611
    def test_sprout_bzrdir_with_repository_to_shared(self):
568
612
        tree = self.make_branch_and_tree('commit_tree')
569
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
613
        self.build_tree(['commit_tree/foo'])
570
614
        tree.add('foo')
571
615
        tree.commit('revision 1', rev_id='1')
572
616
        tree.bzrdir.open_branch().set_revision_history([])
573
617
        tree.set_parent_trees([])
574
618
        tree.commit('revision 2', rev_id='2')
575
619
        source = self.make_repository('source')
576
 
        tree.bzrdir.open_repository().copy_content_into(source)
 
620
        tree.branch.repository.copy_content_into(source)
577
621
        dir = source.bzrdir
578
622
        try:
579
623
            shared_repo = self.make_repository('target', shared=True)
589
633
        except errors.IncompatibleFormat:
590
634
            return
591
635
        tree = self.make_branch_and_tree('commit_tree')
592
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
636
        self.build_tree(['commit_tree/foo'])
593
637
        tree.add('foo')
594
638
        tree.commit('revision 1', rev_id='1')
595
639
        tree.bzrdir.open_branch().set_revision_history([])
596
640
        tree.set_parent_trees([])
597
641
        tree.commit('revision 2', rev_id='2')
598
 
        tree.bzrdir.open_repository().copy_content_into(shared_repo)
 
642
        tree.branch.repository.copy_content_into(shared_repo)
599
643
        dir = self.make_bzrdir('shared/source')
600
644
        dir.create_branch()
601
645
        target = self.sproutOrSkip(dir, self.get_url('shared/target'))
609
653
        except errors.IncompatibleFormat:
610
654
            return
611
655
        tree = self.make_branch_and_tree('commit_tree')
612
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
656
        self.build_tree(['commit_tree/foo'])
613
657
        tree.add('foo')
614
658
        tree.commit('revision 1', rev_id='1')
615
659
        tree.bzrdir.open_branch().set_revision_history([])
616
660
        tree.set_parent_trees([])
617
661
        tree.commit('revision 2', rev_id='2')
618
 
        tree.bzrdir.open_repository().copy_content_into(shared_repo)
619
 
        shared_repo.set_make_working_trees(False)
620
 
        self.assertFalse(shared_repo.make_working_trees())
 
662
        tree.branch.repository.copy_content_into(shared_repo)
 
663
        if shared_repo.make_working_trees():
 
664
            shared_repo.set_make_working_trees(False)
 
665
            self.assertFalse(shared_repo.make_working_trees())
621
666
        self.assertTrue(shared_repo.has_revision('1'))
622
667
        dir = self.make_bzrdir('shared/source')
623
668
        dir.create_branch()
626
671
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
627
672
        branch = target.open_branch()
628
673
        self.assertTrue(branch.repository.has_revision('1'))
629
 
        self.assertTrue(branch.repository.make_working_trees())
 
674
        if not isinstance(branch.bzrdir, RemoteBzrDir):
 
675
            self.assertTrue(branch.repository.make_working_trees())
630
676
        self.assertFalse(branch.repository.is_shared())
631
677
 
632
678
    def test_sprout_bzrdir_repository_under_shared_force_new_repo(self):
633
679
        tree = self.make_branch_and_tree('commit_tree')
634
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
680
        self.build_tree(['commit_tree/foo'])
635
681
        tree.add('foo')
636
682
        tree.commit('revision 1', rev_id='1')
637
683
        tree.bzrdir.open_branch().set_revision_history([])
638
684
        tree.set_parent_trees([])
639
685
        tree.commit('revision 2', rev_id='2')
640
686
        source = self.make_repository('source')
641
 
        tree.bzrdir.open_repository().copy_content_into(source)
 
687
        tree.branch.repository.copy_content_into(source)
642
688
        dir = source.bzrdir
643
689
        try:
644
690
            shared_repo = self.make_repository('target', shared=True)
655
701
        # and sprout it with a revision limit.
656
702
        # 
657
703
        tree = self.make_branch_and_tree('commit_tree')
658
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
704
        self.build_tree(['commit_tree/foo'])
659
705
        tree.add('foo')
660
706
        tree.commit('revision 1', rev_id='1')
661
707
        tree.bzrdir.open_branch().set_revision_history([])
662
708
        tree.set_parent_trees([])
663
709
        tree.commit('revision 2', rev_id='2')
664
710
        source = self.make_repository('source')
665
 
        tree.bzrdir.open_repository().copy_content_into(source)
 
711
        tree.branch.repository.copy_content_into(source)
666
712
        dir = source.bzrdir
667
713
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='2')
668
714
        raise TestSkipped('revision limiting not strict yet')
669
715
 
670
716
    def test_sprout_bzrdir_branch_and_repo(self):
671
717
        tree = self.make_branch_and_tree('commit_tree')
672
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
718
        self.build_tree(['commit_tree/foo'])
673
719
        tree.add('foo')
674
720
        tree.commit('revision 1')
675
721
        source = self.make_branch('source')
676
 
        tree.bzrdir.open_repository().copy_content_into(source.repository)
 
722
        tree.branch.repository.copy_content_into(source.repository)
677
723
        tree.bzrdir.open_branch().copy_content_into(source)
678
724
        dir = source.bzrdir
679
725
        target = self.sproutOrSkip(dir, self.get_url('target'))
697
743
        # sprouting a branch with a repo into a shared repo uses the shared
698
744
        # repo
699
745
        tree = self.make_branch_and_tree('commit_tree')
700
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
746
        self.build_tree(['commit_tree/foo'])
701
747
        tree.add('foo')
702
748
        tree.commit('revision 1', rev_id='1')
703
749
        source = self.make_branch('source')
704
 
        tree.bzrdir.open_repository().copy_content_into(source.repository)
 
750
        tree.branch.repository.copy_content_into(source.repository)
705
751
        tree.bzrdir.open_branch().copy_content_into(source)
706
752
        dir = source.bzrdir
707
753
        try:
715
761
        # sprouting a branch with a repo into a shared repo uses the shared
716
762
        # repo
717
763
        tree = self.make_branch_and_tree('commit_tree')
718
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
764
        self.build_tree(['commit_tree/foo'])
719
765
        tree.add('foo')
720
766
        tree.commit('revision 1', rev_id='1')
721
767
        source = self.make_branch('source')
722
 
        tree.bzrdir.open_repository().copy_content_into(source.repository)
 
768
        tree.branch.repository.copy_content_into(source.repository)
723
769
        tree.bzrdir.open_branch().copy_content_into(source)
724
770
        dir = source.bzrdir
725
771
        try:
808
854
        # and sprout it with a revision limit.
809
855
        # 
810
856
        tree = self.make_branch_and_tree('commit_tree')
811
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
857
        self.build_tree(['commit_tree/foo'])
812
858
        tree.add('foo')
813
859
        tree.commit('revision 1', rev_id='1')
814
860
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
815
861
        source = self.make_branch('source')
816
 
        tree.bzrdir.open_repository().copy_content_into(source.repository)
 
862
        tree.branch.repository.copy_content_into(source.repository)
817
863
        tree.bzrdir.open_branch().copy_content_into(source)
818
864
        dir = source.bzrdir
819
865
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
820
866
        self.assertEqual('1', target.open_branch().last_revision())
821
867
        
822
868
    def test_sprout_bzrdir_tree_branch_repo(self):
823
 
        tree = self.make_branch_and_tree('sourcce')
 
869
        tree = self.make_branch_and_tree('source')
824
870
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
825
871
        tree.add('foo')
826
872
        tree.commit('revision 1')
1046
1092
        source = self.make_branch_and_tree('source')
1047
1093
        source.commit('a', rev_id='a', allow_pointless=True)
1048
1094
        source.commit('b', rev_id='b', allow_pointless=True)
1049
 
        self.build_tree(['new/'])
 
1095
        t.mkdir('new')
1050
1096
        t_new = t.clone('new')
1051
1097
        made_control = self.bzrdir_format.initialize_on_transport(t_new)
1052
1098
        source.branch.repository.clone(made_control)
1294
1340
 
1295
1341
    def test_retire_bzrdir(self):
1296
1342
        bd = self.make_bzrdir('.')
 
1343
        transport = bd.root_transport
1297
1344
        # must not overwrite existing directories
1298
 
        self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',])
1299
 
        self.failUnlessExists('.bzr')
 
1345
        self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
 
1346
            transport=transport)
 
1347
        self.failUnless(transport.has('.bzr'))
1300
1348
        bd.retire_bzrdir()
1301
 
        self.failIfExists('.bzr')
1302
 
        self.failUnlessExists('.bzr.retired.1')
 
1349
        self.failIf(transport.has('.bzr'))
 
1350
        self.failUnless(transport.has('.bzr.retired.1'))
1303
1351
 
1304
1352
class TestBreakLock(TestCaseWithBzrDir):
1305
1353