1
# Copyright (C) 2006-2011 Canonical Ltd
1
# Copyright (C) 2006-2010 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
113
113
"""See BzrBranchFormat.get_format_string()."""
114
114
return "Sample branch format."
116
def initialize(self, a_bzrdir, name=None, repository=None):
116
def initialize(self, a_bzrdir, name=None):
117
117
"""Format 4 branches cannot be created."""
118
118
t = a_bzrdir.get_branch_transport(self, name=name)
119
119
t.put_bytes('format', self.get_format_string())
147
147
return "opened supported branch."
150
class SampleExtraBranchFormat(_mod_branch.BranchFormat):
151
"""A sample format that is not usable in a metadir."""
153
def get_format_string(self):
154
# This format is not usable in a metadir.
157
def network_name(self):
158
# Network name always has to be provided.
161
def initialize(self, a_bzrdir, name=None):
162
raise NotImplementedError(self.initialize)
164
def open(self, transport, name=None, _found=False, ignore_fallbacks=False):
165
raise NotImplementedError(self.open)
168
150
class TestBzrBranchFormat(tests.TestCaseWithTransport):
169
151
"""Tests for the BzrBranchFormat facility."""
181
163
self.failUnless(isinstance(found_format, format.__class__))
182
164
check_format(_mod_branch.BzrBranchFormat5(), "bar")
184
def test_extra_format(self):
185
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
186
SampleSupportedBranchFormat().initialize(dir)
187
format = SampleExtraBranchFormat()
188
_mod_branch.BranchFormat.register_extra_format(format)
189
self.addCleanup(_mod_branch.BranchFormat.unregister_extra_format,
191
self.assertTrue(format in _mod_branch.BranchFormat.get_formats())
192
self.assertEquals(format,
193
_mod_branch.network_format_registry.get("extra"))
195
166
def test_find_format_factory(self):
196
167
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
197
168
SampleSupportedBranchFormat().initialize(dir)
296
267
def test_config(self):
297
268
"""Ensure that all configuration data is stored in the branch"""
298
269
branch = self.make_branch('a', format=self.get_format_name())
299
branch.set_parent('http://example.com')
270
branch.set_parent('http://bazaar-vcs.org')
300
271
self.failIfExists('a/.bzr/branch/parent')
301
self.assertEqual('http://example.com', branch.get_parent())
302
branch.set_push_location('sftp://example.com')
272
self.assertEqual('http://bazaar-vcs.org', branch.get_parent())
273
branch.set_push_location('sftp://bazaar-vcs.org')
303
274
config = branch.get_config()._get_branch_data_config()
304
self.assertEqual('sftp://example.com',
275
self.assertEqual('sftp://bazaar-vcs.org',
305
276
config.get_user_option('push_location'))
306
branch.set_bound_location('ftp://example.com')
277
branch.set_bound_location('ftp://bazaar-vcs.org')
307
278
self.failIfExists('a/.bzr/branch/bound')
308
self.assertEqual('ftp://example.com', branch.get_bound_location())
279
self.assertEqual('ftp://bazaar-vcs.org', branch.get_bound_location())
310
281
def test_set_revision_history(self):
311
282
builder = self.make_branch_builder('.', format=self.get_format_name())