17
17
"""Tests that branch classes implement hook callouts correctly."""
19
from bzrlib.branch import Branch, ChangeBranchTipParams
19
20
from bzrlib.errors import HookFailed, TipChangeRejected
20
from bzrlib.branch import Branch, ChangeBranchTipParams
21
from bzrlib.remote import RemoteBranch
21
22
from bzrlib.revision import NULL_REVISION
22
23
from bzrlib.tests import TestCaseWithMemoryTransport
111
class TestOpen(TestCaseWithMemoryTransport):
113
def capture_hook(self, branch):
114
self.hook_calls.append(branch)
116
def install_hook(self):
118
Branch.hooks.install_named_hook('open', self.capture_hook, None)
120
def test_create(self):
122
b = self.make_branch('.')
123
self.assertEqual([b], self.hook_calls)
126
branch_url = self.make_branch('.').bzrdir.root_transport.base
128
b = Branch.open(branch_url)
129
if isinstance(b, RemoteBranch):
130
# RemoteBranch open always opens the backing branch to get stacking
131
# details. As that is done remotely we can't see the branch object
132
# nor even compare base url's etc. So we just assert that the first
133
# branch returned is the RemoteBranch, and that the second is a
134
# Branch but not a RemoteBranch.
135
self.assertEqual(2, len(self.hook_calls))
136
self.assertEqual(b, self.hook_calls[0])
137
self.assertIsInstance(self.hook_calls[1], Branch)
138
self.assertFalse(isinstance(self.hook_calls[1], RemoteBranch))
140
self.assertEqual([b], self.hook_calls)
110
143
class TestPreChangeBranchTip(ChangeBranchTipTestCase):
111
144
"""Tests for pre_change_branch_tip hook.