114
141
dir = format._matchingbzrdir.initialize(url)
115
142
dir.create_repository()
116
143
format.initialize(dir)
117
found_format = bzrlib.branch.BranchFormat.find_format(dir)
144
found_format = BranchFormat.find_format(dir)
118
145
self.failUnless(isinstance(found_format, format.__class__))
119
check_format(bzrlib.branch.BzrBranchFormat5(), "bar")
146
check_format(BzrBranchFormat5(), "bar")
121
148
def test_find_format_not_branch(self):
122
149
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
123
150
self.assertRaises(NotBranchError,
124
bzrlib.branch.BranchFormat.find_format,
151
BranchFormat.find_format,
127
154
def test_find_format_unknown_format(self):
128
155
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
129
156
SampleBranchFormat().initialize(dir)
130
157
self.assertRaises(UnknownFormatError,
131
bzrlib.branch.BranchFormat.find_format,
158
BranchFormat.find_format,
134
161
def test_register_unregister_format(self):
139
166
format.initialize(dir)
140
167
# register a format for it.
141
bzrlib.branch.BranchFormat.register_format(format)
168
BranchFormat.register_format(format)
142
169
# which branch.Open will refuse (not supported)
143
self.assertRaises(UnsupportedFormatError, bzrlib.branch.Branch.open, self.get_url())
170
self.assertRaises(UnsupportedFormatError, Branch.open, self.get_url())
171
self.make_branch_and_tree('foo')
144
172
# but open_downlevel will work
145
173
self.assertEqual(format.open(dir), bzrdir.BzrDir.open(self.get_url()).open_branch(unsupported=True))
146
174
# unregister the format
147
bzrlib.branch.BranchFormat.unregister_format(format)
175
BranchFormat.unregister_format(format)
176
self.make_branch_and_tree('bar')
179
class TestBranch6(TestCaseWithTransport):
181
def test_creation(self):
182
format = BzrDirMetaFormat1()
183
format.set_branch_format(_mod_branch.BzrBranchFormat6())
184
branch = self.make_branch('a', format=format)
185
self.assertIsInstance(branch, _mod_branch.BzrBranch6)
186
branch = self.make_branch('b', format='dirstate-tags')
187
self.assertIsInstance(branch, _mod_branch.BzrBranch6)
188
branch = _mod_branch.Branch.open('a')
189
self.assertIsInstance(branch, _mod_branch.BzrBranch6)
191
def test_layout(self):
192
branch = self.make_branch('a', format='dirstate-tags')
193
self.failUnlessExists('a/.bzr/branch/last-revision')
194
self.failIfExists('a/.bzr/branch/revision-history')
196
def test_config(self):
197
"""Ensure that all configuration data is stored in the branch"""
198
branch = self.make_branch('a', format='dirstate-tags')
199
branch.set_parent('http://bazaar-vcs.org')
200
self.failIfExists('a/.bzr/branch/parent')
201
self.assertEqual('http://bazaar-vcs.org', branch.get_parent())
202
branch.set_push_location('sftp://bazaar-vcs.org')
203
config = branch.get_config()._get_branch_data_config()
204
self.assertEqual('sftp://bazaar-vcs.org',
205
config.get_user_option('push_location'))
206
branch.set_bound_location('ftp://bazaar-vcs.org')
207
self.failIfExists('a/.bzr/branch/bound')
208
self.assertEqual('ftp://bazaar-vcs.org', branch.get_bound_location())
210
def test_set_revision_history(self):
211
tree = self.make_branch_and_memory_tree('.',
212
format='dirstate-tags')
216
tree.commit('foo', rev_id='foo')
217
tree.commit('bar', rev_id='bar')
218
tree.branch.set_revision_history(['foo', 'bar'])
219
tree.branch.set_revision_history(['foo'])
220
self.assertRaises(errors.NotLefthandHistory,
221
tree.branch.set_revision_history, ['bar'])
225
def test_append_revision(self):
226
tree = self.make_branch_and_tree('branch1',
227
format='dirstate-tags')
230
tree.commit('foo', rev_id='foo')
231
tree.commit('bar', rev_id='bar')
232
tree.commit('baz', rev_id='baz')
233
tree.set_last_revision('bar')
234
tree.branch.set_last_revision_info(2, 'bar')
235
tree.commit('qux', rev_id='qux')
236
tree.add_parent_tree_id('baz')
237
tree.commit('qux', rev_id='quxx')
238
tree.branch.set_last_revision_info(0, 'null:')
239
self.assertRaises(errors.NotLeftParentDescendant,
240
tree.branch.append_revision, 'bar')
241
tree.branch.append_revision('foo')
242
self.assertRaises(errors.NotLeftParentDescendant,
243
tree.branch.append_revision, 'baz')
244
tree.branch.append_revision('bar')
245
tree.branch.append_revision('baz')
246
self.assertRaises(errors.NotLeftParentDescendant,
247
tree.branch.append_revision, 'quxx')
251
def do_checkout_test(self, lightweight=False):
252
tree = self.make_branch_and_tree('source', format='dirstate-with-subtree')
253
subtree = self.make_branch_and_tree('source/subtree',
254
format='dirstate-with-subtree')
255
subsubtree = self.make_branch_and_tree('source/subtree/subsubtree',
256
format='dirstate-with-subtree')
257
self.build_tree(['source/subtree/file',
258
'source/subtree/subsubtree/file'])
259
subsubtree.add('file')
261
subtree.add_reference(subsubtree)
262
tree.add_reference(subtree)
263
tree.commit('a revision')
264
subtree.commit('a subtree file')
265
subsubtree.commit('a subsubtree file')
266
tree.branch.create_checkout('target', lightweight=lightweight)
267
self.failUnlessExists('target')
268
self.failUnlessExists('target/subtree')
269
self.failUnlessExists('target/subtree/file')
270
self.failUnlessExists('target/subtree/subsubtree/file')
271
subbranch = _mod_branch.Branch.open('target/subtree/subsubtree')
273
self.assertEndsWith(subbranch.base, 'source/subtree/subsubtree/')
275
self.assertEndsWith(subbranch.base, 'target/subtree/subsubtree/')
278
def test_checkout_with_references(self):
279
self.do_checkout_test()
281
def test_light_checkout_with_references(self):
282
self.do_checkout_test(lightweight=True)
150
284
class TestBranchReference(TestCaseWithTransport):
151
285
"""Tests for the branch reference facility."""
179
313
def test_installed_hooks_are_BranchHooks(self):
180
314
"""The installed hooks object should be a BranchHooks."""
181
315
# the installed hooks are saved in self._preserved_hooks.
182
self.assertIsInstance(self._preserved_hooks, bzrlib.branch.BranchHooks)
316
self.assertIsInstance(self._preserved_hooks, BranchHooks)
184
318
def test_install_hook_raises_unknown_hook(self):
185
319
"""install_hook should raise UnknownHook if a hook is unknown."""
186
hooks = bzrlib.branch.BranchHooks()
320
hooks = BranchHooks()
187
321
self.assertRaises(UnknownHook, hooks.install_hook, 'silly', None)
189
323
def test_install_hook_appends_known_hook(self):
190
324
"""install_hook should append the callable for known hooks."""
191
hooks = bzrlib.branch.BranchHooks()
325
hooks = BranchHooks()
192
326
hooks.install_hook('set_rh', None)
193
327
self.assertEqual(hooks['set_rh'], [None])
330
class TestPullResult(TestCase):
332
def test_pull_result_to_int(self):
333
# to support old code, the pull result can be used as an int
337
# this usage of results is not recommended for new code (because it
338
# doesn't describe very well what happened), but for api stability
339
# it's still supported
340
a = "%d revisions pulled" % r
341
self.assertEqual(a, "10 revisions pulled")