/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
1
# Copyright (C) 2006 Canonical Ltd
2
# Authors:  Robert Collins <robert.collins@canonical.com>
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
"""Tests for the WorkingTree.merge_from_branch api."""
19
1551.10.31 by Aaron Bentley
Fix WorkingTree4._iter_changes with pending merges and deleted files
20
import os
21
1551.15.69 by Aaron Bentley
Add merge_type to merge_from_branch
22
from bzrlib import (
23
    errors,
24
    merge
25
    )
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
26
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
27
28
29
class TestMergeFromBranch(TestCaseWithWorkingTree):
30
31
    def create_two_trees_for_merging(self):
32
        """Create two trees that can be merged from.
33
34
        This sets self.tree_from, self.first_rev, self.tree_to, self.second_rev
35
        and self.to_second_rev.
36
        """
37
        self.tree_from = self.make_branch_and_tree('from')
38
        self.first_rev = self.tree_from.commit('first post')
39
        self.tree_to = self.tree_from.bzrdir.sprout('to').open_workingtree()
40
        self.second_rev = self.tree_from.commit('second rev', allow_pointless=True)
41
        self.to_second_rev = self.tree_to.commit('second rev', allow_pointless=True)
42
43
    def test_smoking_merge(self):
44
        """Smoke test of merge_from_branch."""
45
        self.create_two_trees_for_merging()
46
        self.tree_to.merge_from_branch(self.tree_from.branch)
47
        self.assertEqual([self.to_second_rev, self.second_rev],
48
            self.tree_to.get_parent_ids())
49
50
    def test_merge_to_revision(self):
51
        """Merge from a branch to a revision that is not the tip."""
52
        self.create_two_trees_for_merging()
53
        self.third_rev = self.tree_from.commit('real_tip')
54
        self.tree_to.merge_from_branch(self.tree_from.branch,
55
            to_revision=self.second_rev)
56
        self.assertEqual([self.to_second_rev, self.second_rev],
57
            self.tree_to.get_parent_ids())
1551.10.31 by Aaron Bentley
Fix WorkingTree4._iter_changes with pending merges and deleted files
58
59
    def test_compare_after_merge(self):
60
        tree_a = self.make_branch_and_tree('tree_a')
61
        self.build_tree_contents([('tree_a/file', 'text-a')])
62
        tree_a.add('file')
63
        tree_a.commit('added file')
64
        tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
65
        os.unlink('tree_a/file')
66
        tree_a.commit('deleted file')
67
        self.build_tree_contents([('tree_b/file', 'text-b')])
68
        tree_b.commit('changed file')
69
        tree_a.merge_from_branch(tree_b.branch)
70
        tree_a.lock_read()
71
        self.addCleanup(tree_a.unlock)
72
        list(tree_a._iter_changes(tree_a.basis_tree()))
2490.2.28 by Aaron Bentley
Fix handling of null revision
73
74
    def test_merge_empty(self):
75
        tree_a = self.make_branch_and_tree('tree_a')
76
        self.build_tree_contents([('tree_a/file', 'text-a')])
77
        tree_a.add('file')
78
        tree_a.commit('added file')
79
        tree_b = self.make_branch_and_tree('treeb')
80
        self.assertRaises(errors.NoCommits, tree_a.merge_from_branch,
81
                          tree_b.branch)
82
        tree_b.merge_from_branch(tree_a.branch)
1551.15.68 by Aaron Bentley
Add support for base to merge_from_branch
83
84
    def test_merge_base(self):
85
        tree_a = self.make_branch_and_tree('tree_a')
86
        self.build_tree_contents([('tree_a/file', 'text-a')])
87
        tree_a.add('file')
88
        tree_a.commit('added file', rev_id='rev_1')
89
        tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
90
        os.unlink('tree_a/file')
91
        tree_a.commit('deleted file')
92
        self.build_tree_contents([('tree_b/file', 'text-b')])
93
        tree_b.commit('changed file')
94
        self.assertRaises(errors.PointlessMerge, tree_a.merge_from_branch,
95
            tree_b.branch, from_revision=tree_b.branch.last_revision())
96
        tree_a.merge_from_branch(tree_b.branch, from_revision='rev_1')
97
        tree_a.lock_read()
98
        self.addCleanup(tree_a.unlock)
99
        changes = list(tree_a._iter_changes(tree_a.basis_tree()))
100
        self.assertEqual(1, len(changes))
1551.15.69 by Aaron Bentley
Add merge_type to merge_from_branch
101
102
    def test_merge_type(self):
103
        this = self.make_branch_and_tree('this')
104
        self.build_tree_contents([('this/foo', 'foo')])
105
        this.add('foo', 'foo-id')
106
        this.commit('added foo')
107
        other = this.bzrdir.sprout('other').open_workingtree()
108
        self.build_tree_contents([('other/foo', 'bar')])
109
        other.commit('content -> bar')
110
        self.build_tree_contents([('this/foo', 'baz')])
111
        this.commit('content -> baz')
112
        class QuxMerge(merge.Merge3Merger):
113
            def text_merge(self, file_id, trans_id):
114
                self.tt.create_file('qux', trans_id)
115
        this.merge_from_branch(other.branch, merge_type=QuxMerge)
116
        self.assertEqual('qux', this.get_file_text('foo-id'))