~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2007-04-28 15:04:17 UTC
  • mfrom: (2466 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2566.
  • Revision ID: john@arbash-meinel.com-20070428150417-trp3pi0pzd411pu4
[merge] bzr.dev 2466

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
 
178
179
        bzrdir.destroy_workingtree_metadata()
179
180
        self.failUnlessExists('tree/file')
180
181
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
 
182
 
 
183
    def test_open_workingtree_raises_no_working_tree(self):
 
184
        """BzrDir.open_workingtree() should raise NoWorkingTree (rather than
 
185
        e.g. NotLocalUrl) if there is no working tree.
 
186
        """
 
187
        dir = self.make_bzrdir('source')
 
188
        vfs_dir = bzrdir.BzrDir.open(self.get_vfs_only_url('source'))
 
189
        if vfs_dir.has_workingtree():
 
190
            # This BzrDir format doesn't support BzrDirs without working trees,
 
191
            # so this test is irrelevant.
 
192
            return
 
193
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
181
194
            
182
195
    def test_clone_bzrdir_empty(self):
183
196
        dir = self.make_bzrdir('source')
231
244
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
232
245
 
233
246
    def test_clone_bzrdir_repository_branch_both_under_shared(self):
 
247
        # Create a shared repository
234
248
        try:
235
249
            shared_repo = self.make_repository('shared', shared=True)
236
250
        except errors.IncompatibleFormat:
237
251
            return
 
252
        # Make a branch, 'commit_tree', and working tree outside of the shared
 
253
        # repository, and commit some revisions to it.
238
254
        tree = self.make_branch_and_tree('commit_tree')
239
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
255
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
240
256
        tree.add('foo')
241
257
        tree.commit('revision 1', rev_id='1')
242
258
        tree.bzrdir.open_branch().set_revision_history([])
243
259
        tree.set_parent_trees([])
244
260
        tree.commit('revision 2', rev_id='2')
245
 
        tree.bzrdir.open_repository().copy_content_into(shared_repo)
 
261
        # Copy the content (i.e. revisions) from the 'commit_tree' branch's
 
262
        # repository into the shared repository.
 
263
        tree.branch.repository.copy_content_into(shared_repo)
 
264
        # Make a branch 'source' inside the shared repository.
246
265
        dir = self.make_bzrdir('shared/source')
247
266
        dir.create_branch()
 
267
        # Clone 'source' to 'target', also inside the shared repository.
248
268
        target = dir.clone(self.get_url('shared/target'))
 
269
        # 'source', 'target', and the shared repo all have distinct bzrdirs.
249
270
        self.assertNotEqual(dir.transport.base, target.transport.base)
250
271
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
 
272
        # The shared repository will contain revisions from the 'commit_tree'
 
273
        # repository, even revisions that are not part of the history of the
 
274
        # 'commit_tree' branch.
251
275
        self.assertTrue(shared_repo.has_revision('1'))
252
276
 
253
277
    def test_clone_bzrdir_repository_branch_only_source_under_shared(self):
256
280
        except errors.IncompatibleFormat:
257
281
            return
258
282
        tree = self.make_branch_and_tree('commit_tree')
259
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
283
        self.build_tree(['commit_tree/foo'])
260
284
        tree.add('foo')
261
285
        tree.commit('revision 1', rev_id='1')
262
 
        tree.bzrdir.open_branch().set_revision_history([])
 
286
        tree.branch.bzrdir.open_branch().set_revision_history([])
263
287
        tree.set_parent_trees([])
264
288
        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())
 
289
        tree.branch.repository.copy_content_into(shared_repo)
 
290
        if shared_repo.make_working_trees():
 
291
            shared_repo.set_make_working_trees(False)
 
292
            self.assertFalse(shared_repo.make_working_trees())
268
293
        self.assertTrue(shared_repo.has_revision('1'))
269
294
        dir = self.make_bzrdir('shared/source')
270
295
        dir.create_branch()
278
303
        
279
304
    def test_clone_bzrdir_repository_under_shared_force_new_repo(self):
280
305
        tree = self.make_branch_and_tree('commit_tree')
281
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
306
        self.build_tree(['commit_tree/foo'])
282
307
        tree.add('foo')
283
308
        tree.commit('revision 1', rev_id='1')
284
309
        dir = self.make_bzrdir('source')
301
326
        # and clone it with a revision limit.
302
327
        # 
303
328
        tree = self.make_branch_and_tree('commit_tree')
304
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
329
        self.build_tree(['commit_tree/foo'])
305
330
        tree.add('foo')
306
331
        tree.commit('revision 1', rev_id='1')
