101
102
# recursive section - that is, it appends the branch name.
104
class SampleBranchFormat(_mod_branch.BranchFormat):
105
class SampleBranchFormat(_mod_branch.BranchFormatMetadir):
105
106
"""A sample format
107
108
this format is initializable, unsupported to aid in testing the
108
109
open and open_downlevel routines.
111
def get_format_string(self):
113
def get_format_string(cls):
112
114
"""See BzrBranchFormat.get_format_string()."""
113
115
return "Sample branch format."
115
def initialize(self, a_bzrdir, name=None, repository=None):
117
def initialize(self, a_bzrdir, name=None, repository=None,
118
append_revisions_only=None):
116
119
"""Format 4 branches cannot be created."""
117
120
t = a_bzrdir.get_branch_transport(self, name=name)
118
121
t.put_bytes('format', self.get_format_string())
121
124
def is_supported(self):
124
def open(self, transport, name=None, _found=False, ignore_fallbacks=False):
127
def open(self, transport, name=None, _found=False, ignore_fallbacks=False,
128
possible_transports=None):
125
129
return "opened branch."
130
134
SampleSupportedBranchFormatString = "Sample supported branch format."
132
136
# And the format class can then reference the constant to avoid skew.
133
class SampleSupportedBranchFormat(_mod_branch.BranchFormat):
137
class SampleSupportedBranchFormat(_mod_branch.BranchFormatMetadir):
134
138
"""A sample supported format."""
136
def get_format_string(self):
141
def get_format_string(cls):
137
142
"""See BzrBranchFormat.get_format_string()."""
138
143
return SampleSupportedBranchFormatString
140
def initialize(self, a_bzrdir, name=None):
145
def initialize(self, a_bzrdir, name=None, append_revisions_only=None):
141
146
t = a_bzrdir.get_branch_transport(self, name=name)
142
147
t.put_bytes('format', self.get_format_string())
143
148
return 'A branch'
145
def open(self, transport, name=None, _found=False, ignore_fallbacks=False):
150
def open(self, transport, name=None, _found=False, ignore_fallbacks=False,
151
possible_transports=None):
146
152
return "opened supported branch."
160
166
def initialize(self, a_bzrdir, name=None):
161
167
raise NotImplementedError(self.initialize)
163
def open(self, transport, name=None, _found=False, ignore_fallbacks=False):
169
def open(self, transport, name=None, _found=False, ignore_fallbacks=False,
170
possible_transports=None):
164
171
raise NotImplementedError(self.open)
176
183
dir = format._matchingbzrdir.initialize(url)
177
184
dir.create_repository()
178
185
format.initialize(dir)
179
found_format = _mod_branch.BranchFormat.find_format(dir)
186
found_format = _mod_branch.BranchFormatMetadir.find_format(dir)
180
187
self.assertIsInstance(found_format, format.__class__)
181
188
check_format(_mod_branch.BzrBranchFormat5(), "bar")
191
198
b = _mod_branch.Branch.open(self.get_url())
192
199
self.assertEqual(b, "opened supported branch.")
201
def test_from_string(self):
202
self.assertIsInstance(
203
SampleBranchFormat.from_string("Sample branch format."),
205
self.assertRaises(AssertionError,
206
SampleBranchFormat.from_string, "Different branch format.")
194
208
def test_find_format_not_branch(self):
195
209
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
196
210
self.assertRaises(errors.NotBranchError,
197
_mod_branch.BranchFormat.find_format,
211
_mod_branch.BranchFormatMetadir.find_format,
200
214
def test_find_format_unknown_format(self):
201
215
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
202
216
SampleBranchFormat().initialize(dir)
203
217
self.assertRaises(errors.UnknownFormatError,
204
_mod_branch.BranchFormat.find_format,
218
_mod_branch.BranchFormatMetadir.find_format,
221
def test_find_format_with_features(self):
222
tree = self.make_branch_and_tree('.', format='2a')
223
tree.branch.update_feature_flags({"name": "optional"})
224
found_format = _mod_branch.BranchFormatMetadir.find_format(tree.bzrdir)
225
self.assertIsInstance(found_format, _mod_branch.BranchFormatMetadir)
226
self.assertEquals(found_format.features.get("name"), "optional")
227
tree.branch.update_feature_flags({"name": None})
228
branch = _mod_branch.Branch.open('.')
229
self.assertEquals(branch._format.features, {})
207
231
def test_register_unregister_format(self):
208
232
# Test the deprecated format registration functions
209
233
format = SampleBranchFormat()
221
245
# but open_downlevel will work
222
246
self.assertEqual(
223
247
format.open(dir),
224
bzrdir.BzrDir.open(self.get_url()).open_branch(unsupported=True))
248
controldir.ControlDir.open(self.get_url()).open_branch(unsupported=True))
225
249
# unregister the format
226
250
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
227
251
_mod_branch.BranchFormat.unregister_format, format)
333
357
self.assertPathDoesNotExist('a/.bzr/branch/parent')
334
358
self.assertEqual('http://example.com', branch.get_parent())
335
359
branch.set_push_location('sftp://example.com')
336
config = branch.get_config()._get_branch_data_config()
337
self.assertEqual('sftp://example.com',
338
config.get_user_option('push_location'))
360
conf = branch.get_config_stack()
361
self.assertEqual('sftp://example.com', conf.get('push_location'))
339
362
branch.set_bound_location('ftp://example.com')
340
363
self.assertPathDoesNotExist('a/.bzr/branch/bound')
341
364
self.assertEqual('ftp://example.com', branch.get_bound_location())
390
413
def test_light_checkout_with_references(self):
391
414
self.do_checkout_test(lightweight=True)
393
def test_set_push(self):
394
branch = self.make_branch('source', format=self.get_format_name())
395
branch.get_config().set_user_option('push_location', 'old',
396
store=config.STORE_LOCATION)
399
warnings.append(args[0] % args[1:])
400
_warning = trace.warning
401
trace.warning = warning
403
branch.set_push_location('new')
405
trace.warning = _warning
406
self.assertEqual(warnings[0], 'Value "new" is masked by "old" from '
410
417
class TestBranch6(TestBranch67, tests.TestCaseWithTransport):
483
490
def make_branch(self, location, format=None):
484
491
if format is None:
485
format = bzrdir.format_registry.make_bzrdir('1.9')
492
format = controldir.format_registry.make_bzrdir('1.9')
486
493
format.set_branch_format(_mod_branch.BzrBranchFormat8())
487
494
return tests.TestCaseWithTransport.make_branch(
488
495
self, location, format=format)
540
547
self.assertEqual(('path3', 'location3'),
541
548
branch.get_reference_info('file-id'))
550
def _recordParentMapCalls(self, repo):
551
self._parent_map_calls = []
552
orig_get_parent_map = repo.revisions.get_parent_map
553
def get_parent_map(q):
555
self._parent_map_calls.extend([e[0] for e in q])
556
return orig_get_parent_map(q)
557
repo.revisions.get_parent_map = get_parent_map
543
560
class TestBranchReference(tests.TestCaseWithTransport):
544
561
"""Tests for the branch reference facility."""
559
576
self.assertEqual(opened_branch.base, target_branch.base)
561
578
def test_get_reference(self):
562
"""For a BranchReference, get_reference should reutrn the location."""
579
"""For a BranchReference, get_reference should return the location."""
563
580
branch = self.make_branch('target')
564
581
checkout = branch.create_checkout('checkout', lightweight=True)
565
582
reference_url = branch.bzrdir.root_transport.abspath('') + '/'
646
663
super(TestBranchOptions, self).setUp()
647
664
self.branch = self.make_branch('.')
648
self.config = self.branch.get_config()
665
self.config_stack = self.branch.get_config_stack()
650
667
def check_append_revisions_only(self, expected_value, value=None):
651
668
"""Set append_revisions_only in config and check its interpretation."""
652
669
if value is not None:
653
self.config.set_user_option('append_revisions_only', value)
670
self.config_stack.set('append_revisions_only', value)
654
671
self.assertEqual(expected_value,
655
self.branch._get_append_revisions_only())
672
self.branch.get_append_revisions_only())
657
674
def test_valid_append_revisions_only(self):
658
675
self.assertEquals(None,
659
self.config.get_user_option('append_revisions_only'))
676
self.config_stack.get('append_revisions_only'))
660
677
self.check_append_revisions_only(None)
661
678
self.check_append_revisions_only(False, 'False')
662
679
self.check_append_revisions_only(True, 'True')
674
691
self.check_append_revisions_only(None, 'not-a-bool')
675
692
self.assertLength(1, self.warnings)
676
693
self.assertEqual(
677
'Value "not-a-bool" is not a boolean for "append_revisions_only"',
694
'Value "not-a-bool" is not valid for "append_revisions_only"',
678
695
self.warnings[0])
697
def test_use_fresh_values(self):
698
copy = _mod_branch.Branch.open(self.branch.base)
701
copy.get_config_stack().set('foo', 'bar')
704
self.assertFalse(self.branch.is_locked())
705
result = self.branch.get_config_stack().get('foo')
706
# Bug: https://bugs.launchpad.net/bzr/+bug/948339
707
self.expectFailure('Unlocked branches cache their configs',
708
self.assertEqual, 'bar', result)
710
def test_set_from_config_get_from_config_stack(self):
711
self.branch.lock_write()
712
self.addCleanup(self.branch.unlock)
713
self.branch.get_config().set_user_option('foo', 'bar')
714
result = self.branch.get_config_stack().get('foo')
715
# https://bugs.launchpad.net/bzr/+bug/948344
716
self.expectFailure('BranchStack uses cache after set_user_option',
717
self.assertEqual, 'bar', result)
719
def test_set_from_config_stack_get_from_config(self):
720
self.branch.lock_write()
721
self.addCleanup(self.branch.unlock)
722
self.branch.get_config_stack().set('foo', 'bar')
723
self.assertEqual('bar',
724
self.branch.get_config().get_user_option('foo'))
726
def test_set_delays_write(self):
727
self.branch.lock_write()
728
self.addCleanup(self.branch.unlock)
729
self.branch.get_config_stack().set('foo', 'bar')
730
copy = _mod_branch.Branch.open(self.branch.base)
731
result = copy.get_config_stack().get('foo')
732
# Bug: https://bugs.launchpad.net/bzr/+bug/948339
733
self.expectFailure("Config writes are not cached.", self.assertIs,
681
737
class TestPullResult(tests.TestCase):
704
760
self.assertEqual("Now on revision 20.\n", f.getvalue())
761
self.assertEqual("Now on revision 20.\n", f.getvalue())
706
763
def test_report_unchanged(self):
707
764
r = _mod_branch.PullResult()