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