307
 
        tree.bzrdir.open_branch().set_revision_history([])
 
332
        tree.branch.bzrdir.open_branch().set_revision_history([])
308
333
        tree.set_parent_trees([])
309
334
        tree.commit('revision 2', rev_id='2')
310
335
        source = self.make_repository('source')
311
 
        tree.bzrdir.open_repository().copy_content_into(source)
 
336
        tree.branch.repository.copy_content_into(source)
312
337
        dir = source.bzrdir
313
338
        target = dir.clone(self.get_url('target'), revision_id='2')
314
339
        raise TestSkipped('revision limiting not strict yet')
315
340
 
316
341
    def test_clone_bzrdir_branch_and_repo(self):
317
342
        tree = self.make_branch_and_tree('commit_tree')
318
 
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
 
343
        self.build_tree(['commit_tree/foo'])
319
344
        tree.add('foo')
320
345
        tree.commit('revision 1')
321
346
        source = self.make_branch('source')
336
361
    def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
337
362
        # by default cloning into a shared repo uses the shared repo.
338
363
        tree = self.make_branch_and_tree('commit_tree')
339
 
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
 
364
        self.build_tree(['commit_tree/foo'])
340
365
        tree.add('foo')
341
366
        tree.commit('revision 1')
342
367
        source = self.make_branch('source')
356
381
    def test_clone_bzrdir_branch_and_repo_into_shared_repo_force_new_repo(self):
357
382
        # by default cloning into a shared repo uses the shared repo.
358
383
        tree = self.make_branch_and_tree('commit_tree')
359
 
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
 
384
        self.build_tree(['commit_tree/foo'])
360
385
        tree.add('foo')
361
386
        tree.commit('revision 1')
362
387
        source = self.make_branch('source')
396
421
        # and clone it with a revision limit.
397
422
        # 
398
423
        tree = self.make_branch_and_tree('commit_tree')
399
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
424
        self.build_tree(['commit_tree/foo'])
400
425
        tree.add('foo')
401
426
        tree.commit('revision 1', rev_id='1')
402
427
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
408
433
        self.assertEqual('1', target.open_branch().last_revision())
409
434
        
410
435
    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('..'))
 
436
        tree = self.make_branch_and_tree('source')
 
437
        self.build_tree(['source/foo'])
413
438
        tree.add('foo')
414
439
        tree.commit('revision 1')
415
440
        dir = tree.bzrdir
428
453
        target.open_workingtree().revert([])
429
454
 
430
455
    def test_revert_inventory(self):
431
 
        tree = self.make_branch_and_tree('sourcce')
432
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
456
        tree = self.make_branch_and_tree('source')
 
457
        self.build_tree(['source/foo'])
433
458
        tree.add('foo')
434
459
        tree.commit('revision 1')
435
460
        dir = tree.bzrdir
484
509
        # This smoke test just checks the revision-id is right. Tree specific
485
510
        # tests will check corner cases.
486
511
        tree = self.make_branch_and_tree('source')
487
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
512
        self.build_tree(['source/foo'])
488
513
        tree.add('foo')
489
514
        tree.commit('revision 1', rev_id='1')
490
515
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
493
518
        self.skipIfNoWorkingTree(target)
494
519
        self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
495
520
 
 
521
    def test_get_branch_reference_on_reference(self):
 
522
        """get_branch_reference should return the right url."""
 
523
        referenced_branch = self.make_branch('referenced')
 
524
        dir = self.make_bzrdir('source')
 
525
        try:
 
526
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
 
527
                referenced_branch)
 
528
        except errors.IncompatibleFormat:
 
529
            # this is ok too, not all formats have to support references.
 
530
            return
 
531
        self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
 
532
            dir.get_branch_reference())
 
533
 
 
534
    def test_get_branch_reference_on_non_reference(self):
 
535
        """get_branch_reference should return None for non-reference branches."""
 
536
        branch = self.make_branch('referenced')
 
537
        self.assertEqual(None, branch.bzrdir.get_branch_reference())
 
538
 
 
539
    def test_get_branch_reference_no_branch(self):
 
540
        """get_branch_reference should not mask NotBranchErrors."""
 
541
        dir = self.make_bzrdir('source')
 
542
        if dir.has_branch():
 
543
            # this format does not support branchless bzrdirs.
 
544
            return
 
545
        self.assertRaises(errors.NotBranchError, dir.get_branch_reference)
 
546
 
496
547
    def test_sprout_bzrdir_empty(self):
497
548
        dir = self.make_bzrdir('source')
498
549
        target = self.sproutOrSkip(dir, self.get_url('target'))
512
563
        target = self.sproutOrSkip(dir, self.get_url('target/child'))
