114
113
tree_a.add('vla', 'file2')
115
114
tree_a.commit('rev2', rev_id='rev2')
117
delta = tree_a.branch.get_revision_delta(1)
116
delta = self.applyDeprecated(symbol_versioning.deprecated_in(
117
(2, 5, 0)), tree_a.branch.get_revision_delta, 1)
118
118
self.assertIsInstance(delta, _mod_delta.TreeDelta)
119
119
self.assertEqual([('foo', 'file1', 'file')], delta.added)
120
delta = tree_a.branch.get_revision_delta(2)
120
delta = self.applyDeprecated(symbol_versioning.deprecated_in(
121
(2, 5, 0)), tree_a.branch.get_revision_delta, 2)
121
122
self.assertIsInstance(delta, _mod_delta.TreeDelta)
122
123
self.assertEqual([('vla', 'file2', 'file')], delta.added)
245
252
self.get_branch().repository.get_revision,
249
# compare the gpg-to-sign info for a commit with a ghost and
250
# an identical tree without a ghost
251
# fetch missing should rewrite the TOC of weaves to list newly available parents.
253
def test_sign_existing_revision(self):
254
wt = self.make_branch_and_tree('.')
256
wt.commit("base", allow_pointless=True, rev_id='A')
257
from bzrlib.testament import Testament
258
strategy = gpg.LoopbackGPGStrategy(None)
259
branch.repository.lock_write()
260
branch.repository.start_write_group()
261
branch.repository.sign_revision('A', strategy)
262
branch.repository.commit_write_group()
263
branch.repository.unlock()
264
self.assertEqual('-----BEGIN PSEUDO-SIGNED CONTENT-----\n' +
265
Testament.from_revision(branch.repository,
266
'A').as_short_text() +
267
'-----END PSEUDO-SIGNED CONTENT-----\n',
268
branch.repository.get_signature_text('A'))
270
def test_store_signature(self):
271
wt = self.make_branch_and_tree('.')
275
branch.repository.start_write_group()
277
branch.repository.store_revision_signature(
278
gpg.LoopbackGPGStrategy(None), 'FOO', 'A')
280
branch.repository.abort_write_group()
283
branch.repository.commit_write_group()
286
# A signature without a revision should not be accessible.
287
self.assertRaises(errors.NoSuchRevision,
288
branch.repository.has_signature_for_revision_id,
290
wt.commit("base", allow_pointless=True, rev_id='A')
291
self.assertEqual('-----BEGIN PSEUDO-SIGNED CONTENT-----\n'
292
'FOO-----END PSEUDO-SIGNED CONTENT-----\n',
293
branch.repository.get_signature_text('A'))
295
def test_branch_keeps_signatures(self):
296
wt = self.make_branch_and_tree('source')
297
wt.commit('A', allow_pointless=True, rev_id='A')
298
repo = wt.branch.repository
300
repo.start_write_group()
301
repo.sign_revision('A', gpg.LoopbackGPGStrategy(None))
302
repo.commit_write_group()
304
#FIXME: clone should work to urls,
305
# wt.clone should work to disks.
306
self.build_tree(['target/'])
307
d2 = repo.bzrdir.clone(urlutils.local_path_to_url('target'))
308
self.assertEqual(repo.get_signature_text('A'),
309
d2.open_repository().get_signature_text('A'))
311
def test_nicks(self):
312
"""Test explicit and implicit branch nicknames.
255
def test_nicks_bzr(self):
256
"""Test the behaviour of branch nicks specific to bzr branches.
314
258
Nicknames are implicitly the name of the branch's directory, unless an
315
259
explicit nickname is set. That is, an explicit nickname always
316
260
overrides the implicit one.
318
263
t = self.get_transport()
319
264
branch = self.make_branch('bzr.dev')
265
if not isinstance(branch, _mod_branch.BzrBranch):
266
raise tests.TestNotApplicable("not a bzr branch format")
320
267
# The nick will be 'bzr.dev', because there is no explicit nick set.
321
268
self.assertEqual(branch.nick, 'bzr.dev')
322
269
# Move the branch to a different directory, 'bzr.ab'. Now that branch
338
285
branch.nick = u"\u1234"
339
286
self.assertEqual(branch.nick, u"\u1234")
288
def test_nicks(self):
289
"""Test explicit and implicit branch nicknames.
291
A nickname is always available, whether set explicitly or not.
293
t = self.get_transport()
294
branch = self.make_branch('bzr.dev')
295
# An implicit nick name is set; what it is exactly depends on the
297
self.assertIsInstance(branch.nick, basestring)
298
# Set the branch nick explicitly.
299
branch.nick = "Aaron's branch"
300
# Because the nick has been set explicitly, the nick is now always
302
self.assertEqual(branch.nick, "Aaron's branch")
303
branch.nick = u"\u1234"
304
self.assertEqual(branch.nick, u"\u1234")
341
306
def test_commit_nicks(self):
342
307
"""Nicknames are committed to the revision"""
343
308
wt = self.make_branch_and_tree('bzr.dev')
353
318
repo = self.make_repository('.', shared=True)
354
319
except errors.IncompatibleFormat:
321
if repo.bzrdir._format.colocated_branches:
322
raise tests.TestNotApplicable(
323
"control dir does not support colocated branches")
356
324
self.assertEquals(0, len(repo.bzrdir.list_branches()))
325
if not self.bzrdir_format.colocated_branches:
326
raise tests.TestNotApplicable("control dir format does not support "
327
"colocated branches")
358
329
child_branch1 = self.branch_format.initialize(repo.bzrdir,
360
except (errors.UninitializableFormat, errors.NoColocatedBranchSupport):
331
except errors.UninitializableFormat:
361
332
# branch references are not default init'able and
362
333
# not all bzrdirs support colocated branches.
365
336
self.branch_format.initialize(repo.bzrdir, name='branch2')
366
337
self.assertEquals(2, len(repo.bzrdir.list_branches()))
339
def test_create_append_revisions_only(self):
341
repo = self.make_repository('.', shared=True)
342
except errors.IncompatibleFormat:
344
for val in (True, False):
346
branch = self.branch_format.initialize(repo.bzrdir,
347
append_revisions_only=True)
348
except (errors.UninitializableFormat, errors.UpgradeRequired):
349
# branch references are not default init'able and
350
# not all branches support append_revisions_only
352
self.assertEquals(True, branch.get_append_revisions_only())
353
repo.bzrdir.destroy_branch()
355
def test_get_set_append_revisions_only(self):
356
branch = self.make_branch('.')
357
if branch._format.supports_set_append_revisions_only():
358
branch.set_append_revisions_only(True)
359
self.assertTrue(branch.get_append_revisions_only())
360
branch.set_append_revisions_only(False)
361
self.assertFalse(branch.get_append_revisions_only())
363
self.assertRaises(errors.UpgradeRequired,
364
branch.set_append_revisions_only, True)
365
self.assertFalse(branch.get_append_revisions_only())
368
367
def test_create_open_branch_uses_repository(self):
370
369
repo = self.make_repository('.', shared=True)
371
370
except errors.IncompatibleFormat:
371
raise tests.TestNotApplicable("requires shared repository support")
373
372
child_transport = repo.bzrdir.root_transport.clone('child')
374
373
child_transport.mkdir('.')
375
child_dir = self.bzrdir_format.initialize_on_transport(child_transport)
375
child_dir = self.bzrdir_format.initialize_on_transport(child_transport)
376
except errors.UninitializableFormat:
377
raise tests.TestNotApplicable("control dir format not initializable")
377
379
child_branch = self.branch_format.initialize(child_dir)
378
380
except errors.UninitializableFormat:
401
403
"""Create a fake revision history easily."""
402
404
tree = self.make_branch_and_tree('.')
403
405
rev1 = tree.commit('foo')
404
orig_history = tree.branch.revision_history()
407
self.addCleanup(tree.unlock)
408
graph = tree.branch.repository.get_graph()
410
graph.iter_lefthand_ancestry(
411
tree.branch.last_revision(), [revision.NULL_REVISION]))
405
412
rev2 = tree.commit('bar', allow_pointless=True)
406
413
tree.branch.generate_revision_history(rev1)
407
self.assertEqual(orig_history, tree.branch.revision_history())
414
self.assertEqual(orig_history, list(
415
graph.iter_lefthand_ancestry(
416
tree.branch.last_revision(), [revision.NULL_REVISION])))
409
418
def test_generate_revision_history_NULL_REVISION(self):
410
419
tree = self.make_branch_and_tree('.')
411
420
rev1 = tree.commit('foo')
422
self.addCleanup(tree.unlock)
412
423
tree.branch.generate_revision_history(revision.NULL_REVISION)
413
self.assertEqual([], tree.branch.revision_history())
424
self.assertEqual(revision.NULL_REVISION, tree.branch.last_revision())
415
426
def test_create_checkout(self):
416
427
tree_a = self.make_branch_and_tree('a')
437
448
tree_a = self.make_branch_and_tree('a')
438
449
rev_id = tree_a.commit('put some content in the branch')
439
450
# open the branch via a readonly transport
440
source_branch = _mod_branch.Branch.open(self.get_readonly_url('a'))
451
url = self.get_readonly_url(urlutils.basename(tree_a.branch.base))
452
t = transport.get_transport_from_url(url)
453
if not tree_a.branch.bzrdir._format.supports_transport(t):
454
raise tests.TestNotApplicable("format does not support transport")
455
source_branch = _mod_branch.Branch.open(url)
441
456
# sanity check that the test will be valid
442
457
self.assertRaises((errors.LockError, errors.TransportNotPossible),
443
458
source_branch.lock_write)
449
464
tree_a = self.make_branch_and_tree('a')
450
465
rev_id = tree_a.commit('put some content in the branch')
451
466
# open the branch via a readonly transport
452
source_branch = _mod_branch.Branch.open(self.get_readonly_url('a'))
467
url = self.get_readonly_url(
468
osutils.basename(tree_a.branch.base.rstrip('/')))
469
t = transport.get_transport_from_url(url)
470
if not tree_a.branch.bzrdir._format.supports_transport(t):
471
raise tests.TestNotApplicable("format does not support transport")
472
source_branch = _mod_branch.Branch.open(url)
453
473
# sanity check that the test will be valid
454
474
self.assertRaises((errors.LockError, errors.TransportNotPossible),
455
475
source_branch.lock_write)
463
483
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
464
484
br.set_revision_history, ["rev1"])
465
self.assertEquals(br.revision_history(), ["rev1"])
485
self.assertEquals(br.last_revision(), "rev1")
466
486
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
467
487
br.set_revision_history, [])
468
self.assertEquals(br.revision_history(), [])
488
self.assertEquals(br.last_revision(), 'null:')
470
490
def test_heads_to_fetch(self):
471
491
# heads_to_fetch is a method that returns a collection of revids that
531
557
_mod_branch.Branch.open_containing,
532
558
self.get_readonly_url('g/p/q'))
533
559
branch = self.make_branch('.')
560
if not branch.bzrdir._format.supports_transport(
561
transport.get_transport_from_url(self.get_readonly_url('.'))):
562
raise tests.TestNotApplicable("format does not support transport")
534
563
branch, relpath = _mod_branch.Branch.open_containing(
535
564
self.get_readonly_url(''))
536
565
self.assertEqual('', relpath)
622
651
class TestChildSubmitFormats(per_branch.TestCaseWithBranch):
624
653
def test_get_child_submit_format_default(self):
625
self.assertEqual(None, self.get_branch().get_child_submit_format())
654
submit_format = self.get_branch().get_child_submit_format()
655
self.assertTrue(submit_format is None or
656
isinstance(submit_format, str))
627
658
def test_get_child_submit_format(self):
628
659
branch = self.get_branch()
629
branch.get_config().set_user_option('child_submit_format', '10')
660
branch.get_config_stack().set('child_submit_format', '10')
630
661
branch = self.get_branch()
631
662
self.assertEqual('10', branch.get_child_submit_format())
835
866
def test_fallbacks_not_opened(self):
836
867
stacked = self.make_branch_with_fallback()
837
868
self.get_transport('').rename('fallback', 'moved')
838
reopened = stacked.bzrdir.open_branch(ignore_fallbacks=True)
869
reopened_dir = bzrdir.BzrDir.open(stacked.base)
870
reopened = reopened_dir.open_branch(ignore_fallbacks=True)
839
871
self.assertEqual([], reopened.repository._fallback_repositories)
841
873
def test_fallbacks_are_opened(self):
842
874
stacked = self.make_branch_with_fallback()
843
reopened = stacked.bzrdir.open_branch(ignore_fallbacks=False)
875
reopened_dir = bzrdir.BzrDir.open(stacked.base)
876
reopened = reopened_dir.open_branch(ignore_fallbacks=False)
844
877
self.assertLength(1, reopened.repository._fallback_repositories)