/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
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
22
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
23
24
25
class TestMergeFromBranch(TestCaseWithWorkingTree):
26
27
    def create_two_trees_for_merging(self):
28
        """Create two trees that can be merged from.
29
30
        This sets self.tree_from, self.first_rev, self.tree_to, self.second_rev
31
        and self.to_second_rev.
32
        """
33
        self.tree_from = self.make_branch_and_tree('from')
34
        self.first_rev = self.tree_from.commit('first post')
35
        self.tree_to = self.tree_from.bzrdir.sprout('to').open_workingtree()
36
        self.second_rev = self.tree_from.commit('second rev', allow_pointless=True)
37
        self.to_second_rev = self.tree_to.commit('second rev', allow_pointless=True)
38
39
    def test_smoking_merge(self):
40
        """Smoke test of merge_from_branch."""
41
        self.create_two_trees_for_merging()
42
        self.tree_to.merge_from_branch(self.tree_from.branch)
43
        self.assertEqual([self.to_second_rev, self.second_rev],
44
            self.tree_to.get_parent_ids())
45
46
    def test_merge_to_revision(self):
47
        """Merge from a branch to a revision that is not the tip."""
48
        self.create_two_trees_for_merging()
49
        self.third_rev = self.tree_from.commit('real_tip')
50
        self.tree_to.merge_from_branch(self.tree_from.branch,
51
            to_revision=self.second_rev)
52
        self.assertEqual([self.to_second_rev, self.second_rev],
53
            self.tree_to.get_parent_ids())
1551.10.31 by Aaron Bentley
Fix WorkingTree4._iter_changes with pending merges and deleted files
54
55
    def test_compare_after_merge(self):
56
        tree_a = self.make_branch_and_tree('tree_a')
57
        self.build_tree_contents([('tree_a/file', 'text-a')])
58
        tree_a.add('file')
59
        tree_a.commit('added file')
60
        tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
61
        os.unlink('tree_a/file')
62
        tree_a.commit('deleted file')
63
        self.build_tree_contents([('tree_b/file', 'text-b')])
64
        tree_b.commit('changed file')
65
        tree_a.merge_from_branch(tree_b.branch)
66
        tree_a.lock_read()
67
        self.addCleanup(tree_a.unlock)
68
        list(tree_a._iter_changes(tree_a.basis_tree()))