505
509
local_branch_path(branch))
506
510
self.assertEqual('', relpath)
512
def test_open_tree_or_branch(self):
513
def local_branch_path(branch):
514
return os.path.realpath(
515
urlutils.local_path_from_url(branch.base))
517
self.make_branch_and_tree('topdir')
518
tree, branch = bzrdir.BzrDir.open_tree_or_branch('topdir')
519
self.assertEqual(os.path.realpath('topdir'),
520
os.path.realpath(tree.basedir))
521
self.assertEqual(os.path.realpath('topdir'),
522
local_branch_path(branch))
523
self.assertIs(tree.bzrdir, branch.bzrdir)
524
# opening from non-local should not return the tree
525
tree, branch = bzrdir.BzrDir.open_tree_or_branch(
526
self.get_readonly_url('topdir'))
527
self.assertEqual(None, tree)
529
self.make_branch('topdir/foo')
530
tree, branch = bzrdir.BzrDir.open_tree_or_branch('topdir/foo')
531
self.assertIs(tree, None)
532
self.assertEqual(os.path.realpath('topdir/foo'),
533
local_branch_path(branch))
508
535
def test_open_from_transport(self):
509
536
# transport pointing at bzrdir should give a bzrdir with root transport
510
537
# set to the given transport
564
591
self.failUnlessExists('repo/tree2/subtree')
565
592
self.failIfExists('repo/tree2/subtree/file')
594
def make_foo_bar_baz(self):
595
foo = bzrdir.BzrDir.create_branch_convenience('foo').bzrdir
596
bar = self.make_branch('foo/bar').bzrdir
597
baz = self.make_branch('baz').bzrdir
600
def test_find_bzrdirs(self):
601
foo, bar, baz = self.make_foo_bar_baz()
602
transport = get_transport(self.get_url())
603
self.assertEqualBzrdirs([baz, foo, bar],
604
bzrdir.BzrDir.find_bzrdirs(transport))
606
def test_find_bzrdirs_list_current(self):
607
def list_current(transport):
608
return [s for s in transport.list_dir('') if s != 'baz']
610
foo, bar, baz = self.make_foo_bar_baz()
611
transport = get_transport(self.get_url())
612
self.assertEqualBzrdirs([foo, bar],
613
bzrdir.BzrDir.find_bzrdirs(transport,
614
list_current=list_current))
617
def test_find_bzrdirs_evaluate(self):
618
def evaluate(bzrdir):
620
repo = bzrdir.open_repository()
621
except NoRepositoryPresent:
622
return True, bzrdir.root_transport.base
624
return False, bzrdir.root_transport.base
626
foo, bar, baz = self.make_foo_bar_baz()
627
transport = get_transport(self.get_url())
628
self.assertEqual([baz.root_transport.base, foo.root_transport.base],
629
list(bzrdir.BzrDir.find_bzrdirs(transport,
632
def assertEqualBzrdirs(self, first, second):
634
second = list(second)
635
self.assertEqual(len(first), len(second))
636
for x, y in zip(first, second):
637
self.assertEqual(x.root_transport.base, y.root_transport.base)
639
def test_find_branches(self):
640
root = self.make_repository('', shared=True)
641
foo, bar, baz = self.make_foo_bar_baz()
642
qux = self.make_bzrdir('foo/qux')
643
transport = get_transport(self.get_url())
644
branches = bzrdir.BzrDir.find_branches(transport)
645
self.assertEqual(baz.root_transport.base, branches[0].base)
646
self.assertEqual(foo.root_transport.base, branches[1].base)
647
self.assertEqual(bar.root_transport.base, branches[2].base)
649
# ensure this works without a top-level repo
650
branches = bzrdir.BzrDir.find_branches(transport.clone('foo'))
651
self.assertEqual(foo.root_transport.base, branches[0].base)
652
self.assertEqual(bar.root_transport.base, branches[1].base)
568
655
class TestMeta1DirFormat(TestCaseWithTransport):
569
656
"""Tests specific to the meta1 dir format."""
870
957
"""Tests redirections for pycurl implementation"""
872
959
_qualifier = 'pycurl'
962
class TestDotBzrHidden(TestCaseWithTransport):
965
if sys.platform == 'win32':
966
ls = [os.environ['COMSPEC'], '/C', 'dir', '/B']
969
f = subprocess.Popen(self.ls, stdout=subprocess.PIPE,
970
stderr=subprocess.PIPE)
971
out, err = f.communicate()
972
self.assertEqual(0, f.returncode, 'Calling %s failed: %s'
974
return out.splitlines()
976
def test_dot_bzr_hidden(self):
977
if sys.platform == 'win32' and not win32utils.has_win32file:
978
raise TestSkipped('unable to make file hidden without pywin32 library')
979
b = bzrdir.BzrDir.create('.')
980
self.build_tree(['a'])
981
self.assertEquals(['a'], self.get_ls())
983
def test_dot_bzr_hidden_with_url(self):
984
if sys.platform == 'win32' and not win32utils.has_win32file:
985
raise TestSkipped('unable to make file hidden without pywin32 library')
986
b = bzrdir.BzrDir.create(urlutils.local_path_to_url('.'))
987
self.build_tree(['a'])
988
self.assertEquals(['a'], self.get_ls())