/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Jonathan Lange
  • Date: 2009-12-09 09:20:42 UTC
  • mfrom: (4881 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4907.
  • Revision ID: jml@canonical.com-20091209092042-s2zgqcf8f39yzxpj
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import bzrlib.branch
27
27
from bzrlib import (
28
28
    bzrdir,
 
29
    check,
29
30
    errors,
 
31
    gpg,
30
32
    lockdir,
31
33
    osutils,
32
34
    repository,
38
40
    workingtree,
39
41
    )
40
42
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
41
 
from bzrlib.check import check_branch
42
43
from bzrlib.errors import (FileExists,
43
44
                           NoSuchRevision,
44
45
                           NoSuchFile,
53
54
                          TestNotApplicable,
54
55
                          TestSkipped,
55
56
                          )
56
 
from bzrlib.tests.bzrdir_implementations import TestCaseWithBzrDir
 
57
from bzrlib.tests.per_bzrdir import TestCaseWithBzrDir
57
58
from bzrlib.trace import mutter
58
59
from bzrlib.transport import get_transport
59
60
from bzrlib.transport.local import LocalTransport
 
61
from bzrlib.ui import (
 
62
    CannedInputUIFactory,
 
63
    )
60
64
from bzrlib.upgrade import upgrade
61
65
from bzrlib.remote import RemoteBzrDir, RemoteRepository
62
66
from bzrlib.repofmt import weaverepo
429
433
        target = dir.clone(self.get_url('target'), revision_id='2')
430
434
        raise TestSkipped('revision limiting not strict yet')
431
435
 
 
436
    def test_clone_bzrdir_branch_and_repo_fixed_user_id(self):
 
437
        # Bug #430868 is about an email containing '.sig'
 
438
        os.environ['BZR_EMAIL'] = 'murphy@host.sighup.org'
 
439
        tree = self.make_branch_and_tree('commit_tree')
 
440
        self.build_tree(['commit_tree/foo'])
 
441
        tree.add('foo')
 
442
        rev1 = tree.commit('revision 1')
 
443
        tree_repo = tree.branch.repository
 
444
        tree_repo.lock_write()
 
445
        tree_repo.start_write_group()
 
446
        tree_repo.sign_revision(rev1, gpg.LoopbackGPGStrategy(None))
 
447
        tree_repo.commit_write_group()
 
448
        tree_repo.unlock()
 
449
        target = self.make_branch('target')
 
450
        tree.branch.repository.copy_content_into(target.repository)
 
451
        tree.branch.copy_content_into(target)
 
452
        self.assertTrue(target.repository.has_revision(rev1))
 
453
        self.assertEqual(
 
454
            tree_repo.get_signature_text(rev1),
 
455
            target.repository.get_signature_text(rev1))
 
456
 
432
457
    def test_clone_bzrdir_branch_and_repo(self):
433
458
        tree = self.make_branch_and_tree('commit_tree')
434
459
        self.build_tree(['commit_tree/foo'])
753
778
                                     './.bzr/repository/inventory.knit',
754
779
                                     ])
755
780
        try:
 
781
            local_inventory = dir.transport.local_abspath('inventory')
 
782
        except errors.NotLocalUrl:
 
783
            return
 
784
        try:
756
785
            # If we happen to have a tree, we'll guarantee everything
757
786
            # except for the tree root is the same.
758
 
            inventory_f = file(dir.transport.base+'inventory', 'rb')
 
787
            inventory_f = file(local_inventory, 'rb')
 
788
            self.addCleanup(inventory_f.close)
759
789
            self.assertContainsRe(inventory_f.read(),
760
 
                                  '<inventory file_id="TREE_ROOT[^"]*"'
761
 
                                  ' format="5">\n</inventory>\n')
762
 
            inventory_f.close()
 
790
                                  '<inventory format="5">\n</inventory>\n')
763
791
        except IOError, e:
764
792
            if e.errno != errno.ENOENT:
765
793
                raise
1207
1235
            return
1208
1236
        self.assertNotEqual(repo.bzrdir.root_transport.base,
1209
1237
            made_repo.bzrdir.root_transport.base)
1210
 
        # New repositories are write locked.
1211
 
        self.assertTrue(made_repo.is_write_locked())
1212
 
        made_repo.unlock()
1213
1238
 
1214
1239
    def test_format_initialize_on_transport_ex_force_new_repo_False(self):
1215
1240
        t = self.get_transport('repo')
1242
1267
            # uninitialisable format
1243
1268
            return
1244
1269
        self.assertLength(1, repo._fallback_repositories)
1245
 
        # New repositories are write locked.
1246
 
        self.assertTrue(repo.is_write_locked())
1247
 
        repo.unlock()
1248
1270
 
1249
1271
    def test_format_initialize_on_transport_ex_default_stack_on(self):
1250
1272
        # When initialize_on_transport_ex uses a stacked-on branch because of
1252
1274
        # repository is the same as the external location of the stacked-on
1253
1275
        # branch.
1254
1276
        balloon = self.make_bzrdir('balloon')
