68
70
old_format = bzrdir.BzrDirFormat.get_default_format()
69
71
# default is BzrDirFormat6
70
72
self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
71
bzrdir.BzrDirFormat._set_default_format(SampleBzrDirFormat())
73
controldir.ControlDirFormat._set_default_format(SampleBzrDirFormat())
72
74
# creating a bzr dir should now create an instrumented dir.
74
76
result = bzrdir.BzrDir.create('memory:///')
75
77
self.failUnless(isinstance(result, SampleBzrDir))
77
bzrdir.BzrDirFormat._set_default_format(old_format)
79
controldir.ControlDirFormat._set_default_format(old_format)
78
80
self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
81
83
class TestFormatRegistry(TestCase):
83
85
def make_format_registry(self):
84
my_format_registry = bzrdir.BzrDirFormatRegistry()
86
my_format_registry = controldir.ControlDirFormatRegistry()
85
87
my_format_registry.register('weave', bzrdir.BzrDirFormat6,
86
88
'Pre-0.8 format. Slower and does not support checkouts or shared'
87
89
' repositories', deprecated=True)
88
90
my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
89
91
'BzrDirFormat6', 'Format registered lazily', deprecated=True)
90
my_format_registry.register_metadir('knit',
92
bzrdir.register_metadir(my_format_registry, 'knit',
91
93
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
92
94
'Format using knits',
94
96
my_format_registry.set_default('knit')
95
my_format_registry.register_metadir(
97
bzrdir.register_metadir(my_format_registry,
97
99
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
98
100
'Experimental successor to knit. Use at your own risk.',
99
101
branch_format='bzrlib.branch.BzrBranchFormat6',
100
102
experimental=True)
101
my_format_registry.register_metadir(
103
bzrdir.register_metadir(my_format_registry,
103
105
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
104
106
'Experimental successor to knit. Use at your own risk.',
173
175
bzrdir.format_registry.set_default_repository(old_default)
175
177
def test_aliases(self):
176
a_registry = bzrdir.BzrDirFormatRegistry()
178
a_registry = controldir.ControlDirFormatRegistry()
177
179
a_registry.register('weave', bzrdir.BzrDirFormat6,
178
180
'Pre-0.8 format. Slower and does not support checkouts or shared'
179
181
' repositories', deprecated=True)
888
890
self.assertEqual(bar.root_transport.base, branches[1].base)
893
class TestMissingRepoBranchesSkipped(TestCaseWithMemoryTransport):
895
def test_find_bzrdirs_missing_repo(self):
896
transport = get_transport(self.get_url())
897
arepo = self.make_repository('arepo', shared=True)
898
abranch_url = arepo.user_url + '/abranch'
899
abranch = bzrdir.BzrDir.create(abranch_url).create_branch()
900
transport.delete_tree('arepo/.bzr')
901
self.assertRaises(errors.NoRepositoryPresent,
902
branch.Branch.open, abranch_url)
903
self.make_branch('baz')
904
for actual_bzrdir in bzrdir.BzrDir.find_branches(transport):
905
self.assertEndsWith(actual_bzrdir.user_url, '/baz/')
891
908
class TestMeta1DirFormat(TestCaseWithTransport):
892
909
"""Tests specific to the meta1 dir format."""
1042
1059
def _known_formats(self):
1043
1060
return set([NotBzrDirFormat()])
1063
class NotBzrDirProber(controldir.Prober):
1046
1065
def probe_transport(self, transport):
1047
1066
"""Our format is present if the transport ends in '.not/'."""
1048
1067
if transport.has('.not'):
1062
1081
dir = format.initialize(self.get_url())
1063
1082
self.assertIsInstance(dir, NotBzrDir)
1064
1083
# now probe for it.
1065
bzrlib.bzrdir.BzrDirFormat.register_control_format(format)
1084
controldir.ControlDirFormat.register_prober(NotBzrDirProber)
1067
1086
found = bzrlib.bzrdir.BzrDirFormat.find_format(
1068
1087
get_transport(self.get_url()))
1069
1088
self.assertIsInstance(found, NotBzrDirFormat)
1071
bzrlib.bzrdir.BzrDirFormat.unregister_control_format(format)
1090
controldir.ControlDirFormat.unregister_prober(NotBzrDirProber)
1073
1092
def test_included_in_known_formats(self):
1074
bzrlib.bzrdir.BzrDirFormat.register_control_format(NotBzrDirFormat)
1093
not_format = NotBzrDirFormat()
1094
bzrlib.controldir.ControlDirFormat.register_format(not_format)
1076
1096
formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
1077
1097
for format in formats:
1145
1165
def create_transport_readonly_server(self):
1166
# We don't set the http protocol version, relying on the default
1146
1167
return http_utils.HTTPServerRedirecting()
1148
1169
def create_transport_secondary_server(self):
1170
# We don't set the http protocol version, relying on the default
1149
1171
return http_utils.HTTPServerRedirecting()
1151
1173
def setUp(self):
1383
1405
self.assertIsInstance(params, RepoInitHookParams)
1384
1406
self.assertTrue(hasattr(params, 'bzrdir'))
1385
1407
self.assertTrue(hasattr(params, 'repository'))
1409
def test_post_repo_init_hook_repr(self):
1411
bzrdir.BzrDir.hooks.install_named_hook('post_repo_init',
1412
lambda params: param_reprs.append(repr(params)), None)
1413
self.make_repository('foo')
1414
self.assertLength(1, param_reprs)
1415
param_repr = param_reprs[0]
1416
self.assertStartsWith(param_repr, '<RepoInitHookParams for ')
1419
class TestGenerateBackupName(TestCaseWithMemoryTransport):
1422
super(TestGenerateBackupName, self).setUp()
1423
self._transport = get_transport(self.get_url())
1424
bzrdir.BzrDir.create(self.get_url(),
1425
possible_transports=[self._transport])
1426
self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)
1429
self.assertEqual("a.~1~", self._bzrdir.generate_backup_name("a"))
1431
def test_exiting(self):
1432
self._transport.put_bytes("a.~1~", "some content")
1433
self.assertEqual("a.~2~", self._bzrdir.generate_backup_name("a"))