72
73
[('set_rh', branch, [], True),
73
74
('set_rh', branch, [], True),
78
class TestPostChangeBranchTip(TestCaseWithMemoryTransport):
82
TestCaseWithMemoryTransport.setUp(self)
84
def capture_post_change_branch_tip_hook(self, params):
85
"""Capture post_change_branch_tip hook calls to self.hook_calls.
87
The call is logged, as is some state of the branch.
89
self.hook_calls.append((params, params.branch.is_locked()))
90
self.assertEquals(params.branch.last_revision_info(),
91
(params.new_revno, params.new_revid))
93
def test_post_change_branch_tip_empty_history(self):
94
branch = self.make_branch('source')
95
Branch.hooks.install_hook('post_change_branch_tip',
96
self.capture_post_change_branch_tip_hook)
97
branch.set_last_revision_info(0, NULL_REVISION)
98
self.assertEqual(len(self.hook_calls), 1)
99
self.assertEqual(self.hook_calls[0][0].branch, branch)
100
self.assertEqual(self.hook_calls[0][0].old_revid, NULL_REVISION)
101
self.assertEqual(self.hook_calls[0][0].old_revno, 0)
102
self.assertEqual(self.hook_calls[0][0].new_revid, NULL_REVISION)
103
self.assertEqual(self.hook_calls[0][0].new_revno, 0)
105
def test_post_change_branch_tip_nonempty_history(self):
106
tree = self.make_branch_and_memory_tree('source')
109
tree.commit('another commit', rev_id='f\xc2\xb5')
110
tree.commit('empty commit', rev_id='foo')
113
Branch.hooks.install_hook('post_change_branch_tip',
114
self.capture_post_change_branch_tip_hook)
115
# some branches require that their history be set to a revision in the
117
branch.set_last_revision_info(1, 'f\xc2\xb5')
118
self.assertEqual(len(self.hook_calls), 1)
119
self.assertEqual(self.hook_calls[0][0].branch, branch)
120
self.assertEqual(self.hook_calls[0][0].old_revid, 'foo')
121
self.assertEqual(self.hook_calls[0][0].old_revno, 2)
122
self.assertEqual(self.hook_calls[0][0].new_revid, 'f\xc2\xb5')
123
self.assertEqual(self.hook_calls[0][0].new_revno, 1)
125
def test_post_change_branch_tip_branch_is_locked(self):
126
branch = self.make_branch('source')
127
Branch.hooks.install_hook('post_change_branch_tip',
128
self.capture_post_change_branch_tip_hook)
129
branch.set_last_revision_info(0, NULL_REVISION)
130
self.assertEqual(len(self.hook_calls), 1)
131
self.assertEqual(self.hook_calls[0][0].branch, branch)
132
self.assertEqual(self.hook_calls[0][1], True)
134
def test_post_change_branch_tip_calls_all_hooks_no_errors(self):
135
branch = self.make_branch('source')
136
Branch.hooks.install_hook('post_change_branch_tip',
137
self.capture_post_change_branch_tip_hook)
138
Branch.hooks.install_hook('post_change_branch_tip',
139
self.capture_post_change_branch_tip_hook)
140
branch.set_last_revision_info(0, NULL_REVISION)
141
self.assertEqual(len(self.hook_calls), 2)
142
self.assertEqual(self.hook_calls[0][0].branch, branch)
143
self.assertEqual(self.hook_calls[1][0].branch, branch)