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