76
77
br = self.get_branch()
77
78
br.fetch(wt.branch)
78
79
br.generate_revision_history('rev3')
79
rh = br.revision_history()
80
self.assertEqual(['rev1', 'rev2', 'rev3'], rh)
81
for revision_id in rh:
80
for revision_id in ['rev3', 'rev2', 'rev1']:
82
81
self.assertIsInstance(revision_id, str)
83
82
last = br.last_revision()
84
83
self.assertEqual('rev3', last)
253
252
self.get_branch().repository.get_revision,
257
# compare the gpg-to-sign info for a commit with a ghost and
258
# an identical tree without a ghost
259
# fetch missing should rewrite the TOC of weaves to list newly available parents.
261
def test_sign_existing_revision(self):
262
wt = self.make_branch_and_tree('.')
264
wt.commit("base", allow_pointless=True, rev_id='A')
265
from bzrlib.testament import Testament
266
strategy = gpg.LoopbackGPGStrategy(None)
267
branch.repository.lock_write()
268
branch.repository.start_write_group()
269
branch.repository.sign_revision('A', strategy)
270
branch.repository.commit_write_group()
271
branch.repository.unlock()
272
self.assertEqual('-----BEGIN PSEUDO-SIGNED CONTENT-----\n' +
273
Testament.from_revision(branch.repository,
274
'A').as_short_text() +
275
'-----END PSEUDO-SIGNED CONTENT-----\n',
276
branch.repository.get_signature_text('A'))
278
def test_store_signature(self):
279
wt = self.make_branch_and_tree('.')
283
branch.repository.start_write_group()
285
branch.repository.store_revision_signature(
286
gpg.LoopbackGPGStrategy(None), 'FOO', 'A')
288
branch.repository.abort_write_group()
291
branch.repository.commit_write_group()
294
# A signature without a revision should not be accessible.
295
self.assertRaises(errors.NoSuchRevision,
296
branch.repository.has_signature_for_revision_id,
298
wt.commit("base", allow_pointless=True, rev_id='A')
299
self.assertEqual('-----BEGIN PSEUDO-SIGNED CONTENT-----\n'
300
'FOO-----END PSEUDO-SIGNED CONTENT-----\n',
301
branch.repository.get_signature_text('A'))
303
def test_branch_keeps_signatures(self):
304
wt = self.make_branch_and_tree('source')
305
wt.commit('A', allow_pointless=True, rev_id='A')
306
repo = wt.branch.repository
308
repo.start_write_group()
309
repo.sign_revision('A', gpg.LoopbackGPGStrategy(None))
310
repo.commit_write_group()
312
#FIXME: clone should work to urls,
313
# wt.clone should work to disks.
314
self.build_tree(['target/'])
315
d2 = repo.bzrdir.clone(urlutils.local_path_to_url('target'))
316
self.assertEqual(repo.get_signature_text('A'),
317
d2.open_repository().get_signature_text('A'))
319
255
def test_nicks_bzr(self):
320
256
"""Test the behaviour of branch nicks specific to bzr branches.
461
397
"""Create a fake revision history easily."""
462
398
tree = self.make_branch_and_tree('.')
463
399
rev1 = tree.commit('foo')
464
orig_history = tree.branch.revision_history()
401
self.addCleanup(tree.unlock)
402
graph = tree.branch.repository.get_graph()
404
graph.iter_lefthand_ancestry(
405
tree.branch.last_revision(), [revision.NULL_REVISION]))
465
406
rev2 = tree.commit('bar', allow_pointless=True)
466
407
tree.branch.generate_revision_history(rev1)
467
self.assertEqual(orig_history, tree.branch.revision_history())
408
self.assertEqual(orig_history, list(
409
graph.iter_lefthand_ancestry(
410
tree.branch.last_revision(), [revision.NULL_REVISION])))
469
412
def test_generate_revision_history_NULL_REVISION(self):
470
413
tree = self.make_branch_and_tree('.')
471
414
rev1 = tree.commit('foo')
416
self.addCleanup(tree.unlock)
472
417
tree.branch.generate_revision_history(revision.NULL_REVISION)
473
self.assertEqual([], tree.branch.revision_history())
418
self.assertEqual(revision.NULL_REVISION, tree.branch.last_revision())
475
420
def test_create_checkout(self):
476
421
tree_a = self.make_branch_and_tree('a')
497
442
tree_a = self.make_branch_and_tree('a')
498
443
rev_id = tree_a.commit('put some content in the branch')
499
444
# open the branch via a readonly transport
500
source_branch = _mod_branch.Branch.open(self.get_readonly_url('a'))
445
url = self.get_readonly_url(urlutils.basename(tree_a.branch.base))
446
t = transport.get_transport_from_url(url)
447
if not tree_a.branch.bzrdir._format.supports_transport(t):
448
raise tests.TestNotApplicable("format does not support transport")
449
source_branch = _mod_branch.Branch.open(url)
501
450
# sanity check that the test will be valid
502
451
self.assertRaises((errors.LockError, errors.TransportNotPossible),
503
452
source_branch.lock_write)
509
458
tree_a = self.make_branch_and_tree('a')
510
459
rev_id = tree_a.commit('put some content in the branch')
511
460
# open the branch via a readonly transport
512
source_branch = _mod_branch.Branch.open(self.get_readonly_url('a'))
461
url = self.get_readonly_url(
462
osutils.basename(tree_a.branch.base.rstrip('/')))
463
t = transport.get_transport_from_url(url)
464
if not tree_a.branch.bzrdir._format.supports_transport(t):
465
raise tests.TestNotApplicable("format does not support transport")
466
source_branch = _mod_branch.Branch.open(url)
513
467
# sanity check that the test will be valid
514
468
self.assertRaises((errors.LockError, errors.TransportNotPossible),
515
469
source_branch.lock_write)
597
551
_mod_branch.Branch.open_containing,
598
552
self.get_readonly_url('g/p/q'))
599
553
branch = self.make_branch('.')
554
if not branch.bzrdir._format.supports_transport(
555
transport.get_transport_from_url(self.get_readonly_url('.'))):
556
raise tests.TestNotApplicable("format does not support transport")
600
557
branch, relpath = _mod_branch.Branch.open_containing(
601
558
self.get_readonly_url(''))
602
559
self.assertEqual('', relpath)
924
881
tree.add_reference(subtree)
925
882
except errors.UnsupportedOperation:
926
883
raise tests.TestNotApplicable('Tree cannot hold references.')
927
reference_parent = tree.branch.reference_parent('subtree-id',
884
reference_parent = tree.branch.reference_parent(
886
urlutils.relative_url(tree.branch.user_url, subtree.branch.user_url))
929
887
self.assertEqual(subtree.branch.base, reference_parent.base)
931
889
def test_reference_parent_accepts_possible_transports(self):
937
895
except errors.UnsupportedOperation:
938
896
raise tests.TestNotApplicable('Tree cannot hold references.')
939
897
reference_parent = tree.branch.reference_parent('subtree-id',
940
'subtree', possible_transports=[subtree.bzrdir.root_transport])
898
urlutils.relative_url(
899
tree.branch.user_url, subtree.branch.user_url),
900
possible_transports=[subtree.bzrdir.root_transport])
942
902
def test_get_reference_info(self):
943
903
branch = self.make_branch('branch')