101
101
# recursive section - that is, it appends the branch name.
104
class SampleBranchFormat(_mod_branch.BranchFormat):
104
class SampleBranchFormat(_mod_branch.BranchFormatMetadir):
105
105
"""A sample format
107
107
this format is initializable, unsupported to aid in testing the
108
108
open and open_downlevel routines.
111
def get_format_string(self):
112
def get_format_string(cls):
112
113
"""See BzrBranchFormat.get_format_string()."""
113
114
return "Sample branch format."
122
123
def is_supported(self):
125
def open(self, transport, name=None, _found=False, ignore_fallbacks=False):
126
def open(self, transport, name=None, _found=False, ignore_fallbacks=False,
127
possible_transports=None):
126
128
return "opened branch."
131
133
SampleSupportedBranchFormatString = "Sample supported branch format."
133
135
# And the format class can then reference the constant to avoid skew.
134
class SampleSupportedBranchFormat(_mod_branch.BranchFormat):
136
class SampleSupportedBranchFormat(_mod_branch.BranchFormatMetadir):
135
137
"""A sample supported format."""
137
def get_format_string(self):
140
def get_format_string(cls):
138
141
"""See BzrBranchFormat.get_format_string()."""
139
142
return SampleSupportedBranchFormatString
143
146
t.put_bytes('format', self.get_format_string())
144
147
return 'A branch'
146
def open(self, transport, name=None, _found=False, ignore_fallbacks=False):
149
def open(self, transport, name=None, _found=False, ignore_fallbacks=False,
150
possible_transports=None):
147
151
return "opened supported branch."
161
165
def initialize(self, a_bzrdir, name=None):
162
166
raise NotImplementedError(self.initialize)
164
def open(self, transport, name=None, _found=False, ignore_fallbacks=False):
168
def open(self, transport, name=None, _found=False, ignore_fallbacks=False,
169
possible_transports=None):
165
170
raise NotImplementedError(self.open)
177
182
dir = format._matchingbzrdir.initialize(url)
178
183
dir.create_repository()
179
184
format.initialize(dir)
180
found_format = _mod_branch.BranchFormat.find_format(dir)
185
found_format = _mod_branch.BranchFormatMetadir.find_format(dir)
181
186
self.assertIsInstance(found_format, format.__class__)
182
187
check_format(_mod_branch.BzrBranchFormat5(), "bar")
192
197
b = _mod_branch.Branch.open(self.get_url())
193
198
self.assertEqual(b, "opened supported branch.")
200
def test_from_string(self):
201
self.assertIsInstance(
202
SampleBranchFormat.from_string("Sample branch format."),
204
self.assertRaises(AssertionError,
205
SampleBranchFormat.from_string, "Different branch format.")
195
207
def test_find_format_not_branch(self):
196
208
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
197
209
self.assertRaises(errors.NotBranchError,
198
_mod_branch.BranchFormat.find_format,
210
_mod_branch.BranchFormatMetadir.find_format,
201
213
def test_find_format_unknown_format(self):
202
214
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
203
215
SampleBranchFormat().initialize(dir)
204
216
self.assertRaises(errors.UnknownFormatError,
205
_mod_branch.BranchFormat.find_format,
217
_mod_branch.BranchFormatMetadir.find_format,
220
def test_find_format_with_features(self):
221
tree = self.make_branch_and_tree('.', format='2a')
222
tree.branch.update_feature_flags({"name": "optional"})
223
found_format = _mod_branch.BranchFormatMetadir.find_format(tree.bzrdir)
224
self.assertIsInstance(found_format, _mod_branch.BranchFormatMetadir)
225
self.assertEquals(found_format.features.get("name"), "optional")
226
tree.branch.update_feature_flags({"name": None})
227
branch = _mod_branch.Branch.open('.')
228
self.assertEquals(branch._format.features, {})
208
230
def test_register_unregister_format(self):
209
231
# Test the deprecated format registration functions
210
232
format = SampleBranchFormat()
391
413
def test_light_checkout_with_references(self):
392
414
self.do_checkout_test(lightweight=True)
394
def test_set_push(self):
395
branch = self.make_branch('source', format=self.get_format_name())
396
branch.get_config().set_user_option('push_location', 'old',
397
store=config.STORE_LOCATION)
400
warnings.append(args[0] % args[1:])
401
_warning = trace.warning
402
trace.warning = warning
404
branch.set_push_location('new')
406
trace.warning = _warning
407
self.assertEqual(warnings[0], 'Value "new" is masked by "old" from '
411
417
class TestBranch6(TestBranch67, tests.TestCaseWithTransport):
657
663
super(TestBranchOptions, self).setUp()
658
664
self.branch = self.make_branch('.')
659
self.config = self.branch.get_config()
665
self.config_stack = self.branch.get_config_stack()
661
667
def check_append_revisions_only(self, expected_value, value=None):
662
668
"""Set append_revisions_only in config and check its interpretation."""
663
669
if value is not None:
664
self.config.set_user_option('append_revisions_only', value)
670
self.config_stack.set('append_revisions_only', value)
665
671
self.assertEqual(expected_value,
666
672
self.branch.get_append_revisions_only())
668
674
def test_valid_append_revisions_only(self):
669
675
self.assertEquals(None,
670
self.config.get_user_option('append_revisions_only'))
676
self.config_stack.get('append_revisions_only'))
671
677
self.check_append_revisions_only(None)
672
678
self.check_append_revisions_only(False, 'False')
673
679
self.check_append_revisions_only(True, 'True')
685
691
self.check_append_revisions_only(None, 'not-a-bool')
686
692
self.assertLength(1, self.warnings)
687
693
self.assertEqual(
688
'Value "not-a-bool" is not a boolean for "append_revisions_only"',
694
'Value "not-a-bool" is not valid for "append_revisions_only"',
689
695
self.warnings[0])
715
721
self.assertEqual("Now on revision 20.\n", f.getvalue())
722
self.assertEqual("Now on revision 20.\n", f.getvalue())
717
724
def test_report_unchanged(self):
718
725
r = _mod_branch.PullResult()