132
130
my_format_registry = self.make_format_registry()
133
131
self.assertEqual('Format registered lazily',
134
132
my_format_registry.get_help('lazy'))
135
self.assertEqual('Format using knits',
133
self.assertEqual('Format using knits',
136
134
my_format_registry.get_help('knit'))
137
self.assertEqual('Format using knits',
135
self.assertEqual('Format using knits',
138
136
my_format_registry.get_help('default'))
139
137
self.assertEqual('Pre-0.8 format. Slower and does not support'
140
' checkouts or shared repositories',
138
' checkouts or shared repositories',
141
139
my_format_registry.get_help('weave'))
143
141
def test_help_topic(self):
144
142
topics = help_topics.HelpTopicRegistry()
145
topics.register('formats', self.make_format_registry().help_topic,
147
topic = topics.get_detail('formats')
148
new, rest = topic.split('Experimental formats')
143
registry = self.make_format_registry()
144
topics.register('current-formats', registry.help_topic,
146
topics.register('other-formats', registry.help_topic,
148
new = topics.get_detail('current-formats')
149
rest = topics.get_detail('other-formats')
149
150
experimental, deprecated = rest.split('Deprecated formats')
150
self.assertContainsRe(new, 'These formats can be used')
151
self.assertContainsRe(new,
151
self.assertContainsRe(new, 'formats-help')
152
self.assertContainsRe(new,
152
153
':knit:\n \(native\) \(default\) Format using knits\n')
153
self.assertContainsRe(experimental,
154
self.assertContainsRe(experimental,
154
155
':branch6:\n \(native\) Experimental successor to knit')
155
self.assertContainsRe(deprecated,
156
self.assertContainsRe(deprecated,
156
157
':lazy:\n \(native\) Format registered lazily\n')
157
158
self.assertNotContainsRe(new, 'hidden')
271
291
# now open_downlevel should fail too.
272
292
self.assertRaises(UnknownFormatError, bzrdir.BzrDir.open_unsupported, url)
274
def test_create_repository_deprecated(self):
275
# new interface is to make the bzrdir, then a repository within that.
276
format = SampleBzrDirFormat()
277
repo = self.applyDeprecated(zero_ninetyone,
278
bzrdir.BzrDir.create_repository,
279
self.get_url(), format=format)
280
self.assertEqual('A repository', repo)
282
def test_create_repository_shared(self):
283
# new interface is to make the bzrdir, then a repository within that.
284
old_format = bzrdir.BzrDirFormat.get_default_format()
285
repo = self.applyDeprecated(zero_ninetyone,
286
bzrdir.BzrDir.create_repository,
288
self.assertTrue(repo.is_shared())
290
def test_create_repository_nonshared(self):
291
# new interface is to make the bzrdir, then a repository within that.
292
old_format = bzrdir.BzrDirFormat.get_default_format()
293
repo = self.applyDeprecated(zero_ninetyone,
294
bzrdir.BzrDir.create_repository,
296
self.assertFalse(repo.is_shared())
298
def test_create_repository_under_shared(self):
299
# an explicit create_repository always does so.
300
# we trust the format is right from the 'create_repository test'
301
# new interface is to make the bzrdir, then a repository within that.
302
format = bzrdir.format_registry.make_bzrdir('knit')
303
self.make_repository('.', shared=True, format=format)
304
repo = self.applyDeprecated(zero_ninetyone,
305
bzrdir.BzrDir.create_repository,
306
self.get_url('child'),
308
self.assertTrue(isinstance(repo, repository.Repository))
309
self.assertTrue(repo.bzrdir.root_transport.base.endswith('child/'))
311
294
def test_create_branch_and_repo_uses_default(self):
312
295
format = SampleBzrDirFormat()
313
296
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url(),
444
427
branch.bzrdir.open_workingtree()
430
class TestRepositoryAcquisitionPolicy(TestCaseWithTransport):
432
def test_acquire_repository_standalone(self):
433
"""The default acquisition policy should create a standalone branch."""
434
my_bzrdir = self.make_bzrdir('.')
435
repo_policy = my_bzrdir.determine_repository_policy()
436
repo, is_new = repo_policy.acquire_repository()
437
self.assertEqual(repo.bzrdir.root_transport.base,
438
my_bzrdir.root_transport.base)
439
self.assertFalse(repo.is_shared())
441
def test_determine_stacking_policy(self):
442
parent_bzrdir = self.make_bzrdir('.')
443
child_bzrdir = self.make_bzrdir('child')
444
parent_bzrdir.get_config().set_default_stack_on('http://example.org')
445
repo_policy = child_bzrdir.determine_repository_policy()
446
self.assertEqual('http://example.org', repo_policy._stack_on)
448
def test_determine_stacking_policy_relative(self):
449
parent_bzrdir = self.make_bzrdir('.')
450
child_bzrdir = self.make_bzrdir('child')
451
parent_bzrdir.get_config().set_default_stack_on('child2')
452
repo_policy = child_bzrdir.determine_repository_policy()
453
self.assertEqual('child2', repo_policy._stack_on)
454
self.assertEqual(parent_bzrdir.root_transport.base,
455
repo_policy._stack_on_pwd)
457
def prepare_default_stacking(self, child_format='1.6'):
458
parent_bzrdir = self.make_bzrdir('.')
459
child_branch = self.make_branch('child', format=child_format)
460
parent_bzrdir.get_config().set_default_stack_on(child_branch.base)
461
new_child_transport = parent_bzrdir.transport.clone('child2')
462
return child_branch, new_child_transport
464
def test_clone_on_transport_obeys_stacking_policy(self):
465
child_branch, new_child_transport = self.prepare_default_stacking()
466
new_child = child_branch.bzrdir.clone_on_transport(new_child_transport)
467
self.assertEqual(child_branch.base,
468
new_child.open_branch().get_stacked_on_url())
470
def test_default_stacking_with_stackable_branch_unstackable_repo(self):
471
# Make stackable source branch with an unstackable repo format.
472
source_bzrdir = self.make_bzrdir('source')
473
pack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
474
source_branch = bzrlib.branch.BzrBranchFormat7().initialize(
476
# Make a directory with a default stacking policy
477
parent_bzrdir = self.make_bzrdir('parent')
478
stacked_on = self.make_branch('parent/stacked-on', format='pack-0.92')
479
parent_bzrdir.get_config().set_default_stack_on(stacked_on.base)
480
# Clone source into directory
481
target = source_bzrdir.clone(self.get_url('parent/target'))
483
def test_sprout_obeys_stacking_policy(self):
484
child_branch, new_child_transport = self.prepare_default_stacking()
485
new_child = child_branch.bzrdir.sprout(new_child_transport.base)
486
self.assertEqual(child_branch.base,
487
new_child.open_branch().get_stacked_on_url())
489
def test_clone_ignores_policy_for_unsupported_formats(self):
490
child_branch, new_child_transport = self.prepare_default_stacking(
491
child_format='pack-0.92')
492
new_child = child_branch.bzrdir.clone_on_transport(new_child_transport)
493
self.assertRaises(errors.UnstackableBranchFormat,
494
new_child.open_branch().get_stacked_on_url)
496
def test_sprout_ignores_policy_for_unsupported_formats(self):
497
child_branch, new_child_transport = self.prepare_default_stacking(
498
child_format='pack-0.92')
499
new_child = child_branch.bzrdir.sprout(new_child_transport.base)
500
self.assertRaises(errors.UnstackableBranchFormat,
501
new_child.open_branch().get_stacked_on_url)
503
def test_sprout_upgrades_format_if_stacked_specified(self):
504
child_branch, new_child_transport = self.prepare_default_stacking(
505
child_format='pack-0.92')
506
new_child = child_branch.bzrdir.sprout(new_child_transport.base,
508
self.assertEqual(child_branch.bzrdir.root_transport.base,
509
new_child.open_branch().get_stacked_on_url())
510
repo = new_child.open_repository()
511
self.assertTrue(repo._format.supports_external_lookups)
512
self.assertFalse(repo.supports_rich_root())
514
def test_clone_on_transport_upgrades_format_if_stacked_on_specified(self):
515
child_branch, new_child_transport = self.prepare_default_stacking(
516
child_format='pack-0.92')
517
new_child = child_branch.bzrdir.clone_on_transport(new_child_transport,
518
stacked_on=child_branch.bzrdir.root_transport.base)
519
self.assertEqual(child_branch.bzrdir.root_transport.base,
520
new_child.open_branch().get_stacked_on_url())
521
repo = new_child.open_repository()
522
self.assertTrue(repo._format.supports_external_lookups)
523
self.assertFalse(repo.supports_rich_root())
525
def test_sprout_upgrades_to_rich_root_format_if_needed(self):
526
child_branch, new_child_transport = self.prepare_default_stacking(
527
child_format='rich-root-pack')
528
new_child = child_branch.bzrdir.sprout(new_child_transport.base,
530
repo = new_child.open_repository()
531
self.assertTrue(repo._format.supports_external_lookups)
532
self.assertTrue(repo.supports_rich_root())
534
def test_add_fallback_repo_handles_absolute_urls(self):
535
stack_on = self.make_branch('stack_on', format='1.6')
536
repo = self.make_repository('repo', format='1.6')
537
policy = bzrdir.UseExistingRepository(repo, stack_on.base)
538
policy._add_fallback(repo)
540
def test_add_fallback_repo_handles_relative_urls(self):
541
stack_on = self.make_branch('stack_on', format='1.6')
542
repo = self.make_repository('repo', format='1.6')
543
policy = bzrdir.UseExistingRepository(repo, '.', stack_on.base)
544
policy._add_fallback(repo)
546
def test_configure_relative_branch_stacking_url(self):
547
stack_on = self.make_branch('stack_on', format='1.6')
548
stacked = self.make_branch('stack_on/stacked', format='1.6')
549
policy = bzrdir.UseExistingRepository(stacked.repository,
551
policy.configure_branch(stacked)
552
self.assertEqual('..', stacked.get_stacked_on_url())
554
def test_relative_branch_stacking_to_absolute(self):
555
stack_on = self.make_branch('stack_on', format='1.6')
556
stacked = self.make_branch('stack_on/stacked', format='1.6')
557
policy = bzrdir.UseExistingRepository(stacked.repository,
558
'.', self.get_readonly_url('stack_on'))
559
policy.configure_branch(stacked)
560
self.assertEqual(self.get_readonly_url('stack_on'),
561
stacked.get_stacked_on_url())
447
564
class ChrootedTests(TestCaseWithTransport):
448
565
"""A support class that provides readonly urls outside the local namespace.
468
588
branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url('g/p/q'))
469
589
self.assertEqual('g/p/q', relpath)
591
def test_open_containing_tree_branch_or_repository_empty(self):
592
self.assertRaises(errors.NotBranchError,
593
bzrdir.BzrDir.open_containing_tree_branch_or_repository,
594
self.get_readonly_url(''))
596
def test_open_containing_tree_branch_or_repository_all(self):
597
self.make_branch_and_tree('topdir')
598
tree, branch, repo, relpath = \
599
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
601
self.assertEqual(os.path.realpath('topdir'),
602
os.path.realpath(tree.basedir))
603
self.assertEqual(os.path.realpath('topdir'),
604
self.local_branch_path(branch))
606
osutils.realpath(os.path.join('topdir', '.bzr', 'repository')),
607
repo.bzrdir.transport.local_abspath('repository'))
608
self.assertEqual(relpath, 'foo')
610
def test_open_containing_tree_branch_or_repository_no_tree(self):
611
self.make_branch('branch')
612
tree, branch, repo, relpath = \
613
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
615
self.assertEqual(tree, None)
616
self.assertEqual(os.path.realpath('branch'),
617
self.local_branch_path(branch))
619
osutils.realpath(os.path.join('branch', '.bzr', 'repository')),
620
repo.bzrdir.transport.local_abspath('repository'))
621
self.assertEqual(relpath, 'foo')
623
def test_open_containing_tree_branch_or_repository_repo(self):
624
self.make_repository('repo')
625
tree, branch, repo, relpath = \
626
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
628
self.assertEqual(tree, None)
629
self.assertEqual(branch, None)
631
osutils.realpath(os.path.join('repo', '.bzr', 'repository')),
632
repo.bzrdir.transport.local_abspath('repository'))
633
self.assertEqual(relpath, '')
635
def test_open_containing_tree_branch_or_repository_shared_repo(self):
636
self.make_repository('shared', shared=True)
637
bzrdir.BzrDir.create_branch_convenience('shared/branch',
638
force_new_tree=False)
639
tree, branch, repo, relpath = \
640
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
642
self.assertEqual(tree, None)
643
self.assertEqual(os.path.realpath('shared/branch'),
644
self.local_branch_path(branch))
646
osutils.realpath(os.path.join('shared', '.bzr', 'repository')),
647
repo.bzrdir.transport.local_abspath('repository'))
648
self.assertEqual(relpath, '')
650
def test_open_containing_tree_branch_or_repository_branch_subdir(self):
651
self.make_branch_and_tree('foo')
652
self.build_tree(['foo/bar/'])
653
tree, branch, repo, relpath = \
654
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
656
self.assertEqual(os.path.realpath('foo'),
657
os.path.realpath(tree.basedir))
658
self.assertEqual(os.path.realpath('foo'),
659
self.local_branch_path(branch))
661
osutils.realpath(os.path.join('foo', '.bzr', 'repository')),
662
repo.bzrdir.transport.local_abspath('repository'))
663
self.assertEqual(relpath, 'bar')
665
def test_open_containing_tree_branch_or_repository_repo_subdir(self):
666
self.make_repository('bar')
667
self.build_tree(['bar/baz/'])
668
tree, branch, repo, relpath = \
669
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
671
self.assertEqual(tree, None)
672
self.assertEqual(branch, None)
674
osutils.realpath(os.path.join('bar', '.bzr', 'repository')),
675
repo.bzrdir.transport.local_abspath('repository'))
676
self.assertEqual(relpath, 'baz')
471
678
def test_open_containing_from_transport(self):
472
679
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
473
680
get_transport(self.get_readonly_url('')))
696
900
def test_needs_conversion_different_working_tree(self):
697
901
# meta1dirs need an conversion if any element is not the default.
698
old_format = bzrdir.BzrDirFormat.get_default_format()
700
new_default = bzrdir.format_registry.make_bzrdir('dirstate')
701
bzrdir.BzrDirFormat._set_default_format(new_default)
703
tree = self.make_branch_and_tree('tree', format='knit')
704
self.assertTrue(tree.bzrdir.needs_format_conversion())
706
bzrdir.BzrDirFormat._set_default_format(old_format)
902
new_format = bzrdir.format_registry.make_bzrdir('dirstate')
903
tree = self.make_branch_and_tree('tree', format='knit')
904
self.assertTrue(tree.bzrdir.needs_format_conversion(
907
def test_initialize_on_format_uses_smart_transport(self):
908
self.setup_smart_server_with_call_log()
909
new_format = bzrdir.format_registry.make_bzrdir('dirstate')
910
transport = self.get_transport('target')
911
transport.ensure_base()
912
self.reset_smart_call_log()
913
instance = new_format.initialize_on_transport(transport)
914
self.assertIsInstance(instance, remote.RemoteBzrDir)
915
rpc_count = len(self.hpss_calls)
916
# This figure represent the amount of work to perform this use case. It
917
# is entirely ok to reduce this number if a test fails due to rpc_count
918
# being too low. If rpc_count increases, more network roundtrips have
919
# become necessary for this use case. Please do not adjust this number
920
# upwards without agreement from bzr's network support maintainers.
921
self.assertEqual(2, rpc_count)
709
924
class TestFormat5(TestCaseWithTransport):
710
925
"""Tests specific to the version 5 bzrdir format."""
712
927
def test_same_lockfiles_between_tree_repo_branch(self):
713
# this checks that only a single lockfiles instance is created
928
# this checks that only a single lockfiles instance is created
714
929
# for format 5 objects
715
930
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
716
931
def check_dir_components_use_same_lock(dir):
723
938
# and if we open it normally.
724
939
dir = bzrdir.BzrDir.open(self.get_url())
725
940
check_dir_components_use_same_lock(dir)
727
942
def test_can_convert(self):
728
943
# format 5 dirs are convertable
729
944
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
730
945
self.assertTrue(dir.can_convert_format())
732
947
def test_needs_conversion(self):
733
# format 5 dirs need a conversion if they are not the default.
734
# and they start of not the default.
735
old_format = bzrdir.BzrDirFormat.get_default_format()
736
bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
738
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
739
self.assertFalse(dir.needs_format_conversion())
741
bzrdir.BzrDirFormat._set_default_format(old_format)
742
self.assertTrue(dir.needs_format_conversion())
948
# format 5 dirs need a conversion if they are not the default,
950
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
951
# don't need to convert it to itself
952
self.assertFalse(dir.needs_format_conversion(bzrdir.BzrDirFormat5()))
953
# do need to convert it to the current default
954
self.assertTrue(dir.needs_format_conversion(
955
bzrdir.BzrDirFormat.get_default_format()))
745
958
class TestFormat6(TestCaseWithTransport):
746
959
"""Tests specific to the version 6 bzrdir format."""
748
961
def test_same_lockfiles_between_tree_repo_branch(self):
749
# this checks that only a single lockfiles instance is created
962
# this checks that only a single lockfiles instance is created
750
963
# for format 6 objects
751
964
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
752
965
def check_dir_components_use_same_lock(dir):
890
1099
workingtree.WorkingTreeFormat3)
893
class TestHTTPRedirectionLoop(object):
894
"""Test redirection loop between two http servers.
1102
class TestHTTPRedirections(object):
1103
"""Test redirection between two http servers.
896
1105
This MUST be used by daughter classes that also inherit from
897
1106
TestCaseWithTwoWebservers.
899
1108
We can't inherit directly from TestCaseWithTwoWebservers or the
900
1109
test framework will try to create an instance which cannot
901
run, its implementation being incomplete.
1110
run, its implementation being incomplete.
904
# Should be defined by daughter classes to ensure redirection
905
# still use the same transport implementation (not currently
906
# enforced as it's a bit tricky to get right (see the FIXME
907
# in BzrDir.open_from_transport for the unique use case so
911
1113
def create_transport_readonly_server(self):
912
return HTTPServerRedirecting()
1114
return http_utils.HTTPServerRedirecting()
914
1116
def create_transport_secondary_server(self):
915
return HTTPServerRedirecting()
1117
return http_utils.HTTPServerRedirecting()
917
1119
def setUp(self):
918
# Both servers redirect to each server creating a loop
919
super(TestHTTPRedirectionLoop, self).setUp()
1120
super(TestHTTPRedirections, self).setUp()
920
1121
# The redirections will point to the new server
921
1122
self.new_server = self.get_readonly_server()
922
1123
# The requests to the old server will be redirected
923
1124
self.old_server = self.get_secondary_server()
924
1125
# Configure the redirections
925
1126
self.old_server.redirect_to(self.new_server.host, self.new_server.port)
1128
def test_loop(self):
1129
# Both servers redirect to each other creating a loop
926
1130
self.new_server.redirect_to(self.old_server.host, self.old_server.port)
928
def _qualified_url(self, host, port):
929
return 'http+%s://%s:%s' % (self._qualifier, host, port)
932
1131
# Starting from either server should loop
933
old_url = self._qualified_url(self.old_server.host,
1132
old_url = self._qualified_url(self.old_server.host,
934
1133
self.old_server.port)
935
1134
oldt = self._transport(old_url)
936
1135
self.assertRaises(errors.NotBranchError,
937
1136
bzrdir.BzrDir.open_from_transport, oldt)
938
new_url = self._qualified_url(self.new_server.host,
1137
new_url = self._qualified_url(self.new_server.host,
939
1138
self.new_server.port)
940
1139
newt = self._transport(new_url)
941
1140
self.assertRaises(errors.NotBranchError,
942
1141
bzrdir.BzrDir.open_from_transport, newt)
945
class TestHTTPRedirections_urllib(TestHTTPRedirectionLoop,
946
TestCaseWithTwoWebservers):
1143
def test_qualifier_preserved(self):
1144
wt = self.make_branch_and_tree('branch')
1145
old_url = self._qualified_url(self.old_server.host,
1146
self.old_server.port)
1147
start = self._transport(old_url).clone('branch')
1148
bdir = bzrdir.BzrDir.open_from_transport(start)
1149
# Redirection should preserve the qualifier, hence the transport class
1151
self.assertIsInstance(bdir.root_transport, type(start))
1154
class TestHTTPRedirections_urllib(TestHTTPRedirections,
1155
http_utils.TestCaseWithTwoWebservers):
947
1156
"""Tests redirections for urllib implementation"""
949
_qualifier = 'urllib'
950
1158
_transport = HttpTransport_urllib
1160
def _qualified_url(self, host, port):
1161
result = 'http+urllib://%s:%s' % (host, port)
1162
self.permit_url(result)
954
1167
class TestHTTPRedirections_pycurl(TestWithTransport_pycurl,
955
TestHTTPRedirectionLoop,
956
TestCaseWithTwoWebservers):
1168
TestHTTPRedirections,
1169
http_utils.TestCaseWithTwoWebservers):
957
1170
"""Tests redirections for pycurl implementation"""
959
_qualifier = 'pycurl'
1172
def _qualified_url(self, host, port):
1173
result = 'http+pycurl://%s:%s' % (host, port)
1174
self.permit_url(result)
1178
class TestHTTPRedirections_nosmart(TestHTTPRedirections,
1179
http_utils.TestCaseWithTwoWebservers):
1180
"""Tests redirections for the nosmart decorator"""
1182
_transport = NoSmartTransportDecorator
1184
def _qualified_url(self, host, port):
1185
result = 'nosmart+http://%s:%s' % (host, port)
1186
self.permit_url(result)
1190
class TestHTTPRedirections_readonly(TestHTTPRedirections,
1191
http_utils.TestCaseWithTwoWebservers):
1192
"""Tests redirections for readonly decoratror"""
1194
_transport = ReadonlyTransportDecorator
1196
def _qualified_url(self, host, port):
1197
result = 'readonly+http://%s:%s' % (host, port)
1198
self.permit_url(result)
962
1202
class TestDotBzrHidden(TestCaseWithTransport):
986
1226
b = bzrdir.BzrDir.create(urlutils.local_path_to_url('.'))
987
1227
self.build_tree(['a'])
988
1228
self.assertEquals(['a'], self.get_ls())
1231
class _TestBzrDirFormat(bzrdir.BzrDirMetaFormat1):
1232
"""Test BzrDirFormat implementation for TestBzrDirSprout."""
1234
def _open(self, transport):
1235
return _TestBzrDir(transport, self)
1238
class _TestBzrDir(bzrdir.BzrDirMeta1):
1239
"""Test BzrDir implementation for TestBzrDirSprout.
1241
When created a _TestBzrDir already has repository and a branch. The branch
1242
is a test double as well.
1245
def __init__(self, *args, **kwargs):
1246
super(_TestBzrDir, self).__init__(*args, **kwargs)
1247
self.test_branch = _TestBranch()
1248
self.test_branch.repository = self.create_repository()
1250
def open_branch(self, unsupported=False):
1251
return self.test_branch
1253
def cloning_metadir(self, require_stacking=False):
1254
return _TestBzrDirFormat()
1257
class _TestBranchFormat(bzrlib.branch.BranchFormat):
1258
"""Test Branch format for TestBzrDirSprout."""
1261
class _TestBranch(bzrlib.branch.Branch):
1262
"""Test Branch implementation for TestBzrDirSprout."""
1264
def __init__(self, *args, **kwargs):
1265
self._format = _TestBranchFormat()
1266
super(_TestBranch, self).__init__(*args, **kwargs)
1270
def sprout(self, *args, **kwargs):
1271
self.calls.append('sprout')
1272
return _TestBranch()
1274
def copy_content_into(self, destination, revision_id=None):
1275
self.calls.append('copy_content_into')
1277
def get_parent(self):
1280
def set_parent(self, parent):
1281
self._parent = parent
1284
class TestBzrDirSprout(TestCaseWithMemoryTransport):
1286
def test_sprout_uses_branch_sprout(self):
1287
"""BzrDir.sprout calls Branch.sprout.
1289
Usually, BzrDir.sprout should delegate to the branch's sprout method
1290
for part of the work. This allows the source branch to control the
1291
choice of format for the new branch.
1293
There are exceptions, but this tests avoids them:
1294
- if there's no branch in the source bzrdir,
1295
- or if the stacking has been requested and the format needs to be
1296
overridden to satisfy that.
1298
# Make an instrumented bzrdir.
1299
t = self.get_transport('source')
1301
source_bzrdir = _TestBzrDirFormat().initialize_on_transport(t)
1302
# The instrumented bzrdir has a test_branch attribute that logs calls
1303
# made to the branch contained in that bzrdir. Initially the test
1304
# branch exists but no calls have been made to it.
1305
self.assertEqual([], source_bzrdir.test_branch.calls)
1308
target_url = self.get_url('target')
1309
result = source_bzrdir.sprout(target_url, recurse='no')
1311
# The bzrdir called the branch's sprout method.
1312
self.assertSubset(['sprout'], source_bzrdir.test_branch.calls)
1314
def test_sprout_parent(self):
1315
grandparent_tree = self.make_branch('grandparent')
1316
parent = grandparent_tree.bzrdir.sprout('parent').open_branch()
1317
branch_tree = parent.bzrdir.sprout('branch').open_branch()
1318
self.assertContainsRe(branch_tree.get_parent(), '/parent/$')
1321
class TestBzrDirHooks(TestCaseWithMemoryTransport):
1323
def test_pre_open_called(self):
1325
bzrdir.BzrDir.hooks.install_named_hook('pre_open', calls.append, None)
1326
transport = self.get_transport('foo')
1327
url = transport.base
1328
self.assertRaises(errors.NotBranchError, bzrdir.BzrDir.open, url)
1329
self.assertEqual([transport.base], [t.base for t in calls])
1331
def test_pre_open_actual_exceptions_raised(self):
1333
def fail_once(transport):
1336
raise errors.BzrError("fail")
1337
bzrdir.BzrDir.hooks.install_named_hook('pre_open', fail_once, None)
1338
transport = self.get_transport('foo')
1339
url = transport.base
1340
err = self.assertRaises(errors.BzrError, bzrdir.BzrDir.open, url)
1341
self.assertEqual('fail', err._preformatted_string)