513
564
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
514
565
        target.open_branch()
515
 
        target.open_workingtree()
 
566
        try:
 
567
            target.open_workingtree()
 
568
        except errors.NoWorkingTree:
 
569
            # bzrdir's that never have working trees are allowed to pass;
 
570
            # whitelist them for now.
 
571
            self.assertIsInstance(target, RemoteBzrDir)
516
572
 
517
573
    def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
518
574
        # the force_new_repo parameter should force use of a new repo in an empty
566
622
 
567
623
    def test_sprout_bzrdir_with_repository_to_shared(self):
568
624
        tree = self.make_branch_and_tree('commit_tree')
569
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
625
        self.build_tree(['commit_tree/foo'])
570
626
        tree.add('foo')
571
627
        tree.commit('revision 1', rev_id='1')
572
628
        tree.bzrdir.open_branch().set_revision_history([])
573
629
        tree.set_parent_trees([])
574
630
        tree.commit('revision 2', rev_id='2')
575
631
        source = self.make_repository('source')
576
 
        tree.bzrdir.open_repository().copy_content_into(source)
 
632
        tree.branch.repository.copy_content_into(source)
577
633
        dir = source.bzrdir
578
634
        try:
579
635
            shared_repo = self.make_repository('target', shared=True)
589
645
        except errors.IncompatibleFormat:
590
646
            return
591
647
        tree = self.make_branch_and_tree('commit_tree')
592
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
648
        self.build_tree(['commit_tree/foo'])
593
649
        tree.add('foo')
594
650
        tree.commit('revision 1', rev_id='1')
595
651
        tree.bzrdir.open_branch().set_revision_history([])
596
652
        tree.set_parent_trees([])
597
653
        tree.commit('revision 2', rev_id='2')
598
 
        tree.bzrdir.open_repository().copy_content_into(shared_repo)
 
654
        tree.branch.repository.copy_content_into(shared_repo)
599
655
        dir = self.make_bzrdir('shared/source')
600
656
        dir.create_branch()
601
657
        target = self.sproutOrSkip(dir, self.get_url('shared/target'))
609
665
        except errors.IncompatibleFormat:
610
666
            return
611
667
        tree = self.make_branch_and_tree('commit_tree')
612
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
668
        self.build_tree(['commit_tree/foo'])
613
669
        tree.add('foo')
614
670
        tree.commit('revision 1', rev_id='1')
615
671
        tree.bzrdir.open_branch().set_revision_history([])
616
672
        tree.set_parent_trees([])
617
673
        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())
 
674
        tree.branch.repository.copy_content_into(shared_repo)
 
675
        if shared_repo.make_working_trees():
 
676
            shared_repo.set_make_working_trees(False)
 
677
            self.assertFalse(shared_repo.make_working_trees())
621
678
        self.assertTrue(shared_repo.has_revision('1'))
622
679
        dir = self.make_bzrdir('shared/source')
623
680
        dir.create_branch()
626
683
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
627
684
        branch = target.open_branch()
628
685
        self.assertTrue(branch.repository.has_revision('1'))
629
 
        self.assertTrue(branch.repository.make_working_trees())
 
686
        if not isinstance(branch.bzrdir, RemoteBzrDir):
 
687
            self.assertTrue(branch.repository.make_working_trees())
630
688
        self.assertFalse(branch.repository.is_shared())
631
689
 
632
690
    def test_sprout_bzrdir_repository_under_shared_force_new_repo(self):
633
691
        tree = self.make_branch_and_tree('commit_tree')
634
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
692
        self.build_tree(['commit_tree/foo'])
635
693
        tree.add('foo')
636
694
        tree.commit('revision 1', rev_id='1')
637
695
        tree.bzrdir.open_branch().set_revision_history([])
638
696
        tree.set_parent_trees([])
639
697
        tree.commit('revision 2', rev_id='2')
640
698
        source = self.make_repository('source')
641
 
        tree.bzrdir.open_repository().copy_content_into(source)
 
699
        tree.branch.repository.copy_content_into(source)
642
700
        dir = source.bzrdir
643
701
        try:
644
702
            shared_repo = self.make_repository('target', shared=True)
655
713
        # and sprout it with a revision limit.
656
714
        # 
657
715
        tree = self.make_branch_and_tree('commit_tree')
658
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
716
        self.build_tree(['commit_tree/foo'])
659
717
        tree.add('foo')
660
718
        tree.commit('revision 1', rev_id='1')
661
719
        tree.bzrdir.open_branch().set_revision_history([])
662
720
        tree.set_parent_trees([])
663
721
        tree.commit('revision 2', rev_id='2')
