70
70
self.assertEqual([expected_params], hook_calls)
73
class TestSetRevisionHistoryHook(ChangeBranchTipTestCase):
77
super(TestSetRevisionHistoryHook, self).setUp()
79
def capture_set_rh_hook(self, branch, rev_history):
80
"""Capture post set-rh hook calls to self.hook_calls.
82
The call is logged, as is some state of the branch.
84
self.hook_calls.append(
85
('set_rh', branch, rev_history, branch.is_locked()))
87
def test_set_rh_empty_history(self):
88
branch = self.make_branch('source')
89
_mod_branch.Branch.hooks.install_named_hook(
90
'set_rh', self.capture_set_rh_hook, None)
91
self.applyDeprecated(deprecated_in((2, 4, 0)),
92
branch.set_revision_history, [])
93
expected_params = ('set_rh', branch, [], True)
94
self.assertHookCalls(expected_params, branch)
96
def test_set_rh_nonempty_history(self):
97
tree = self.make_branch_and_memory_tree('source')
100
tree.commit('another commit', rev_id='f\xc2\xb5')
101
tree.commit('empty commit', rev_id='foo')
104
_mod_branch.Branch.hooks.install_named_hook(
105
'set_rh', self.capture_set_rh_hook, None)
106
# some branches require that their history be set to a revision in the
108
self.applyDeprecated(deprecated_in((2, 4, 0)),
109
branch.set_revision_history, ['f\xc2\xb5'])
110
expected_params =('set_rh', branch, ['f\xc2\xb5'], True)
111
self.assertHookCalls(expected_params, branch)
113
def test_set_rh_branch_is_locked(self):
114
branch = self.make_branch('source')
115
_mod_branch.Branch.hooks.install_named_hook(
116
'set_rh', self.capture_set_rh_hook, None)
117
self.applyDeprecated(deprecated_in((2, 4, 0)),
118
branch.set_revision_history, [])
119
expected_params = ('set_rh', branch, [], True)
120
self.assertHookCalls(expected_params, branch)
122
def test_set_rh_calls_all_hooks_no_errors(self):
123
branch = self.make_branch('source')
124
_mod_branch.Branch.hooks.install_named_hook(
125
'set_rh', self.capture_set_rh_hook, None)
126
_mod_branch.Branch.hooks.install_named_hook(
127
'set_rh', self.capture_set_rh_hook, None)
128
self.applyDeprecated(deprecated_in((2, 4, 0)),
129
branch.set_revision_history, [])
130
expected_calls = [('set_rh', branch, [], True),
131
('set_rh', branch, [], True),
133
if isinstance(branch, remote.RemoteBranch):
134
# For a remote branch, both the server and the client will raise
135
# set_rh, and the server will do so first because that is where
136
# the change takes place.
137
self.assertEqual(expected_calls, self.hook_calls[2:])
138
self.assertEqual(4, len(self.hook_calls))
140
self.assertEqual(expected_calls, self.hook_calls)
143
73
class TestOpen(tests.TestCaseWithMemoryTransport):
145
75
def capture_hook(self, branch):
389
319
self.assertEqual(length, len(self.pre_hook_calls))
390
320
self.assertEqual(length, len(self.post_hook_calls))
392
def test_set_revision_history(self):
393
branch = self.make_branch('')
394
self.applyDeprecated(deprecated_in((2, 4, 0)),
395
branch.set_revision_history, [])
396
self.assertPreAndPostHooksWereInvoked(branch, True)
398
322
def test_set_last_revision_info(self):
399
323
branch = self.make_branch('')
400
324
branch.set_last_revision_info(0, revision.NULL_REVISION)