~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge.py

  • Committer: John Arbash Meinel
  • Date: 2006-03-08 14:31:23 UTC
  • mfrom: (1598 +trunk)
  • mto: (1685.1.1 bzr-encoding)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060308143123-448308b0db4de410
[merge] bzr.dev 1573, lots of updates

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
from StringIO import StringIO
 
3
 
 
4
from bzrlib.branch import Branch
 
5
from bzrlib.builtins import merge
 
6
from bzrlib.commit import commit
 
7
from bzrlib.errors import UnrelatedBranches, NoCommits, BzrCommandError
 
8
from bzrlib.merge import transform_tree, merge_inner
 
9
from bzrlib.osutils import pathjoin
 
10
from bzrlib.revision import common_ancestor
 
11
from bzrlib.tests import TestCaseWithTransport
 
12
from bzrlib.trace import (enable_test_log, disable_test_log)
 
13
from bzrlib.workingtree import WorkingTree
 
14
 
 
15
 
 
16
class TestMerge(TestCaseWithTransport):
 
17
    """Test appending more than one revision"""
 
18
 
 
19
    def test_pending(self):
 
20
        wt = self.make_branch_and_tree('.')
 
21
        wt.commit("lala!")
 
22
        self.assertEquals(len(wt.pending_merges()), 0)
 
23
        merge([u'.', -1], [None, None])
 
24
        self.assertEquals(len(wt.pending_merges()), 0)
 
25
 
 
26
    def test_nocommits(self):
 
27
        self.test_pending()
 
28
        wt2 = self.make_branch_and_tree('branch2')
 
29
        self.assertRaises(NoCommits, merge, ['branch2', -1], 
 
30
                          [None, None])
 
31
        return wt2
 
32
 
 
33
    def test_unrelated(self):
 
34
        wt2 = self.test_nocommits()
 
35
        wt2.commit("blah")
 
36
        self.assertRaises(UnrelatedBranches, merge, ['branch2', -1], 
 
37
                          [None, None])
 
38
        return wt2
 
39
 
 
40
    def test_pending_with_null(self):
 
41
        """When base is forced to revno 0, pending_merges is set"""
 
42
        wt2 = self.test_unrelated()
 
43
        wt1 = WorkingTree.open('.')
 
44
        br1 = wt1.branch
 
45
        br1.fetch(wt2.branch)
 
46
        # merge all of branch 2 into branch 1 even though they 
 
47
        # are not related.
 
48
        self.assertRaises(BzrCommandError, merge, ['branch2', -1], 
 
49
                          ['branch2', 0], reprocess=True, show_base=True)
 
50
        merge(['branch2', -1], ['branch2', 0], reprocess=True)
 
51
        self.assertEquals(len(wt1.pending_merges()), 1)
 
52
        return (wt1, wt2.branch)
 
53
 
 
54
    def test_two_roots(self):
 
55
        """Merge base is sane when two unrelated branches are merged"""
 
56
        wt1, br2 = self.test_pending_with_null()
 
57
        wt1.commit("blah")
 
58
        last = wt1.branch.last_revision()
 
59
        self.assertEquals(common_ancestor(last, last, wt1.branch.repository), last)
 
60
 
 
61
    def test_create_rename(self):
 
62
        """Rename an inventory entry while creating the file"""
 
63
        tree =self.make_branch_and_tree('.')
 
64
        file('name1', 'wb').write('Hello')
 
65
        tree.add('name1')
 
66
        tree.commit(message="hello")
 
67
        tree.rename_one('name1', 'name2')
 
68
        os.unlink('name2')
 
69
        transform_tree(tree, tree.branch.basis_tree())
 
70
 
 
71
    def test_layered_rename(self):
 
72
        """Rename both child and parent at same time"""
 
73
        tree =self.make_branch_and_tree('.')
 
74
        os.mkdir('dirname1')
 
75
        tree.add('dirname1')
 
76
        filename = pathjoin('dirname1', 'name1')
 
77
        file(filename, 'wb').write('Hello')
 
78
        tree.add(filename)
 
79
        tree.commit(message="hello")
 
80
        filename2 = pathjoin('dirname1', 'name2')
 
81
        tree.rename_one(filename, filename2)
 
82
        tree.rename_one('dirname1', 'dirname2')
 
83
        transform_tree(tree, tree.branch.basis_tree())
 
84
 
 
85
    def test_ignore_zero_merge_inner(self):
 
86
        # Test that merge_inner's ignore zero paramter is effective
 
87
        tree_a =self.make_branch_and_tree('a')
 
88
        tree_a.commit(message="hello")
 
89
        dir_b = tree_a.bzrdir.sprout('b')
 
90
        tree_b = dir_b.open_workingtree()
 
91
        tree_a.commit(message="hello again")
 
92
        log = StringIO()
 
93
        merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(), 
 
94
                    this_tree=tree_b, ignore_zero=True)
 
95
        lines = self._get_log().splitlines(True)[-1]
 
96
        self.failUnless('All changes applied successfully.\n' not in lines)
 
97
        tree_b.revert([])
 
98
        merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(), 
 
99
                    this_tree=tree_b, ignore_zero=False)
 
100
        lines = self._get_log().splitlines(True)[-1]
 
101
        self.failUnless('All changes applied successfully.\n' in lines)