67
71
old_format = bzrdir.BzrDirFormat.get_default_format()
68
72
# default is BzrDirFormat6
69
73
self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
70
bzrdir.BzrDirFormat._set_default_format(SampleBzrDirFormat())
74
controldir.ControlDirFormat._set_default_format(SampleBzrDirFormat())
71
75
# creating a bzr dir should now create an instrumented dir.
73
77
result = bzrdir.BzrDir.create('memory:///')
74
78
self.failUnless(isinstance(result, SampleBzrDir))
76
bzrdir.BzrDirFormat._set_default_format(old_format)
80
controldir.ControlDirFormat._set_default_format(old_format)
77
81
self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
80
84
class TestFormatRegistry(TestCase):
82
86
def make_format_registry(self):
83
my_format_registry = bzrdir.BzrDirFormatRegistry()
87
my_format_registry = controldir.ControlDirFormatRegistry()
84
88
my_format_registry.register('weave', bzrdir.BzrDirFormat6,
85
89
'Pre-0.8 format. Slower and does not support checkouts or shared'
86
90
' repositories', deprecated=True)
87
91
my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
88
92
'BzrDirFormat6', 'Format registered lazily', deprecated=True)
89
my_format_registry.register_metadir('knit',
93
bzrdir.register_metadir(my_format_registry, 'knit',
90
94
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
91
95
'Format using knits',
93
97
my_format_registry.set_default('knit')
94
my_format_registry.register_metadir(
98
bzrdir.register_metadir(my_format_registry,
96
100
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
97
101
'Experimental successor to knit. Use at your own risk.',
98
102
branch_format='bzrlib.branch.BzrBranchFormat6',
99
103
experimental=True)
100
my_format_registry.register_metadir(
104
bzrdir.register_metadir(my_format_registry,
102
106
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
103
107
'Experimental successor to knit. Use at your own risk.',
172
176
bzrdir.format_registry.set_default_repository(old_default)
174
178
def test_aliases(self):
175
a_registry = bzrdir.BzrDirFormatRegistry()
179
a_registry = controldir.ControlDirFormatRegistry()
176
180
a_registry.register('weave', bzrdir.BzrDirFormat6,
177
181
'Pre-0.8 format. Slower and does not support checkouts or shared'
178
182
' repositories', deprecated=True)
787
791
self.build_tree(['tree1/subtree/file'])
788
792
sub_tree.add('file')
789
793
tree.commit('Initial commit')
794
# The following line force the orhaning to reveal bug #634470
795
tree.branch.get_config().set_user_option(
796
'bzr.transform.orphan_policy', 'move')
790
797
tree.bzrdir.destroy_workingtree()
798
# FIXME: subtree/.bzr is left here which allows the test to pass (or
799
# fail :-( ) -- vila 20100909
791
800
repo = self.make_repository('repo', shared=True,
792
801
format='dirstate-with-subtree')
793
802
repo.set_make_working_trees(False)
794
tree.bzrdir.sprout('repo/tree2')
795
self.failUnlessExists('repo/tree2/subtree')
796
self.failIfExists('repo/tree2/subtree/file')
803
# FIXME: we just deleted the workingtree and now we want to use it ????
804
# At a minimum, we should use tree.branch below (but this fails too
805
# currently) or stop calling this test 'treeless'. Specifically, I've
806
# turn the line below into an assertRaises when 'subtree/.bzr' is
807
# orphaned and sprout tries to access the branch there (which is left
808
# by bzrdir.BzrDirMeta1.destroy_workingtree when it ignores the
809
# [DeletingParent('Not deleting', u'subtree', None)] conflict). See bug
810
# #634470. -- vila 20100909
811
self.assertRaises(errors.NotBranchError,
812
tree.bzrdir.sprout, 'repo/tree2')
813
# self.failUnlessExists('repo/tree2/subtree')
814
# self.failIfExists('repo/tree2/subtree/file')
798
816
def make_foo_bar_baz(self):
799
817
foo = bzrdir.BzrDir.create_branch_convenience('foo').bzrdir
807
825
self.assertEqualBzrdirs([baz, foo, bar],
808
826
bzrdir.BzrDir.find_bzrdirs(transport))
828
def make_fake_permission_denied_transport(self, transport, paths):
829
"""Create a transport that raises PermissionDenied for some paths."""
832
raise errors.PermissionDenied(path)
834
path_filter_server = pathfilter.PathFilteringServer(transport, filter)
835
path_filter_server.start_server()
836
self.addCleanup(path_filter_server.stop_server)
837
path_filter_transport = pathfilter.PathFilteringTransport(
838
path_filter_server, '.')
839
return (path_filter_server, path_filter_transport)
841
def assertBranchUrlsEndWith(self, expect_url_suffix, actual_bzrdirs):
842
"""Check that each branch url ends with the given suffix."""
843
for actual_bzrdir in actual_bzrdirs:
844
self.assertEndsWith(actual_bzrdir.user_url, expect_url_suffix)
846
def test_find_bzrdirs_permission_denied(self):
847
foo, bar, baz = self.make_foo_bar_baz()
848
transport = get_transport(self.get_url())
849
path_filter_server, path_filter_transport = \
850
self.make_fake_permission_denied_transport(transport, ['foo'])
852
self.assertBranchUrlsEndWith('/baz/',
853
bzrdir.BzrDir.find_bzrdirs(path_filter_transport))
855
smart_transport = self.make_smart_server('.',
856
backing_server=path_filter_server)
857
self.assertBranchUrlsEndWith('/baz/',
858
bzrdir.BzrDir.find_bzrdirs(smart_transport))
810
860
def test_find_bzrdirs_list_current(self):
811
861
def list_current(transport):
812
862
return [s for s in transport.list_dir('') if s != 'baz']
856
905
self.assertEqual(bar.root_transport.base, branches[1].base)
908
class TestMissingRepoBranchesSkipped(TestCaseWithMemoryTransport):
910
def test_find_bzrdirs_missing_repo(self):
911
transport = get_transport(self.get_url())
912
arepo = self.make_repository('arepo', shared=True)
913
abranch_url = arepo.user_url + '/abranch'
914
abranch = bzrdir.BzrDir.create(abranch_url).create_branch()
915
transport.delete_tree('arepo/.bzr')
916
self.assertRaises(errors.NoRepositoryPresent,
917
branch.Branch.open, abranch_url)
918
self.make_branch('baz')
919
for actual_bzrdir in bzrdir.BzrDir.find_branches(transport):
920
self.assertEndsWith(actual_bzrdir.user_url, '/baz/')
859
923
class TestMeta1DirFormat(TestCaseWithTransport):
860
924
"""Tests specific to the meta1 dir format."""
1010
1074
def _known_formats(self):
1011
1075
return set([NotBzrDirFormat()])
1078
class NotBzrDirProber(controldir.Prober):
1014
1080
def probe_transport(self, transport):
1015
1081
"""Our format is present if the transport ends in '.not/'."""
1016
1082
if transport.has('.not'):
1030
1096
dir = format.initialize(self.get_url())
1031
1097
self.assertIsInstance(dir, NotBzrDir)
1032
1098
# now probe for it.
1033
bzrlib.bzrdir.BzrDirFormat.register_control_format(format)
1099
controldir.ControlDirFormat.register_prober(NotBzrDirProber)
1035
1101
found = bzrlib.bzrdir.BzrDirFormat.find_format(
1036
1102
get_transport(self.get_url()))
1037
1103
self.assertIsInstance(found, NotBzrDirFormat)
1039
bzrlib.bzrdir.BzrDirFormat.unregister_control_format(format)
1105
controldir.ControlDirFormat.unregister_prober(NotBzrDirProber)
1041
1107
def test_included_in_known_formats(self):
1042
bzrlib.bzrdir.BzrDirFormat.register_control_format(NotBzrDirFormat)
1108
not_format = NotBzrDirFormat()
1109
bzrlib.controldir.ControlDirFormat.register_format(not_format)
1044
1111
formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
1045
1112
for format in formats:
1113
1180
def create_transport_readonly_server(self):
1181
# We don't set the http protocol version, relying on the default
1114
1182
return http_utils.HTTPServerRedirecting()
1116
1184
def create_transport_secondary_server(self):
1185
# We don't set the http protocol version, relying on the default
1117
1186
return http_utils.HTTPServerRedirecting()
1119
1188
def setUp(self):
1351
1420
self.assertIsInstance(params, RepoInitHookParams)
1352
1421
self.assertTrue(hasattr(params, 'bzrdir'))
1353
1422
self.assertTrue(hasattr(params, 'repository'))
1424
def test_post_repo_init_hook_repr(self):
1426
bzrdir.BzrDir.hooks.install_named_hook('post_repo_init',
1427
lambda params: param_reprs.append(repr(params)), None)
1428
self.make_repository('foo')
1429
self.assertLength(1, param_reprs)
1430
param_repr = param_reprs[0]
1431
self.assertStartsWith(param_repr, '<RepoInitHookParams for ')
1434
class TestGenerateBackupName(TestCaseWithMemoryTransport):
1435
# FIXME: This may need to be unified with test_osutils.TestBackupNames or
1436
# moved to per_bzrdir or per_transport for better coverage ?
1440
super(TestGenerateBackupName, self).setUp()
1441
self._transport = get_transport(self.get_url())
1442
bzrdir.BzrDir.create(self.get_url(),
1443
possible_transports=[self._transport])
1444
self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)
1446
def test_deprecated_generate_backup_name(self):
1447
res = self.applyDeprecated(
1448
symbol_versioning.deprecated_in((2, 3, 0)),
1449
self._bzrdir.generate_backup_name, 'whatever')
1452
self.assertEqual("a.~1~", self._bzrdir._available_backup_name("a"))
1454
def test_exiting(self):
1455
self._transport.put_bytes("a.~1~", "some content")
1456
self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))