1255
 
        if isinstance(balloon, bzrdir.BzrDirMetaFormat1):
 
1277
        if isinstance(balloon._format, bzrdir.BzrDirMetaFormat1):
1256
1278
            stack_on = self.make_branch('stack-on', format='1.9')
1257
1279
        else:
1258
1280
            stack_on = self.make_branch('stack-on')
1267
1289
        repo_name = repo_fmt.repository_format.network_name()
1268
1290
        repo, control = self.assertInitializeEx(
1269
1291
            t, need_meta=True, repo_format_name=repo_name, stacked_on=None)
 
1292
        # self.addCleanup(repo.unlock)
1270
1293
        if control is None:
1271
1294
            # uninitialisable format
1272
1295
            return
1298
1321
            # must stay with the all-in-one-format.
1299
1322
            repo_name = self.bzrdir_format.network_name()
1300
1323
        self.assertEqual(repo_name, repo._format.network_name())
1301
 
        # New repositories are write locked.
1302
 
        self.assertTrue(repo.is_write_locked())
1303
 
        repo.unlock()
1304
1324
 
1305
1325
    def assertInitializeEx(self, t, need_meta=False, **kwargs):
1306
1326
        """Execute initialize_on_transport_ex and check it succeeded correctly.
1318
1338
            return None, None
1319
1339
        repo, control, require_stacking, repo_policy = \
1320
1340
            self.bzrdir_format.initialize_on_transport_ex(t, **kwargs)
 
1341
        if repo is not None:
 
1342
            # Repositories are open write-locked
 
1343
            self.assertTrue(repo.is_write_locked())
 
1344
            self.addCleanup(repo.unlock)
1321
1345
        self.assertIsInstance(control, bzrdir.BzrDir)
1322
1346
        opened = bzrdir.BzrDir.open(t.base)
1323
1347
        expected_format = self.bzrdir_format
1735
1759
            finally:
1736
1760
                pb.finished()
1737
1761
            # and it should pass 'check' now.
1738
 
            check_branch(bzrdir.BzrDir.open(self.get_url('.')).open_branch(),
1739
 
                         False)
 
1762
            check.check_dwim(self.get_url('.'), False, True, True)
1740
1763
 
1741
1764
    def test_format_description(self):
1742
1765
        dir = self.make_bzrdir('.')
1774
1797
        # ours
1775
1798
        self.old_factory = bzrlib.ui.ui_factory
1776
1799
        self.addCleanup(self.restoreFactory)
1777
 
        bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1778
1800
 
1779
1801
    def restoreFactory(self):
1780
1802
        bzrlib.ui.ui_factory = self.old_factory
1800
1822
            return
1801
1823
        # only one yes needed here: it should only be unlocking
1802
1824
        # the repo
1803
 
        bzrlib.ui.ui_factory.stdin = StringIO("y\n")
 
1825
        bzrlib.ui.ui_factory = CannedInputUIFactory([True])
1804
1826
        try:
1805
1827
            repo.bzrdir.break_lock()
1806
1828
        except NotImplementedError:
1831
1853
            # two yes's : branch and repository. If the repo in this
1832
1854
            # dir is inappropriately accessed, 3 will be needed, and
1833
1855
            # we'll see that because the stream will be fully consumed
1834
 
            bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\n")
 
1856
            bzrlib.ui.ui_factory = CannedInputUIFactory([True, True, True])
1835
1857
            # determine if the repository will have been locked;
1836
1858
            this_repo_locked = \
1837
1859
                thisdir.open_repository().get_physical_lock_status()
1838
1860
            master.bzrdir.break_lock()
1839
1861
            if this_repo_locked:
1840
1862
                # only two ys should have been read
1841
 
                self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
 
1863
                self.assertEqual([True],
 
1864
                    bzrlib.ui.ui_factory.responses)
1842
1865
            else:
1843
1866
                # only one y should have been read
1844
 
                self.assertEqual("y\ny\n", bzrlib.ui.ui_factory.stdin.read())
 
1867
                self.assertEqual([True, True],
 
1868
                    bzrlib.ui.ui_factory.responses)
1845
1869
            # we should be able to lock a newly opened branch now
1846
1870
            branch = master.bzrdir.open_branch()
1847
1871
            branch.lock_write()
1865
1889
        tree = self.make_branch_and_tree('.')
1866
1890
        tree.lock_write()
1867
1891
        # three yes's : tree, branch and repository.
1868
 
        bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\ny\n")
 
1892
        bzrlib.ui.ui_factory = CannedInputUIFactory([True, True, True])
1869
1893
        try:
1870
1894
            tree.bzrdir.break_lock()
1871
1895
        except (NotImplementedError, errors.LockActive):
1875
1899
            # object.
1876
1900
            tree.unlock()
1877
1901
            return
1878
 
        self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
 
1902
        self.assertEqual([True],
 
1903
                bzrlib.ui.ui_factory.responses)
1879
1904
        lock_tree = tree.bzrdir.open_workingtree()
1880
1905
        lock_tree.lock_write()
1881
1906
        lock_tree.unlock()