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 = _mod_transport.get_transport(self.get_url())
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 = _mod_transport.get_transport(self.get_url())
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())
745
transport = _mod_transport.get_transport(self.get_url())
744
746
opened_bzrdir = bzrdir.BzrDir.open_from_transport(transport)
745
747
self.assertEqual(transport.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())
751
transport = _mod_transport.get_transport(self.get_url())
750
752
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
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())
757
transport = _mod_transport.get_transport(self.get_url())
756
758
transport.mkdir('subdir')
757
759
transport = transport.clone('subdir')
758
760
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
823
825
def test_find_bzrdirs(self):
824
826
foo, bar, baz = self.make_foo_bar_baz()
825
transport = get_transport(self.get_url())
827
transport = _mod_transport.get_transport(self.get_url())
826
828
self.assertEqualBzrdirs([baz, foo, bar],
827
829
bzrdir.BzrDir.find_bzrdirs(transport))
847
849
def test_find_bzrdirs_permission_denied(self):
848
850
foo, bar, baz = self.make_foo_bar_baz()
849
transport = get_transport(self.get_url())
851
transport = _mod_transport.get_transport(self.get_url())
850
852
path_filter_server, path_filter_transport = \
851
853
self.make_fake_permission_denied_transport(transport, ['foo'])
852
854
# local transport
863
865
return [s for s in transport.list_dir('') if s != 'baz']
865
867
foo, bar, baz = self.make_foo_bar_baz()
866
transport = get_transport(self.get_url())
868
transport = _mod_transport.get_transport(self.get_url())
867
869
self.assertEqualBzrdirs([foo, bar],
868
870
bzrdir.BzrDir.find_bzrdirs(transport,
869
871
list_current=list_current))
878
880
return False, bzrdir.root_transport.base
880
882
foo, bar, baz = self.make_foo_bar_baz()
881
transport = get_transport(self.get_url())
883
transport = _mod_transport.get_transport(self.get_url())
882
884
self.assertEqual([baz.root_transport.base, foo.root_transport.base],
883
885
list(bzrdir.BzrDir.find_bzrdirs(transport,
884
886
evaluate=evaluate)))
894
896
root = self.make_repository('', shared=True)
895
897
foo, bar, baz = self.make_foo_bar_baz()
896
898
qux = self.make_bzrdir('foo/qux')
897
transport = get_transport(self.get_url())
899
transport = _mod_transport.get_transport(self.get_url())
898
900
branches = bzrdir.BzrDir.find_branches(transport)
899
901
self.assertEqual(baz.root_transport.base, branches[0].base)
900
902
self.assertEqual(foo.root_transport.base, branches[1].base)
909
911
class TestMissingRepoBranchesSkipped(TestCaseWithMemoryTransport):
911
913
def test_find_bzrdirs_missing_repo(self):
912
transport = get_transport(self.get_url())
914
transport = _mod_transport.get_transport(self.get_url())
913
915
arepo = self.make_repository('arepo', shared=True)
914
916
abranch_url = arepo.user_url + '/abranch'
915
917
abranch = bzrdir.BzrDir.create(abranch_url).create_branch()
1100
1102
controldir.ControlDirFormat.register_prober(NotBzrDirProber)
1102
1104
found = bzrlib.bzrdir.BzrDirFormat.find_format(
1103
get_transport(self.get_url()))
1105
_mod_transport.get_transport(self.get_url()))
1104
1106
self.assertIsInstance(found, NotBzrDirFormat)
1106
1108
controldir.ControlDirFormat.unregister_prober(NotBzrDirProber)
1446
1448
def setUp(self):
1447
1449
super(TestGenerateBackupName, self).setUp()
1448
self._transport = get_transport(self.get_url())
1450
self._transport = _mod_transport.get_transport(self.get_url())
1449
1451
bzrdir.BzrDir.create(self.get_url(),
1450
1452
possible_transports=[self._transport])
1451
1453
self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)