171
172
self.assertIs(bzrdir.format_registry.get('dirstate-with-subtree'),
172
173
bzrdir.format_registry.get('default'))
174
repository.RepositoryFormat.get_default_format().__class__,
175
repository.format_registry.get_default().__class__,
175
176
knitrepo.RepositoryFormatKnit3)
177
178
bzrdir.format_registry.set_default_repository(old_default)
254
255
# is the right format object found for a branch?
255
256
# create a branch with a few known format objects.
256
257
# this is not quite the same as
257
t = get_transport(self.get_url())
258
t = self.get_transport()
258
259
self.build_tree(["foo/", "bar/"], transport=t)
259
260
def check_format(format, url):
260
261
format.initialize(url)
261
t = get_transport(url)
262
t = _mod_transport.get_transport(url)
262
263
found_format = bzrdir.BzrDirFormat.find_format(t)
263
264
self.failUnless(isinstance(found_format, format.__class__))
264
265
check_format(bzrdir.BzrDirFormat5(), "foo")
267
268
def test_find_format_nothing_there(self):
268
269
self.assertRaises(NotBranchError,
269
270
bzrdir.BzrDirFormat.find_format,
271
_mod_transport.get_transport('.'))
272
273
def test_find_format_unknown_format(self):
273
t = get_transport(self.get_url())
274
t = self.get_transport()
275
276
t.put_bytes('.bzr/branch-format', '')
276
277
self.assertRaises(UnknownFormatError,
277
278
bzrdir.BzrDirFormat.find_format,
279
_mod_transport.get_transport('.'))
280
281
def test_register_unregister_format(self):
281
282
format = SampleBzrDirFormat()
289
290
# which bzrdir.open_containing will refuse (not supported)
290
291
self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open_containing, url)
291
292
# but open_downlevel will work
292
t = get_transport(url)
293
t = _mod_transport.get_transport(url)
293
294
self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
294
295
# unregister the format
295
296
bzrdir.BzrDirFormat.unregister_format(format)
681
682
self.assertEqual(relpath, 'baz')
683
684
def test_open_containing_from_transport(self):
684
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
685
get_transport(self.get_readonly_url('')))
686
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
687
get_transport(self.get_readonly_url('g/p/q')))
685
self.assertRaises(NotBranchError,
686
bzrdir.BzrDir.open_containing_from_transport,
687
_mod_transport.get_transport(self.get_readonly_url('')))
688
self.assertRaises(NotBranchError,
689
bzrdir.BzrDir.open_containing_from_transport,
690
_mod_transport.get_transport(self.get_readonly_url('g/p/q')))
688
691
control = bzrdir.BzrDir.create(self.get_url())
689
692
branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
690
get_transport(self.get_readonly_url('')))
693
_mod_transport.get_transport(self.get_readonly_url('')))
691
694
self.assertEqual('', relpath)
692
695
branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
693
get_transport(self.get_readonly_url('g/p/q')))
696
_mod_transport.get_transport(self.get_readonly_url('g/p/q')))
694
697
self.assertEqual('g/p/q', relpath)
696
699
def test_open_containing_tree_or_branch(self):
740
743
# transport pointing at bzrdir should give a bzrdir with root transport
741
744
# set to the given transport
742
745
control = bzrdir.BzrDir.create(self.get_url())
743
transport = get_transport(self.get_url())
744
opened_bzrdir = bzrdir.BzrDir.open_from_transport(transport)
745
self.assertEqual(transport.base, opened_bzrdir.root_transport.base)
746
t = self.get_transport()
747
opened_bzrdir = bzrdir.BzrDir.open_from_transport(t)
748
self.assertEqual(t.base, opened_bzrdir.root_transport.base)
746
749
self.assertIsInstance(opened_bzrdir, bzrdir.BzrDir)
748
751
def test_open_from_transport_no_bzrdir(self):
749
transport = get_transport(self.get_url())
750
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
752
t = self.get_transport()
753
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
753
755
def test_open_from_transport_bzrdir_in_parent(self):
754
756
control = bzrdir.BzrDir.create(self.get_url())
755
transport = get_transport(self.get_url())
756
transport.mkdir('subdir')
757
transport = transport.clone('subdir')
758
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
757
t = self.get_transport()
759
t = t.clone('subdir')
760
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
761
762
def test_sprout_recursive(self):
762
763
tree = self.make_branch_and_tree('tree1',
823
824
def test_find_bzrdirs(self):
824
825
foo, bar, baz = self.make_foo_bar_baz()
825
transport = get_transport(self.get_url())
826
self.assertEqualBzrdirs([baz, foo, bar],
827
bzrdir.BzrDir.find_bzrdirs(transport))
826
t = self.get_transport()
827
self.assertEqualBzrdirs([baz, foo, bar], bzrdir.BzrDir.find_bzrdirs(t))
829
829
def make_fake_permission_denied_transport(self, transport, paths):
830
830
"""Create a transport that raises PermissionDenied for some paths."""
847
847
def test_find_bzrdirs_permission_denied(self):
848
848
foo, bar, baz = self.make_foo_bar_baz()
849
transport = get_transport(self.get_url())
849
t = self.get_transport()
850
850
path_filter_server, path_filter_transport = \
851
self.make_fake_permission_denied_transport(transport, ['foo'])
851
self.make_fake_permission_denied_transport(t, ['foo'])
852
852
# local transport
853
853
self.assertBranchUrlsEndWith('/baz/',
854
854
bzrdir.BzrDir.find_bzrdirs(path_filter_transport))
863
863
return [s for s in transport.list_dir('') if s != 'baz']
865
865
foo, bar, baz = self.make_foo_bar_baz()
866
transport = get_transport(self.get_url())
867
self.assertEqualBzrdirs([foo, bar],
868
bzrdir.BzrDir.find_bzrdirs(transport,
869
list_current=list_current))
866
t = self.get_transport()
867
self.assertEqualBzrdirs(
869
bzrdir.BzrDir.find_bzrdirs(t, list_current=list_current))
871
871
def test_find_bzrdirs_evaluate(self):
872
872
def evaluate(bzrdir):
878
878
return False, bzrdir.root_transport.base
880
880
foo, bar, baz = self.make_foo_bar_baz()
881
transport = get_transport(self.get_url())
881
t = self.get_transport()
882
882
self.assertEqual([baz.root_transport.base, foo.root_transport.base],
883
list(bzrdir.BzrDir.find_bzrdirs(transport,
883
list(bzrdir.BzrDir.find_bzrdirs(t, evaluate=evaluate)))
886
885
def assertEqualBzrdirs(self, first, second):
887
886
first = list(first)
894
893
root = self.make_repository('', shared=True)
895
894
foo, bar, baz = self.make_foo_bar_baz()
896
895
qux = self.make_bzrdir('foo/qux')
897
transport = get_transport(self.get_url())
898
branches = bzrdir.BzrDir.find_branches(transport)
896
t = self.get_transport()
897
branches = bzrdir.BzrDir.find_branches(t)
899
898
self.assertEqual(baz.root_transport.base, branches[0].base)
900
899
self.assertEqual(foo.root_transport.base, branches[1].base)
901
900
self.assertEqual(bar.root_transport.base, branches[2].base)
903
902
# ensure this works without a top-level repo
904
branches = bzrdir.BzrDir.find_branches(transport.clone('foo'))
903
branches = bzrdir.BzrDir.find_branches(t.clone('foo'))
905
904
self.assertEqual(foo.root_transport.base, branches[0].base)
906
905
self.assertEqual(bar.root_transport.base, branches[1].base)
909
908
class TestMissingRepoBranchesSkipped(TestCaseWithMemoryTransport):
911
910
def test_find_bzrdirs_missing_repo(self):
912
transport = get_transport(self.get_url())
911
t = self.get_transport()
913
912
arepo = self.make_repository('arepo', shared=True)
914
913
abranch_url = arepo.user_url + '/abranch'
915
914
abranch = bzrdir.BzrDir.create(abranch_url).create_branch()
916
transport.delete_tree('arepo/.bzr')
915
t.delete_tree('arepo/.bzr')
917
916
self.assertRaises(errors.NoRepositoryPresent,
918
917
branch.Branch.open, abranch_url)
919
918
self.make_branch('baz')
920
for actual_bzrdir in bzrdir.BzrDir.find_branches(transport):
919
for actual_bzrdir in bzrdir.BzrDir.find_branches(t):
921
920
self.assertEndsWith(actual_bzrdir.user_url, '/baz/')
1099
1098
# now probe for it.
1100
1099
controldir.ControlDirFormat.register_prober(NotBzrDirProber)
1102
found = bzrlib.bzrdir.BzrDirFormat.find_format(
1103
get_transport(self.get_url()))
1101
found = bzrlib.bzrdir.BzrDirFormat.find_format(self.get_transport())
1104
1102
self.assertIsInstance(found, NotBzrDirFormat)
1106
1104
controldir.ControlDirFormat.unregister_prober(NotBzrDirProber)
1446
1447
def setUp(self):
1447
1448
super(TestGenerateBackupName, self).setUp()
1448
self._transport = get_transport(self.get_url())
1449
self._transport = self.get_transport()
1449
1450
bzrdir.BzrDir.create(self.get_url(),
1450
1451
possible_transports=[self._transport])
1451
1452
self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)