187
184
self.assertEqual(branch_b.get_parent(), branch_c.get_parent())
189
186
# We can also set a specific parent, and it should be honored
190
random_parent = 'http://bazaar-vcs.org/path/to/branch'
187
random_parent = 'http://example.com/path/to/branch'
191
188
branch_b.set_parent(random_parent)
192
189
repo_d = self.make_repository('d')
193
190
branch_b.repository.copy_content_into(repo_d)
310
307
self.assertEqual(repo.get_signature_text('A'),
311
308
d2.open_repository().get_signature_text('A'))
313
def test_missing_revisions(self):
314
t1 = self.make_branch_and_tree('b1')
315
rev1 = t1.commit('one')
316
t2 = t1.bzrdir.sprout('b2').open_workingtree()
317
rev2 = t1.commit('two')
318
rev3 = t1.commit('three')
320
self.assertEqual([rev2, rev3],
321
self.applyDeprecated(deprecated_in((1, 6, 0)),
322
t2.branch.missing_revisions, t1.branch))
325
self.applyDeprecated(deprecated_in((1, 6, 0)),
326
t2.branch.missing_revisions, t1.branch, stop_revision=1))
327
self.assertEqual([rev2],
328
self.applyDeprecated(deprecated_in((1, 6, 0)),
329
t2.branch.missing_revisions, t1.branch, stop_revision=2))
330
self.assertEqual([rev2, rev3],
331
self.applyDeprecated(deprecated_in((1, 6, 0)),
332
t2.branch.missing_revisions, t1.branch, stop_revision=3))
334
self.assertRaises(errors.NoSuchRevision,
335
self.applyDeprecated, deprecated_in((1, 6, 0)),
336
t2.branch.missing_revisions, t1.branch, stop_revision=4)
338
rev4 = t2.commit('four')
339
self.assertRaises(errors.DivergedBranches,
340
self.applyDeprecated, deprecated_in((1, 6, 0)),
341
t2.branch.missing_revisions, t1.branch)
343
310
def test_nicks(self):
344
311
"""Test explicit and implicit branch nicknames.
347
314
explicit nickname is set. That is, an explicit nickname always
348
315
overrides the implicit one.
350
t = transport.get_transport(self.get_url())
317
t = self.get_transport()
351
318
branch = self.make_branch('bzr.dev')
352
319
# The nick will be 'bzr.dev', because there is no explicit nick set.
353
320
self.assertEqual(branch.nick, 'bzr.dev')
497
464
br.set_revision_history([])
498
465
self.assertEquals(br.revision_history(), [])
467
def test_heads_to_fetch(self):
468
# heads_to_fetch is a method that returns a collection of revids that
469
# need to be fetched to copy this branch into another repo. At a
470
# minimum this will include the tip.
471
# (In native formats, this is the tip + tags, but other formats may
472
# have other revs needed)
473
tree = self.make_branch_and_tree('a')
474
tree.commit('first commit', rev_id='rev1')
475
tree.commit('second commit', rev_id='rev2')
476
must_fetch, should_fetch = tree.branch.heads_to_fetch()
477
self.assertTrue('rev2' in must_fetch)
479
def test_heads_to_fetch_not_null_revision(self):
480
# NULL_REVISION does not appear in the result of heads_to_fetch, even
481
# for an empty branch.
482
tree = self.make_branch_and_tree('a')
483
must_fetch, should_fetch = tree.branch.heads_to_fetch()
484
self.assertFalse(revision.NULL_REVISION in must_fetch)
485
self.assertFalse(revision.NULL_REVISION in should_fetch)
501
488
class TestBranchFormat(per_branch.TestCaseWithBranch):
746
733
except errors.UpgradeRequired:
747
734
raise tests.TestNotApplicable('Format does not support binding')
736
def test_unbind_clears_cached_master_branch(self):
737
"""b.unbind clears any cached value of b.get_master_branch."""
738
master = self.make_branch('master')
739
branch = self.make_branch('branch')
742
except errors.UpgradeRequired:
743
raise tests.TestNotApplicable('Format does not support binding')
744
self.addCleanup(branch.lock_write().unlock)
745
self.assertNotEqual(None, branch.get_master_branch())
747
self.assertEqual(None, branch.get_master_branch())
749
def test_unlocked_does_not_cache_master_branch(self):
750
"""Unlocked branches do not cache the result of get_master_branch."""
751
master = self.make_branch('master')
752
branch1 = self.make_branch('branch')
755
except errors.UpgradeRequired:
756
raise tests.TestNotApplicable('Format does not support binding')
758
branch2 = branch1.bzrdir.open_branch()
759
self.assertNotEqual(None, branch1.get_master_branch())
760
# Unbind the branch via branch2. branch1 isn't locked so will
761
# immediately return the new value for get_master_branch.
763
self.assertEqual(None, branch1.get_master_branch())
765
def test_bind_clears_cached_master_branch(self):
766
"""b.bind clears any cached value of b.get_master_branch."""
767
master1 = self.make_branch('master1')
768
master2 = self.make_branch('master2')
769
branch = self.make_branch('branch')
772
except errors.UpgradeRequired:
773
raise tests.TestNotApplicable('Format does not support binding')
774
self.addCleanup(branch.lock_write().unlock)
775
self.assertNotEqual(None, branch.get_master_branch())
777
self.assertEqual('.', urlutils.relative_url(self.get_url('master2'),
778
branch.get_master_branch().base))
780
def test_set_bound_location_clears_cached_master_branch(self):
781
"""b.set_bound_location clears any cached value of b.get_master_branch.
783
master1 = self.make_branch('master1')
784
master2 = self.make_branch('master2')
785
branch = self.make_branch('branch')
788
except errors.UpgradeRequired:
789
raise tests.TestNotApplicable('Format does not support binding')
790
self.addCleanup(branch.lock_write().unlock)
791
self.assertNotEqual(None, branch.get_master_branch())
792
branch.set_bound_location(self.get_url('master2'))
793
self.assertEqual('.', urlutils.relative_url(self.get_url('master2'),
794
branch.get_master_branch().base))
750
797
class TestStrict(per_branch.TestCaseWithBranch):