~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge.py

  • Committer: Patch Queue Manager
  • Date: 2011-12-21 15:32:34 UTC
  • mfrom: (6388.1.8 merge-hooks)
  • Revision ID: pqm@pqm.ubuntu.com-20111221153234-kbq1axff8pe224vt
(jelmer) Add pre_merge and post_merge hooks in Merger.hooks. (Jelmer
 Vernooij)

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(self):
 
3250
        super(TestMergeHooks, self).setUp()
 
3251
        self.tree_a = self.make_branch_and_tree('tree_a')
 
3252
        self.build_tree_contents([('tree_a/file', 'content_1')])
 
3253
        self.tree_a.add('file', 'file-id')
 
3254
        self.tree_a.commit('added file')
 
3255
 
 
3256
        self.tree_b = self.tree_a.bzrdir.sprout('tree_b').open_workingtree()
 
3257
        self.build_tree_contents([('tree_b/file', 'content_2')])
 
3258
        self.tree_b.commit('modify file')
 
3259
 
 
3260
    def test_pre_merge_hook_inject_different_tree(self):
 
3261
        tree_c = self.tree_b.bzrdir.sprout('tree_c').open_workingtree()
 
3262
        self.build_tree_contents([('tree_c/file', 'content_3')])
 
3263
        tree_c.commit("more content")
 
3264
        calls = []
 
3265
        def factory(merger):
 
3266
            self.assertIsInstance(merger, _mod_merge.Merge3Merger)
 
3267
            merger.other_tree = tree_c
 
3268
            calls.append(merger)
 
3269
        _mod_merge.Merger.hooks.install_named_hook('pre_merge',
 
3270
                                                   factory, 'test factory')
 
3271
        self.tree_a.merge_from_branch(self.tree_b.branch)
 
3272
 
 
3273
        self.assertFileEqual("content_3", 'tree_a/file')
 
3274
        self.assertLength(1, calls)
 
3275
 
 
3276
    def test_post_merge_hook_called(self):
 
3277
        calls = []
 
3278
        def factory(merger):
 
3279
            self.assertIsInstance(merger, _mod_merge.Merge3Merger)
 
3280
            calls.append(merger)
 
3281
        _mod_merge.Merger.hooks.install_named_hook('post_merge',
 
3282
                                                   factory, 'test factory')
 
3283
 
 
3284
        self.tree_a.merge_from_branch(self.tree_b.branch)
 
3285
 
 
3286
        self.assertFileEqual("content_2", 'tree_a/file')
 
3287
        self.assertLength(1, calls)