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