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