193
193
class TestHookMergeFileContent(TestCaseWithTransport):
194
194
"""Tests that the 'merge_file_content' hook is invoked."""
196
def install_hook_merge_file_content(self):
196
def install_hook_noop(self):
197
197
def hook_na(merge_params):
198
198
# This hook unconditionally does nothing.
199
199
return 'not_applicable', None
200
200
_mod_merge.Merger.hooks.install_named_hook(
201
201
'merge_file_content', hook_na, 'test hook (n/a)')
203
def install_hook_success(self):
202
204
def hook_success(merge_params):
203
205
if merge_params.file_id == '1':
204
206
return 'success', ['text-merged-by-hook']
206
208
_mod_merge.Merger.hooks.install_named_hook(
207
209
'merge_file_content', hook_success, 'test hook (success)')
211
def install_hook_delete(self):
212
def hook_delete(merge_params):
213
if merge_params.file_id == '1':
214
return 'delete', None
215
return 'not_applicable', None
216
_mod_merge.Merger.hooks.install_named_hook(
217
'merge_file_content', hook_delete, 'test hook (delete)')
209
219
def make_merge_builder(self):
210
220
builder = MergeBuilder(self.test_base_dir)
211
221
self.addCleanup(builder.cleanup)
214
def test_hook_merge_file_content(self):
215
self.install_hook_merge_file_content()
224
def test_change_vs_change(self):
225
"""Hook is used for (changed, changed)"""
226
self.install_hook_success()
216
227
builder = self.make_merge_builder()
217
228
builder.add_file("1", builder.tree_root, "name1", "text1", True)
218
229
builder.change_contents("1", other="text4", this="text3")
221
232
self.assertEqual(
222
233
builder.this.get_file('1').read(), 'text-merged-by-hook')
235
def test_change_vs_deleted(self):
236
"""Hook is used for (changed, deleted)"""
237
self.install_hook_success()
238
builder = self.make_merge_builder()
239
builder.add_file("1", builder.tree_root, "name1", "text1", True)
240
builder.change_contents("1", this="text2")
241
builder.remove_file("1", other=True)
242
conflicts = builder.merge(self.merge_type)
243
self.assertEqual(conflicts, [])
245
builder.this.get_file('1').read(), 'text-merged-by-hook')
247
def test_result_can_be_delete(self):
248
"""A hook's result can be the deletion of a file."""
249
self.install_hook_delete()
250
builder = self.make_merge_builder()
251
builder.add_file("1", builder.tree_root, "name1", "text1", True)
252
builder.change_contents("1", this="text2", other="text3")
253
conflicts = builder.merge(self.merge_type)
254
self.assertEqual(conflicts, [])
255
self.assertRaises(errors.NoSuchId, builder.this.id2path, '1')