85
def test_set_push_location(self):
86
from bzrlib.config import (locations_config_filename,
87
ensure_config_dir_exists)
88
ensure_config_dir_exists()
89
fn = locations_config_filename()
90
branch = self.make_branch('.', format='knit')
91
branch.set_push_location('foo')
92
local_path = urlutils.local_path_from_url(branch.base[:-1])
93
self.assertFileEqual("[%s]\n"
94
"push_location = foo\n"
95
"push_location:policy = norecurse" % local_path,
98
# TODO RBC 20051029 test getting a push location from a branch in a
99
# recursive section - that is, it appends the branch name.
81
102
class SampleBranchFormat(bzrlib.branch.BranchFormat):
82
103
"""A sample format
141
162
bzrlib.branch.BranchFormat.register_format(format)
142
163
# which branch.Open will refuse (not supported)
143
164
self.assertRaises(UnsupportedFormatError, bzrlib.branch.Branch.open, self.get_url())
165
self.make_branch_and_tree('foo')
144
166
# but open_downlevel will work
145
167
self.assertEqual(format.open(dir), bzrdir.BzrDir.open(self.get_url()).open_branch(unsupported=True))
146
168
# unregister the format
147
169
bzrlib.branch.BranchFormat.unregister_format(format)
170
self.make_branch_and_tree('bar')
172
def test_checkout_format(self):
173
branch = self.make_repository('repository', shared=True)
174
branch = self.make_branch('repository/branch',
176
tree = branch.create_checkout('checkout')
177
self.assertIs(tree.branch.__class__, _mod_branch.BzrBranch5)
180
class TestBranch6(TestCaseWithTransport):
182
def test_creation(self):
183
format = BzrDirMetaFormat1()
184
format.set_branch_format(_mod_branch.BzrBranchFormat6())
185
branch = self.make_branch('a', format=format)
186
self.assertIsInstance(branch, _mod_branch.BzrBranch6)
187
branch = self.make_branch('b', format='experimental-branch6')
188
self.assertIsInstance(branch, _mod_branch.BzrBranch6)
189
branch = _mod_branch.Branch.open('a')
190
self.assertIsInstance(branch, _mod_branch.BzrBranch6)
192
def test_layout(self):
193
branch = self.make_branch('a', format='experimental-branch6')
194
self.failUnlessExists('a/.bzr/branch/last-revision')
195
self.failIfExists('a/.bzr/branch/revision-history')
197
def test_config(self):
198
"""Ensure that all configuration data is stored in the branch"""
199
branch = self.make_branch('a', format='experimental-branch6')
200
branch.set_parent('http://bazaar-vcs.org')
201
self.failIfExists('a/.bzr/branch/parent')
202
self.assertEqual('http://bazaar-vcs.org', branch.get_parent())
203
branch.set_push_location('sftp://bazaar-vcs.org')
204
config = branch.get_config()._get_branch_data_config()
205
self.assertEqual('sftp://bazaar-vcs.org',
206
config.get_user_option('push_location'))
207
branch.set_bound_location('ftp://bazaar-vcs.org')
208
self.failIfExists('a/.bzr/branch/bound')
209
self.assertEqual('ftp://bazaar-vcs.org', branch.get_bound_location())
211
def test_set_revision_history(self):
212
tree = self.make_branch_and_memory_tree('.',
213
format='experimental-branch6')
217
tree.commit('foo', rev_id='foo')
218
tree.commit('bar', rev_id='bar')
219
tree.branch.set_revision_history(['foo', 'bar'])
220
tree.branch.set_revision_history(['foo'])
221
self.assertRaises(errors.NotLefthandHistory,
222
tree.branch.set_revision_history, ['bar'])
226
def test_append_revision(self):
227
tree = self.make_branch_and_tree('branch1',
228
format='experimental-branch6')
232
tree.commit('foo', rev_id='foo')
233
tree.commit('bar', rev_id='bar')
234
tree.commit('baz', rev_id='baz')
235
tree.set_last_revision('bar')
236
tree.branch.set_last_revision_info(2, 'bar')
237
tree.commit('qux', rev_id='qux')
238
tree.add_parent_tree_id('baz')
239
tree.commit('qux', rev_id='quxx')
240
tree.branch.set_last_revision_info(0, 'null:')
241
self.assertRaises(errors.NotLeftParentDescendant,
242
tree.branch.append_revision, 'bar')
243
tree.branch.append_revision('foo')
244
self.assertRaises(errors.NotLeftParentDescendant,
245
tree.branch.append_revision, 'baz')
246
tree.branch.append_revision('bar')
247
tree.branch.append_revision('baz')
248
self.assertRaises(errors.NotLeftParentDescendant,
249
tree.branch.append_revision, 'quxx')
150
254
class TestBranchReference(TestCaseWithTransport):