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)
217
216
def test_record_initial_ghost(self):
218
217
"""Branches should support having ghosts."""
219
218
wt = self.make_branch_and_tree('.')
219
if not wt.branch.repository._format.supports_ghosts:
220
raise tests.TestNotApplicable("repository format does not "
220
222
wt.set_parent_ids(['non:existent@rev--ision--0--2'],
221
223
allow_leftmost_as_ghost=True)
222
224
self.assertEqual(['non:existent@rev--ision--0--2'],
230
232
def test_record_two_ghosts(self):
231
233
"""Recording with all ghosts works."""
232
234
wt = self.make_branch_and_tree('.')
235
if not wt.branch.repository._format.supports_ghosts:
236
raise tests.TestNotApplicable("repository format does not "
233
238
wt.set_parent_ids([
234
239
'foo@azkhazan-123123-abcabc',
235
240
'wibble@fofof--20050401--1928390812',
247
252
self.get_branch().repository.get_revision,
251
# compare the gpg-to-sign info for a commit with a ghost and
252
# an identical tree without a ghost
253
# fetch missing should rewrite the TOC of weaves to list newly available parents.
255
def test_sign_existing_revision(self):
256
wt = self.make_branch_and_tree('.')
258
wt.commit("base", allow_pointless=True, rev_id='A')
259
from bzrlib.testament import Testament
260
strategy = gpg.LoopbackGPGStrategy(None)
261
branch.repository.lock_write()
262
branch.repository.start_write_group()
263
branch.repository.sign_revision('A', strategy)
264
branch.repository.commit_write_group()
265
branch.repository.unlock()
266
self.assertEqual('-----BEGIN PSEUDO-SIGNED CONTENT-----\n' +
267
Testament.from_revision(branch.repository,
268
'A').as_short_text() +
269
'-----END PSEUDO-SIGNED CONTENT-----\n',
270
branch.repository.get_signature_text('A'))
272
def test_store_signature(self):
273
wt = self.make_branch_and_tree('.')
277
branch.repository.start_write_group()
279
branch.repository.store_revision_signature(
280
gpg.LoopbackGPGStrategy(None), 'FOO', 'A')
282
branch.repository.abort_write_group()
285
branch.repository.commit_write_group()
288
# A signature without a revision should not be accessible.
289
self.assertRaises(errors.NoSuchRevision,
290
branch.repository.has_signature_for_revision_id,
292
wt.commit("base", allow_pointless=True, rev_id='A')
293
self.assertEqual('-----BEGIN PSEUDO-SIGNED CONTENT-----\n'
294
'FOO-----END PSEUDO-SIGNED CONTENT-----\n',
295
branch.repository.get_signature_text('A'))
297
def test_branch_keeps_signatures(self):
298
wt = self.make_branch_and_tree('source')
299
wt.commit('A', allow_pointless=True, rev_id='A')
300
repo = wt.branch.repository
302
repo.start_write_group()
303
repo.sign_revision('A', gpg.LoopbackGPGStrategy(None))
304
repo.commit_write_group()
306
#FIXME: clone should work to urls,
307
# wt.clone should work to disks.
308
self.build_tree(['target/'])
309
d2 = repo.bzrdir.clone(urlutils.local_path_to_url('target'))
310
self.assertEqual(repo.get_signature_text('A'),
311
d2.open_repository().get_signature_text('A'))
313
255
def test_nicks_bzr(self):
314
256
"""Test the behaviour of branch nicks specific to bzr branches.
421
363
repo = self.make_repository('.', shared=True)
422
364
except errors.IncompatibleFormat:
365
raise tests.TestNotApplicable("requires shared repository support")
424
366
child_transport = repo.bzrdir.root_transport.clone('child')
425
367
child_transport.mkdir('.')
427
369
child_dir = self.bzrdir_format.initialize_on_transport(child_transport)
428
370
except errors.UninitializableFormat:
371
raise tests.TestNotApplicable("control dir format not initializable")
431
373
child_branch = self.branch_format.initialize(child_dir)
432
374
except errors.UninitializableFormat:
455
397
"""Create a fake revision history easily."""
456
398
tree = self.make_branch_and_tree('.')
457
399
rev1 = tree.commit('foo')
458
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]))
459
406
rev2 = tree.commit('bar', allow_pointless=True)
460
407
tree.branch.generate_revision_history(rev1)
461
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])))
463
412
def test_generate_revision_history_NULL_REVISION(self):
464
413
tree = self.make_branch_and_tree('.')
465
414
rev1 = tree.commit('foo')
416
self.addCleanup(tree.unlock)
466
417
tree.branch.generate_revision_history(revision.NULL_REVISION)
467
self.assertEqual([], tree.branch.revision_history())
418
self.assertEqual(revision.NULL_REVISION, tree.branch.last_revision())
469
420
def test_create_checkout(self):
470
421
tree_a = self.make_branch_and_tree('a')
491
442
tree_a = self.make_branch_and_tree('a')
492
443
rev_id = tree_a.commit('put some content in the branch')
493
444
# open the branch via a readonly transport
494
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)
495
450
# sanity check that the test will be valid
496
451
self.assertRaises((errors.LockError, errors.TransportNotPossible),
497
452
source_branch.lock_write)
503
458
tree_a = self.make_branch_and_tree('a')
504
459
rev_id = tree_a.commit('put some content in the branch')
505
460
# open the branch via a readonly transport
506
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)
507
467
# sanity check that the test will be valid
508
468
self.assertRaises((errors.LockError, errors.TransportNotPossible),
509
469
source_branch.lock_write)
591
551
_mod_branch.Branch.open_containing,
592
552
self.get_readonly_url('g/p/q'))
593
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")
594
557
branch, relpath = _mod_branch.Branch.open_containing(
595
558
self.get_readonly_url(''))
596
559
self.assertEqual('', relpath)
897
860
def test_fallbacks_not_opened(self):
898
861
stacked = self.make_branch_with_fallback()
899
862
self.get_transport('').rename('fallback', 'moved')
900
reopened = stacked.bzrdir.open_branch(ignore_fallbacks=True)
863
reopened_dir = bzrdir.BzrDir.open(stacked.base)
864
reopened = reopened_dir.open_branch(ignore_fallbacks=True)
901
865
self.assertEqual([], reopened.repository._fallback_repositories)
903
867
def test_fallbacks_are_opened(self):
904
868
stacked = self.make_branch_with_fallback()
905
reopened = stacked.bzrdir.open_branch(ignore_fallbacks=False)
869
reopened_dir = bzrdir.BzrDir.open(stacked.base)
870
reopened = reopened_dir.open_branch(ignore_fallbacks=False)
906
871
self.assertLength(1, reopened.repository._fallback_repositories)
916
881
tree.add_reference(subtree)
917
882
except errors.UnsupportedOperation:
918
883
raise tests.TestNotApplicable('Tree cannot hold references.')
919
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))
921
887
self.assertEqual(subtree.branch.base, reference_parent.base)
923
889
def test_reference_parent_accepts_possible_transports(self):
929
895
except errors.UnsupportedOperation:
930
896
raise tests.TestNotApplicable('Tree cannot hold references.')
931
897
reference_parent = tree.branch.reference_parent('subtree-id',
932
'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])
934
902
def test_get_reference_info(self):
935
903
branch = self.make_branch('branch')