664
722
        source = self.make_repository('source')
665
 
        tree.bzrdir.open_repository().copy_content_into(source)
 
723
        tree.branch.repository.copy_content_into(source)
666
724
        dir = source.bzrdir
667
725
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='2')
668
726
        raise TestSkipped('revision limiting not strict yet')
669
727
 
670
728
    def test_sprout_bzrdir_branch_and_repo(self):
671
729
        tree = self.make_branch_and_tree('commit_tree')
672
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
730
        self.build_tree(['commit_tree/foo'])
673
731
        tree.add('foo')
674
732
        tree.commit('revision 1')
675
733
        source = self.make_branch('source')
676
 
        tree.bzrdir.open_repository().copy_content_into(source.repository)
 
734
        tree.branch.repository.copy_content_into(source.repository)
677
735
        tree.bzrdir.open_branch().copy_content_into(source)
678
736
        dir = source.bzrdir
679
737
        target = self.sproutOrSkip(dir, self.get_url('target'))
697
755
        # sprouting a branch with a repo into a shared repo uses the shared
698
756
        # repo
699
757
        tree = self.make_branch_and_tree('commit_tree')
700
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
758
        self.build_tree(['commit_tree/foo'])
701
759
        tree.add('foo')
702
760
        tree.commit('revision 1', rev_id='1')
703
761
        source = self.make_branch('source')
704
 
        tree.bzrdir.open_repository().copy_content_into(source.repository)
 
762
        tree.branch.repository.copy_content_into(source.repository)
705
763
        tree.bzrdir.open_branch().copy_content_into(source)
706
764
        dir = source.bzrdir
707
765
        try:
715
773
        # sprouting a branch with a repo into a shared repo uses the shared
716
774
        # repo
717
775
        tree = self.make_branch_and_tree('commit_tree')
718
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
776
        self.build_tree(['commit_tree/foo'])
719
777
        tree.add('foo')
720
778
        tree.commit('revision 1', rev_id='1')
721
779
        source = self.make_branch('source')
722
 
        tree.bzrdir.open_repository().copy_content_into(source.repository)
 
780
        tree.branch.repository.copy_content_into(source.repository)
723
781
        tree.bzrdir.open_branch().copy_content_into(source)
724
782
        dir = source.bzrdir
725
783
        try:
808
866
        # and sprout it with a revision limit.
809
867
        # 
810
868
        tree = self.make_branch_and_tree('commit_tree')
811
 
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
 
869
        self.build_tree(['commit_tree/foo'])
812
870
        tree.add('foo')
813
871
        tree.commit('revision 1', rev_id='1')
814
872
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
815
873
        source = self.make_branch('source')
816
 
        tree.bzrdir.open_repository().copy_content_into(source.repository)
 
874
        tree.branch.repository.copy_content_into(source.repository)
817
875
        tree.bzrdir.open_branch().copy_content_into(source)
818
876
        dir = source.bzrdir
819
877
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
820
878
        self.assertEqual('1', target.open_branch().last_revision())
821
879
        
822
880
    def test_sprout_bzrdir_tree_branch_repo(self):
823
 
        tree = self.make_branch_and_tree('sourcce')
 
881
        tree = self.make_branch_and_tree('source')
824
882
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
825
883
        tree.add('foo')
826
884
        tree.commit('revision 1')
1046
1104
        source = self.make_branch_and_tree('source')
1047
1105
        source.commit('a', rev_id='a', allow_pointless=True)
1048
1106
        source.commit('b', rev_id='b', allow_pointless=True)
1049
 
        self.build_tree(['new/'])
 
1107
        t.mkdir('new')
1050
1108
        t_new = t.clone('new')
1051
1109
        made_control = self.bzrdir_format.initialize_on_transport(t_new)
1052
1110
        source.branch.repository.clone(made_control)
1294
1352
 
1295
1353
    def test_retire_bzrdir(self):
1296
1354
        bd = self.make_bzrdir('.')
 
1355
        transport = bd.root_transport
1297
1356
        # must not overwrite existing directories
1298
 
        self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',])
1299
 
        self.failUnlessExists('.bzr')
 
1357
        self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
 
1358
            transport=transport)
 
1359
        self.failUnless(transport.has('.bzr'))
1300
1360
        bd.retire_bzrdir()
1301
 
        self.failIfExists('.bzr')
1302
 
        self.failUnlessExists('.bzr.retired.1')
 
1361
        self.failIf(transport.has('.bzr'))
 
1362
        self.failUnless(transport.has('.bzr.retired.1'))
1303
1363
 
1304
1364
class TestBreakLock(TestCaseWithBzrDir):
1305
1365