3247
3247
class TestMergeHooks(TestCaseWithTransport):
3250
super(TestMergeHooks, self).setUp()
3251
self.tree_a = self.make_branch_and_tree('tree_a')
3249
def setup_trees_to_merge(self):
3250
tree_a = self.make_branch_and_tree('tree_a')
3252
3251
self.build_tree_contents([('tree_a/file', 'content_1')])
3253
self.tree_a.add('file', 'file-id')
3254
self.tree_a.commit('added file')
3252
tree_a.add('file', 'file-id')
3253
tree_a.commit('added file')
3256
self.tree_b = self.tree_a.bzrdir.sprout('tree_b').open_workingtree()
3255
tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
3257
3256
self.build_tree_contents([('tree_b/file', 'content_2')])
3258
self.tree_b.commit('modify file')
3257
tree_b.commit('modify file')
3258
return tree_a, tree_b
3260
def test_pre_merge_hook_inject_different_tree(self):
3261
tree_c = self.tree_b.bzrdir.sprout('tree_c').open_workingtree()
3260
def test_pre_merge(self):
3261
tree_a, tree_b = self.setup_trees_to_merge()
3262
tree_c = tree_b.bzrdir.sprout('tree_c').open_workingtree()
3262
3263
self.build_tree_contents([('tree_c/file', 'content_3')])
3263
3264
tree_c.commit("more content")
3268
3269
calls.append(merger)
3269
3270
_mod_merge.Merger.hooks.install_named_hook('pre_merge',
3270
3271
factory, 'test factory')
3271
self.tree_a.merge_from_branch(self.tree_b.branch)
3272
tree_a.merge_from_branch(tree_b.branch)
3273
3274
self.assertFileEqual("content_3", 'tree_a/file')
3274
3276
self.assertLength(1, calls)
3276
def test_post_merge_hook_called(self):
3278
def test_post_merge(self):
3278
3280
def factory(merger):
3279
3281
self.assertIsInstance(merger, _mod_merge.Merge3Merger)
3281
3283
_mod_merge.Merger.hooks.install_named_hook('post_merge',
3282
3284
factory, 'test factory')
3284
self.tree_a.merge_from_branch(self.tree_b.branch)
3286
tree_a, tree_b = self.setup_trees_to_merge()
3287
tree_a.merge_from_branch(tree_b.branch)
3286
3289
self.assertFileEqual("content_2", 'tree_a/file')
3287
3291
self.assertLength(1, calls)