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