1
# Copyright (C) 2006-2012 Canonical Ltd
1
# Copyright (C) 2006-2011 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
101
101
# recursive section - that is, it appends the branch name.
104
class SampleBranchFormat(_mod_branch.BranchFormatMetadir):
104
class SampleBranchFormat(_mod_branch.BranchFormat):
105
105
"""A sample format
107
107
this format is initializable, unsupported to aid in testing the
108
108
open and open_downlevel routines.
112
def get_format_string(cls):
111
def get_format_string(self):
113
112
"""See BzrBranchFormat.get_format_string()."""
114
113
return "Sample branch format."
133
132
SampleSupportedBranchFormatString = "Sample supported branch format."
135
134
# And the format class can then reference the constant to avoid skew.
136
class SampleSupportedBranchFormat(_mod_branch.BranchFormatMetadir):
135
class SampleSupportedBranchFormat(_mod_branch.BranchFormat):
137
136
"""A sample supported format."""
140
def get_format_string(cls):
138
def get_format_string(self):
141
139
"""See BzrBranchFormat.get_format_string()."""
142
140
return SampleSupportedBranchFormatString
182
180
dir = format._matchingbzrdir.initialize(url)
183
181
dir.create_repository()
184
182
format.initialize(dir)
185
found_format = _mod_branch.BranchFormatMetadir.find_format(dir)
183
found_format = _mod_branch.BranchFormat.find_format(dir)
186
184
self.assertIsInstance(found_format, format.__class__)
187
185
check_format(_mod_branch.BzrBranchFormat5(), "bar")
197
195
b = _mod_branch.Branch.open(self.get_url())
198
196
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.")
207
198
def test_find_format_not_branch(self):
208
199
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
209
200
self.assertRaises(errors.NotBranchError,
210
_mod_branch.BranchFormatMetadir.find_format,
201
_mod_branch.BranchFormat.find_format,
213
204
def test_find_format_unknown_format(self):
214
205
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
215
206
SampleBranchFormat().initialize(dir)
216
207
self.assertRaises(errors.UnknownFormatError,
217
_mod_branch.BranchFormatMetadir.find_format,
208
_mod_branch.BranchFormat.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, {})
230
211
def test_register_unregister_format(self):
231
212
# Test the deprecated format registration functions
232
213
format = SampleBranchFormat()
356
337
self.assertPathDoesNotExist('a/.bzr/branch/parent')
357
338
self.assertEqual('http://example.com', branch.get_parent())
358
339
branch.set_push_location('sftp://example.com')
359
conf = branch.get_config_stack()
360
self.assertEqual('sftp://example.com', conf.get('push_location'))
340
config = branch.get_config()._get_branch_data_config()
341
self.assertEqual('sftp://example.com',
342
config.get_user_option('push_location'))
361
343
branch.set_bound_location('ftp://example.com')
362
344
self.assertPathDoesNotExist('a/.bzr/branch/bound')
363
345
self.assertEqual('ftp://example.com', branch.get_bound_location())
412
394
def test_light_checkout_with_references(self):
413
395
self.do_checkout_test(lightweight=True)
397
def test_set_push(self):
398
branch = self.make_branch('source', format=self.get_format_name())
399
branch.get_config().set_user_option('push_location', 'old',
400
store=config.STORE_LOCATION)
403
warnings.append(args[0] % args[1:])
404
_warning = trace.warning
405
trace.warning = warning
407
branch.set_push_location('new')
409
trace.warning = _warning
410
self.assertEqual(warnings[0], 'Value "new" is masked by "old" from '
416
414
class TestBranch6(TestBranch67, tests.TestCaseWithTransport):
575
573
self.assertEqual(opened_branch.base, target_branch.base)
577
575
def test_get_reference(self):
578
"""For a BranchReference, get_reference should return the location."""
576
"""For a BranchReference, get_reference should reutrn the location."""
579
577
branch = self.make_branch('target')
580
578
checkout = branch.create_checkout('checkout', lightweight=True)
581
579
reference_url = branch.bzrdir.root_transport.abspath('') + '/'
662
660
super(TestBranchOptions, self).setUp()
663
661
self.branch = self.make_branch('.')
664
self.config_stack = self.branch.get_config_stack()
662
self.config = self.branch.get_config()
666
664
def check_append_revisions_only(self, expected_value, value=None):
667
665
"""Set append_revisions_only in config and check its interpretation."""
668
666
if value is not None:
669
self.config_stack.set('append_revisions_only', value)
667
self.config.set_user_option('append_revisions_only', value)
670
668
self.assertEqual(expected_value,
671
669
self.branch.get_append_revisions_only())
673
671
def test_valid_append_revisions_only(self):
674
672
self.assertEquals(None,
675
self.config_stack.get('append_revisions_only'))
673
self.config.get_user_option('append_revisions_only'))
676
674
self.check_append_revisions_only(None)
677
675
self.check_append_revisions_only(False, 'False')
678
676
self.check_append_revisions_only(True, 'True')
690
688
self.check_append_revisions_only(None, 'not-a-bool')
691
689
self.assertLength(1, self.warnings)
692
690
self.assertEqual(
693
'Value "not-a-bool" is not valid for "append_revisions_only"',
691
'Value "not-a-bool" is not a boolean for "append_revisions_only"',
694
692
self.warnings[0])
720
718
self.assertEqual("Now on revision 20.\n", f.getvalue())
721
self.assertEqual("Now on revision 20.\n", f.getvalue())
723
720
def test_report_unchanged(self):
724
721
r = _mod_branch.PullResult()