113
141
dir = format._matchingbzrdir.initialize(url)
114
142
dir.create_repository()
115
143
format.initialize(dir)
116
found_format = bzrlib.branch.BranchFormat.find_format(dir)
144
found_format = BranchFormat.find_format(dir)
117
145
self.failUnless(isinstance(found_format, format.__class__))
118
check_format(bzrlib.branch.BzrBranchFormat5(), "bar")
146
check_format(BzrBranchFormat5(), "bar")
120
148
def test_find_format_not_branch(self):
121
149
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
122
150
self.assertRaises(NotBranchError,
123
bzrlib.branch.BranchFormat.find_format,
151
BranchFormat.find_format,
126
154
def test_find_format_unknown_format(self):
127
155
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
128
156
SampleBranchFormat().initialize(dir)
129
157
self.assertRaises(UnknownFormatError,
130
bzrlib.branch.BranchFormat.find_format,
158
BranchFormat.find_format,
133
161
def test_register_unregister_format(self):
138
166
format.initialize(dir)
139
167
# register a format for it.
140
bzrlib.branch.BranchFormat.register_format(format)
168
BranchFormat.register_format(format)
141
169
# which branch.Open will refuse (not supported)
142
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')
143
172
# but open_downlevel will work
144
173
self.assertEqual(format.open(dir), bzrdir.BzrDir.open(self.get_url()).open_branch(unsupported=True))
145
174
# unregister the format
146
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)
149
284
class TestBranchReference(TestCaseWithTransport):
150
285
"""Tests for the branch reference facility."""
158
293
target_branch = dir.create_branch()
159
294
t.mkdir('branch')
160
295
branch_dir = bzrdirformat.initialize(self.get_url('branch'))
161
made_branch = bzrlib.branch.BranchReferenceFormat().initialize(branch_dir, target_branch)
296
made_branch = BranchReferenceFormat().initialize(branch_dir, target_branch)
162
297
self.assertEqual(made_branch.base, target_branch.base)
163
298
opened_branch = branch_dir.open_branch()
164
299
self.assertEqual(opened_branch.base, target_branch.base)
301
def test_get_reference(self):
302
"""For a BranchReference, get_reference should reutrn the location."""
303
branch = self.make_branch('target')
304
checkout = branch.create_checkout('checkout', lightweight=True)
305
reference_url = branch.bzrdir.root_transport.abspath('') + '/'
306
# if the api for create_checkout changes to return different checkout types
307
# then this file read will fail.
308
self.assertFileEqual(reference_url, 'checkout/.bzr/branch/location')
309
self.assertEqual(reference_url,
310
_mod_branch.BranchReferenceFormat().get_reference(checkout.bzrdir))
313
class TestHooks(TestCase):
315
def test_constructor(self):
316
"""Check that creating a BranchHooks instance has the right defaults."""
317
hooks = BranchHooks()
318
self.assertTrue("set_rh" in hooks, "set_rh not in %s" % hooks)
319
self.assertTrue("post_push" in hooks, "post_push not in %s" % hooks)
320
self.assertTrue("post_commit" in hooks, "post_commit not in %s" % hooks)
321
self.assertTrue("post_pull" in hooks, "post_pull not in %s" % hooks)
322
self.assertTrue("post_uncommit" in hooks, "post_uncommit not in %s" % hooks)
324
def test_installed_hooks_are_BranchHooks(self):
325
"""The installed hooks object should be a BranchHooks."""
326
# the installed hooks are saved in self._preserved_hooks.
327
self.assertIsInstance(self._preserved_hooks[_mod_branch.Branch], BranchHooks)
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")