~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2009-02-23 20:55:58 UTC
  • mfrom: (4034 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4053.
  • Revision ID: jelmer@samba.org-20090223205558-1cx2k4w1zgs8r5qa
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
from bzrlib.transport import get_transport
59
59
from bzrlib.transport.local import LocalTransport
60
60
from bzrlib.upgrade import upgrade
61
 
from bzrlib.remote import RemoteBzrDir
 
61
from bzrlib.remote import RemoteBzrDir, RemoteRepository
62
62
from bzrlib.repofmt import weaverepo
63
63
 
64
64
 
75
75
        """Assert that the content of source and target are identical.
76
76
 
77
77
        paths in ignore list will be completely ignored.
78
 
        
 
78
 
79
79
        We ignore paths that represent data which is allowed to change during
80
80
        a clone or sprout: for instance, inventory.knit contains gzip fragements
81
 
        which have timestamps in them, and as we have read the inventory from 
 
81
        which have timestamps in them, and as we have read the inventory from
82
82
        the source knit, the already-read data is recompressed rather than
83
83
        reading it again, which leads to changed timestamps. This is ok though,
84
84
        because the inventory.kndx file is not ignored, and the integrity of
169
169
 
170
170
    def skipIfNoWorkingTree(self, a_bzrdir):
171
171
        """Raises TestSkipped if a_bzrdir doesn't have a working tree.
172
 
        
 
172
 
173
173
        If the bzrdir does have a workingtree, this is a no-op.
174
174
        """
175
175
        try:
180
180
 
181
181
    def createWorkingTreeOrSkip(self, a_bzrdir):
182
182
        """Create a working tree on a_bzrdir, or raise TestSkipped.
183
 
        
 
183
 
184
184
        A simple wrapper for create_workingtree that translates NotLocalUrl into
185
185
        TestSkipped.  Returns the newly created working tree.
186
186
        """
194
194
                     force_new_repo=False, accelerator_tree=None,
195
195
                     create_tree_if_local=True):
196
196
        """Sprout from_bzrdir into to_url, or raise TestSkipped.
197
 
        
 
197
 
198
198
        A simple wrapper for from_bzrdir.sprout that translates NotLocalUrl into
199
199
        TestSkipped.  Returns the newly sprouted bzrdir.
200
200
        """
286
286
        self.assertNotEqual(dir.transport.base, target.transport.base)
287
287
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
288
288
                                    ['./.bzr/merge-hashes'])
289
 
    
 
289
 
290
290
    def test_clone_bzrdir_empty_force_new_ignored(self):
291
291
        # the force_new_repo parameter should have no effect on an empty
292
292
        # bzrdir's clone logic
295
295
        self.assertNotEqual(dir.transport.base, target.transport.base)
296
296
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
297
297
                                    ['./.bzr/merge-hashes'])
298
 
    
 
298
 
299
299
    def test_clone_bzrdir_repository(self):
300
300
        tree = self.make_branch_and_tree('commit_tree')
301
301
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
389
389
        self.assertTrue(branch.repository.has_revision('1'))
390
390
        self.assertFalse(branch.repository.make_working_trees())
391
391
        self.assertTrue(branch.repository.is_shared())
392
 
        
 
392
 
393
393
    def test_clone_bzrdir_repository_under_shared_force_new_repo(self):
394
394
        tree = self.make_branch_and_tree('commit_tree')
395
395
        self.build_tree(['commit_tree/foo'])
414
414
        # test for revision limiting, [smoke test, not corner case checks].
415
415
        # make a repository with some revisions,
416
416
        # and clone it with a revision limit.
417
 
        # 
 
417
        #
418
418
        tree = self.make_branch_and_tree('commit_tree')
419
419
        self.build_tree(['commit_tree/foo'])
420
420
        tree.add('foo')
510
510
        # test for revision limiting, [smoke test, not corner case checks].
511
511
        # make a branch with some revisions,
512
512
        # and clone it with a revision limit.
513
 
        # 
 
513
        #
514
514
        tree = self.make_branch_and_tree('commit_tree')
515
515
        self.build_tree(['commit_tree/foo'])
516
516
        tree.add('foo')
522
522
        dir = source.bzrdir
523
523
        target = dir.clone(self.get_url('target'), revision_id='1')
524
524
        self.assertEqual('1', target.open_branch().last_revision())
525
 
        
 
525
 
526
526
    def test_clone_bzrdir_tree_branch_repo(self):
527
527
        tree = self.make_branch_and_tree('source')
528
528
        self.build_tree(['source/foo'])
558
558
        target_repo = target_bzrdir.open_repository()
559
559
        source_branch = bzrlib.branch.Branch.open(
560
560
            self.get_vfs_only_url('source'))
 
561
        if isinstance(target_repo, RemoteRepository):
 
562
            target_repo._ensure_real()
 
563
            target_repo = target_repo._real_repository
561
564
        self.assertEqual(target_repo._format, source_branch.repository._format)
562
565
 
563
566
    def test_revert_inventory(self):
592
595
            target.open_repository())
593
596
 
594
597
    def test_clone_bzrdir_tree_branch_reference(self):
595
 
        # a tree with a branch reference (aka a checkout) 
 
598
        # a tree with a branch reference (aka a checkout)
596
599
        # should stay a checkout on clone.
597
600
        referenced_branch = self.make_branch('referencced')
598
601
        dir = self.make_bzrdir('source')
722
725
        target.open_repository()
723
726
        target.open_branch()
724
727
        target.open_workingtree()
725
 
    
 
728
 
726
729
    def test_sprout_bzrdir_repository(self):
727
730
        tree = self.make_branch_and_tree('commit_tree')
728
731
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
753
756
            # If we happen to have a tree, we'll guarantee everything
754
757
            # except for the tree root is the same.
755
758
            inventory_f = file(dir.transport.base+'inventory', 'rb')
756
 
            self.assertContainsRe(inventory_f.read(), 
 
759
            self.assertContainsRe(inventory_f.read(),
757
760
                                  '<inventory file_id="TREE_ROOT[^"]*"'
758
761
                                  ' format="5">\n</inventory>\n')
759
762
            inventory_f.close()
852
855
        # test for revision limiting, [smoke test, not corner case checks].
853
856
        # make a repository with some revisions,
854
857
        # and sprout it with a revision limit.
855
 
        # 
 
858
        #
856
859
        tree = self.make_branch_and_tree('commit_tree')
857
860
        self.build_tree(['commit_tree/foo'])
858
861
        tree.add('foo')
945
948
        self.assertNotEqual(dir.transport.base, target.transport.base)
946
949
        # we want target to have a branch that is in-place.
947
950
        self.assertEqual(target, target.open_branch().bzrdir)
948
 
        # and as we dont support repositories being detached yet, a repo in 
 
951
        # and as we dont support repositories being detached yet, a repo in
949
952
        # place
950
953
        target.open_repository()
951
954
 
970
973
        # we want target to have a branch that is in-place.
971
974
        self.assertEqual(target, target.open_branch().bzrdir)
972
975
        # and we want no repository as the target is shared
973
 
        self.assertRaises(errors.NoRepositoryPresent, 
 
976
        self.assertRaises(errors.NoRepositoryPresent,
974
977
                          target.open_repository)
975
978
        # and we want revision '1' in the shared repo
976
979
        self.assertTrue(shared_repo.has_revision('1'))
1005
1008
        # test for revision limiting, [smoke test, not corner case checks].
1006
1009
        # make a repository with some revisions,
1007
1010
        # and sprout it with a revision limit.
1008
 
        # 
 
1011
        #
1009
1012
        tree = self.make_branch_and_tree('commit_tree')
1010
1013
        self.build_tree(['commit_tree/foo'])
1011
1014
        tree.add('foo')
1017
1020
        dir = source.bzrdir
1018
1021
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
1019
1022
        self.assertEqual('1', target.open_branch().last_revision())
1020
 
        
 
1023
 
1021
1024
    def test_sprout_bzrdir_tree_branch_repo(self):
1022
1025
        tree = self.make_branch_and_tree('source')
1023
1026
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
1060
1063
        self.assertNotEqual(dir.transport.base, target.transport.base)
1061
1064
        # we want target to have a branch that is in-place.
1062
1065
        self.assertEqual(target, target.open_branch().bzrdir)
1063
 
        # and as we dont support repositories being detached yet, a repo in 
 
1066
        # and as we dont support repositories being detached yet, a repo in
1064
1067
        # place
1065
1068
        target.open_repository()
1066
1069
        result_tree = target.open_workingtree()
1089
1092
        self.assertNotEqual(dir.transport.base, target.transport.base)
1090
1093
        # we want target to have a branch that is in-place.
1091
1094
        self.assertEqual(target, target.open_branch().bzrdir)
1092
 
        # and as we dont support repositories being detached yet, a repo in 
 
1095
        # and as we dont support repositories being detached yet, a repo in
1093
1096
        # place
1094
1097
        target.open_repository()
1095
1098
        # we trust that the working tree sprouting works via the other tests.
1181
1184
        made_branch = made_control.create_branch()
1182
1185
        self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
1183
1186
        self.assertEqual(made_control, made_branch.bzrdir)
1184
 
        
 
1187
 
1185
1188
    def test_open_branch(self):
1186
1189
        if not self.bzrdir_format.is_supported():
1187
1190
            # unsupported formats are not loopback testable
1212
1215
        self.assertEqual(made_control, made_repo.bzrdir)
1213
1216
 
1214
1217
    def test_create_repository_shared(self):
1215
 
        # a bzrdir can create a shared repository or 
 
1218
        # a bzrdir can create a shared repository or
1216
1219
        # fail appropriately
1217
1220
        if not self.bzrdir_format.is_supported():
1218
1221
            # unsupported formats are not loopback testable
1230
1233
        self.assertTrue(made_repo.is_shared())
1231
1234
 
1232
1235
    def test_create_repository_nonshared(self):
1233
 
        # a bzrdir can create a non-shared repository 
 
1236
        # a bzrdir can create a non-shared repository
1234
1237
        if not self.bzrdir_format.is_supported():
1235
1238
            # unsupported formats are not loopback testable
1236
1239
            # because the default open will not open them and
1240
1243
        made_control = self.bzrdir_format.initialize(t.base)
1241
1244
        made_repo = made_control.create_repository(shared=False)
1242
1245
        self.assertFalse(made_repo.is_shared())
1243
 
        
 
1246
 
1244
1247
    def test_open_repository(self):
1245
1248
        if not self.bzrdir_format.is_supported():
1246
1249
            # unsupported formats are not loopback testable
1269
1272
        made_tree = self.createWorkingTreeOrSkip(made_control)
1270
1273
        self.failUnless(isinstance(made_tree, workingtree.WorkingTree))
1271
1274
        self.assertEqual(made_control, made_tree.bzrdir)
1272
 
        
 
1275
 
1273
1276
    def test_create_workingtree_revision(self):
1274
1277
        # a bzrdir can construct a working tree for itself @ a specific revision.
1275
1278
        t = self.get_transport()
1286
1289
        except errors.NotLocalUrl:
1287
1290
            raise TestSkipped("Can't make working tree on transport %r" % t)
1288
1291
        self.assertEqual(['a'], made_tree.get_parent_ids())
1289
 
        
 
1292
 
1290
1293
    def test_open_workingtree(self):
1291
1294
        if not self.bzrdir_format.is_supported():
1292
1295
            # unsupported formats are not loopback testable
1394
1397
            self.get_url('intermediate/child'))
1395
1398
        try:
1396
1399
            child_repo = innermost_control.open_repository()
1397
 
            # if there is a repository, then the format cannot ever hit this 
 
1400
            # if there is a repository, then the format cannot ever hit this
1398
1401
            # code path.
1399
1402
            return
1400
1403
        except errors.NoRepositoryPresent:
1415
1418
        made_control = self.bzrdir_format.initialize(url)
1416
1419
        try:
1417
1420
            child_repo = made_control.open_repository()
1418
 
            # if there is a repository, then the format cannot ever hit this 
 
1421
            # if there is a repository, then the format cannot ever hit this
1419
1422
            # code path.
1420
1423
            return
1421
1424
        except errors.NoRepositoryPresent:
1423
1426
        found_repo = made_control.find_repository()
1424
1427
        self.assertEqual(repo.bzrdir.root_transport.base,
1425
1428
                         found_repo.bzrdir.root_transport.base)
1426
 
        
 
1429
 
1427
1430
    def test_find_repository_standalone_with_containing_shared_repository(self):
1428
1431
        # find repo inside a standalone repo inside a shared repo finds the standalone repo
1429
1432
        try:
1456
1459
                            containing_repo.bzrdir.root_transport.base)
1457
1460
 
1458
1461
    def test_find_repository_with_nested_dirs_works(self):
1459
 
        # find repo inside a bzrdir inside a bzrdir inside a shared repo 
 
1462
        # find repo inside a bzrdir inside a bzrdir inside a shared repo
1460
1463
        # finds the outer shared repo.
1461
1464
        try:
1462
1465
            repo = self.make_repository('.', shared=True)
1469
1472
        made_control = self.bzrdir_format.initialize(url)
1470
1473
        try:
1471
1474
            child_repo = made_control.open_repository()
1472
 
            # if there is a repository, then the format cannot ever hit this 
 
1475
            # if there is a repository, then the format cannot ever hit this
1473
1476
            # code path.
1474
1477
            return
1475
1478
        except errors.NoRepositoryPresent:
1478
1481
            self.get_url('intermediate/child'))
1479
1482
        try:
1480
1483
            child_repo = innermost_control.open_repository()
1481
 
            # if there is a repository, then the format cannot ever hit this 
 
1484
            # if there is a repository, then the format cannot ever hit this
1482
1485
            # code path.
1483
1486
            return
1484
1487
        except errors.NoRepositoryPresent:
1486
1489
        found_repo = innermost_control.find_repository()
1487
1490
        self.assertEqual(repo.bzrdir.root_transport.base,
1488
1491
                         found_repo.bzrdir.root_transport.base)
1489
 
        
 
1492
 
1490
1493
    def test_can_and_needs_format_conversion(self):
1491
1494
        # check that we can ask an instance if its upgradable
1492
1495
        dir = self.make_bzrdir('.')
1493
1496
        if dir.can_convert_format():
1494
 
            # if its default updatable there must be an updater 
 
1497
            # if its default updatable there must be an updater
1495
1498
            # (we force the latest known format as downgrades may not be
1496
1499
            # available
1497
1500
            self.assertTrue(isinstance(dir._format.get_converter(
1509
1512
        new_path = urlutils.local_path_from_url(new_url)
1510
1513
        self.failUnlessExists(old_path)
1511
1514
        self.failUnlessExists(new_path)
1512
 
        for (((dir_relpath1, _), entries1), 
 
1515
        for (((dir_relpath1, _), entries1),
1513
1516
             ((dir_relpath2, _), entries2)) in izip(
1514
 
                osutils.walkdirs(old_path), 
 
1517
                osutils.walkdirs(old_path),
1515
1518
                osutils.walkdirs(new_path)):
1516
1519
            self.assertEquals(dir_relpath1, dir_relpath2)
1517
1520
            for f1, f2 in zip(entries1, entries2):
1528
1531
        dir.create_branch()
1529
1532
        self.createWorkingTreeOrSkip(dir)
1530
1533
        if dir.can_convert_format():
1531
 
            # if its default updatable there must be an updater 
 
1534
            # if its default updatable there must be an updater
1532
1535
            # (we force the latest known format as downgrades may not be
1533
1536
            # available
1534
1537
            pb = ui.ui_factory.nested_progress_bar()
1564
1567
            transport=transport)
1565
1568
        self.failUnless(transport.has('.bzr'))
1566
1569
        self.assertRaises((errors.FileExists, errors.DirectoryNotEmpty),
1567
 
            bd.retire_bzrdir, limit=0) 
 
1570
            bd.retire_bzrdir, limit=0)
1568
1571
 
1569
1572
 
1570
1573
class TestBreakLock(TestCaseWithBzrDir):
1659
1662
        self.assertRaises(errors.LockBroken, master.unlock)
1660
1663
 
1661
1664
    def test_break_lock_tree(self):
1662
 
        # break lock with a tree should unlock the tree but not try the 
1663
 
        # branch explicitly. However this is very hard to test for as we 
1664
 
        # dont have a tree reference class, nor is one needed; 
 
1665
        # break lock with a tree should unlock the tree but not try the
 
1666
        # branch explicitly. However this is very hard to test for as we
 
1667
        # dont have a tree reference class, nor is one needed;
1665
1668
        # the worst case if this code unlocks twice is an extra question
1666
1669
        # being asked.
1667
1670
        tree = self.make_branch_and_tree('.')
1705
1708
class ChrootedBzrDirTests(ChrootedTestCase):
1706
1709
 
1707
1710
    def test_find_repository_no_repository(self):
1708
 
        # loopback test to check the current format fails to find a 
 
1711
        # loopback test to check the current format fails to find a
1709
1712
        # share repository correctly.
1710
1713
        if not self.bzrdir_format.is_supported():
1711
1714
            # unsupported formats are not loopback testable
1720
1723
        made_control = self.bzrdir_format.initialize(self.get_url('subdir'))
1721
1724
        try:
1722
1725
            repo = made_control.open_repository()
1723
 
            # if there is a repository, then the format cannot ever hit this 
 
1726
            # if there is a repository, then the format cannot ever hit this
1724
1727
            # code path.
1725
1728
            return
1726
1729
        except errors.NoRepositoryPresent: