70
69
self.assertEqual([expected_params], hook_calls)
72
class TestSetRevisionHistoryHook(ChangeBranchTipTestCase):
76
super(TestSetRevisionHistoryHook, self).setUp()
78
def capture_set_rh_hook(self, branch, rev_history):
79
"""Capture post set-rh hook calls to self.hook_calls.
81
The call is logged, as is some state of the branch.
83
self.hook_calls.append(
84
('set_rh', branch, rev_history, branch.is_locked()))
86
def test_set_rh_empty_history(self):
87
branch = self.make_branch('source')
88
_mod_branch.Branch.hooks.install_named_hook(
89
'set_rh', self.capture_set_rh_hook, None)
90
branch.set_revision_history([])
91
expected_params = ('set_rh', branch, [], True)
92
self.assertHookCalls(expected_params, branch)
94
def test_set_rh_nonempty_history(self):
95
tree = self.make_branch_and_memory_tree('source')
98
tree.commit('another commit', rev_id='f\xc2\xb5')
99
tree.commit('empty commit', rev_id='foo')
102
_mod_branch.Branch.hooks.install_named_hook(
103
'set_rh', self.capture_set_rh_hook, None)
104
# some branches require that their history be set to a revision in the
106
branch.set_revision_history(['f\xc2\xb5'])
107
expected_params =('set_rh', branch, ['f\xc2\xb5'], True)
108
self.assertHookCalls(expected_params, branch)
110
def test_set_rh_branch_is_locked(self):
111
branch = self.make_branch('source')
112
_mod_branch.Branch.hooks.install_named_hook(
113
'set_rh', self.capture_set_rh_hook, None)
114
branch.set_revision_history([])
115
expected_params = ('set_rh', branch, [], True)
116
self.assertHookCalls(expected_params, branch)
118
def test_set_rh_calls_all_hooks_no_errors(self):
119
branch = self.make_branch('source')
120
_mod_branch.Branch.hooks.install_named_hook(
121
'set_rh', self.capture_set_rh_hook, None)
122
_mod_branch.Branch.hooks.install_named_hook(
123
'set_rh', self.capture_set_rh_hook, None)
124
branch.set_revision_history([])
125
expected_calls = [('set_rh', branch, [], True),
126
('set_rh', branch, [], True),
128
if isinstance(branch, remote.RemoteBranch):
129
# For a remote branch, both the server and the client will raise
130
# set_rh, and the server will do so first because that is where
131
# the change takes place.
132
self.assertEqual(expected_calls, self.hook_calls[2:])
133
self.assertEqual(4, len(self.hook_calls))
135
self.assertEqual(expected_calls, self.hook_calls)
73
138
class TestOpen(tests.TestCaseWithMemoryTransport):
75
140
def capture_hook(self, branch):
319
384
self.assertEqual(length, len(self.pre_hook_calls))
320
385
self.assertEqual(length, len(self.post_hook_calls))
387
def test_set_revision_history(self):
388
branch = self.make_branch('')
389
branch.set_revision_history([])
390
self.assertPreAndPostHooksWereInvoked(branch, True)
322
392
def test_set_last_revision_info(self):
323
393
branch = self.make_branch('')
324
394
branch.set_last_revision_info(0, revision.NULL_REVISION)