59
62
def test_set_rh_branch_is_locked(self):
60
63
branch = self.make_branch('source')
61
Branch.hooks.install_hook('set_rh', self.capture_set_rh_hook)
64
Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
62
66
branch.set_revision_history([])
63
67
self.assertEqual(self.hook_calls,
64
68
[('set_rh', branch, [], True)])
66
70
def test_set_rh_calls_all_hooks_no_errors(self):
67
71
branch = self.make_branch('source')
68
Branch.hooks.install_hook('set_rh', self.capture_set_rh_hook)
69
Branch.hooks.install_hook('set_rh', self.capture_set_rh_hook)
72
Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
74
Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
70
76
branch.set_revision_history([])
71
77
self.assertEqual(self.hook_calls,
72
78
[('set_rh', branch, [], True),
73
79
('set_rh', branch, [], True),
83
class TestPostChangeBranchTip(TestCaseWithMemoryTransport):
87
TestCaseWithMemoryTransport.setUp(self)
89
def capture_post_change_branch_tip_hook(self, params):
90
"""Capture post_change_branch_tip hook calls to self.hook_calls.
92
The call is logged, as is some state of the branch.
94
self.hook_calls.append((params, params.branch.is_locked()))
95
self.assertEquals(params.branch.last_revision_info(),
96
(params.new_revno, params.new_revid))
98
def test_post_change_branch_tip_empty_history(self):
99
branch = self.make_branch('source')
100
Branch.hooks.install_named_hook(
101
'post_change_branch_tip',
102
self.capture_post_change_branch_tip_hook,
104
branch.set_last_revision_info(0, NULL_REVISION)
105
self.assertEqual(len(self.hook_calls), 1)
106
self.assertEqual(self.hook_calls[0][0].branch, branch)
107
self.assertEqual(self.hook_calls[0][0].old_revid, NULL_REVISION)
108
self.assertEqual(self.hook_calls[0][0].old_revno, 0)
109
self.assertEqual(self.hook_calls[0][0].new_revid, NULL_REVISION)
110
self.assertEqual(self.hook_calls[0][0].new_revno, 0)
112
def test_post_change_branch_tip_nonempty_history(self):
113
tree = self.make_branch_and_memory_tree('source')
116
tree.commit('another commit', rev_id='f\xc2\xb5')
117
tree.commit('empty commit', rev_id='foo')
120
Branch.hooks.install_named_hook(
121
'post_change_branch_tip',
122
self.capture_post_change_branch_tip_hook,
124
# some branches require that their history be set to a revision in the
126
branch.set_last_revision_info(1, 'f\xc2\xb5')
127
self.assertEqual(len(self.hook_calls), 1)
128
self.assertEqual(self.hook_calls[0][0].branch, branch)
129
self.assertEqual(self.hook_calls[0][0].old_revid, 'foo')
130
self.assertEqual(self.hook_calls[0][0].old_revno, 2)
131
self.assertEqual(self.hook_calls[0][0].new_revid, 'f\xc2\xb5')
132
self.assertEqual(self.hook_calls[0][0].new_revno, 1)
134
def test_post_change_branch_tip_branch_is_locked(self):
135
branch = self.make_branch('source')
136
Branch.hooks.install_named_hook(
137
'post_change_branch_tip',
138
self.capture_post_change_branch_tip_hook,
140
branch.set_last_revision_info(0, NULL_REVISION)
141
self.assertEqual(len(self.hook_calls), 1)
142
self.assertEqual(self.hook_calls[0][0].branch, branch)
143
self.assertEqual(self.hook_calls[0][1], True)
145
def test_post_change_branch_tip_calls_all_hooks_no_errors(self):
146
branch = self.make_branch('source')
147
Branch.hooks.install_named_hook(
148
'post_change_branch_tip',
149
self.capture_post_change_branch_tip_hook,
151
Branch.hooks.install_named_hook(
152
'post_change_branch_tip',
153
self.capture_post_change_branch_tip_hook,
155
branch.set_last_revision_info(0, NULL_REVISION)
156
self.assertEqual(len(self.hook_calls), 2)
157
self.assertEqual(self.hook_calls[0][0].branch, branch)
158
self.assertEqual(self.hook_calls[1][0].branch, branch)