~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge.py

  • Committer: Jelmer Vernooij
  • Date: 2011-12-20 12:47:20 UTC
  • mto: This revision was merged to the branch mainline in revision 6395.
  • Revision ID: jelmer@canonical.com-20111220124720-kya9ilr0dle3tve2
Add pre and post merge hooks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3242
3242
        # The dest tree is unmodified.
3243
3243
        self.assertEqual(['r1-dest'], dest_wt.get_parent_ids())
3244
3244
        self.assertTreeEntriesEqual([('', 'dest-root-id')], dest_wt)
 
3245
 
 
3246
 
 
3247
class TestMergeHooks(TestCaseWithTransport):
 
3248
 
 
3249
    def setup_trees_to_merge(self):
 
3250
        tree_a = self.make_branch_and_tree('tree_a')
 
3251
        self.build_tree_contents([('tree_a/file', 'content_1')])
 
3252
        tree_a.add('file', 'file-id')
 
3253
        tree_a.commit('added file')
 
3254
 
 
3255
        tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
 
3256
        self.build_tree_contents([('tree_b/another-file', 'content_2')])
 
3257
        tree_b.add('another-file', 'another-file-id')
 
3258
        tree_b.commit('add another file')
 
3259
        return tree_a, tree_b
 
3260
 
 
3261
    def test_pre_merge(self):
 
3262
        calls = []
 
3263
        def factory(pre_merge_args):
 
3264
            calls.append(pre_merge_args)
 
3265
        _mod_merge.Merger.hooks.install_named_hook('pre_merge',
 
3266
                                                   factory, 'test factory')
 
3267
        tree_a, tree_b = self.setup_trees_to_merge()
 
3268
        tree_a.merge_from_branch(tree_b.branch)
 
3269
 
 
3270
        self.assertLength(1, calls)
 
3271
 
 
3272
    def test_post_merge(self):
 
3273
        calls = []
 
3274
        def factory(post_merge_args):
 
3275
            self.assertIsInstance(post_merge_args, _mod_merge.Merge3Merger)
 
3276
            calls.append(post_merge_args)
 
3277
        _mod_merge.Merger.hooks.install_named_hook('post_merge',
 
3278
                                                   factory, 'test factory')
 
3279
 
 
3280
        tree_a, tree_b = self.setup_trees_to_merge()
 
3281
        tree_a.merge_from_branch(tree_b.branch)
 
3282
 
 
3283
        self.assertLength(1, calls)