/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge.py

  • Committer: Jelmer Vernooij
  • Date: 2006-06-27 00:58:18 UTC
  • mto: (1711.2.65 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1818.
  • Revision ID: jelmer@samba.org-20060627005818-622971c3e6b95cd2
Fix copy-pasted comment.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005, 2006 by Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
import os
 
18
from StringIO import StringIO
 
19
 
 
20
from bzrlib.branch import Branch
 
21
from bzrlib.builtins import merge
 
22
from bzrlib.errors import UnrelatedBranches, NoCommits, BzrCommandError
 
23
from bzrlib.merge import transform_tree, merge_inner
 
24
from bzrlib.osutils import pathjoin
 
25
from bzrlib.revision import common_ancestor
 
26
from bzrlib.tests import TestCaseWithTransport
 
27
from bzrlib.trace import (enable_test_log, disable_test_log)
 
28
from bzrlib.workingtree import WorkingTree
 
29
 
 
30
 
 
31
class TestMerge(TestCaseWithTransport):
 
32
    """Test appending more than one revision"""
 
33
 
 
34
    def test_pending(self):
 
35
        wt = self.make_branch_and_tree('.')
 
36
        wt.commit("lala!")
 
37
        self.assertEquals(len(wt.pending_merges()), 0)
 
38
        merge([u'.', -1], [None, None])
 
39
        self.assertEquals(len(wt.pending_merges()), 0)
 
40
 
 
41
    def test_undo(self):
 
42
        wt = self.make_branch_and_tree('.')
 
43
        wt.commit("lala!")
 
44
        wt.commit("haha!")
 
45
        wt.commit("blabla!")
 
46
        merge([u'.', 2], [u'.', 1])
 
47
 
 
48
    def test_nocommits(self):
 
49
        self.test_pending()
 
50
        wt2 = self.make_branch_and_tree('branch2')
 
51
        self.assertRaises(NoCommits, merge, ['branch2', -1], 
 
52
                          [None, None])
 
53
        return wt2
 
54
 
 
55
    def test_unrelated(self):
 
56
        wt2 = self.test_nocommits()
 
57
        wt2.commit("blah")
 
58
        self.assertRaises(UnrelatedBranches, merge, ['branch2', -1], 
 
59
                          [None, None])
 
60
        return wt2
 
61
 
 
62
    def test_merge_one(self):
 
63
        wt1 = self.make_branch_and_tree('branch1')
 
64
        wt1.commit('empty commit')
 
65
        wt2 = self.make_branch_and_tree('branch2')
 
66
        wt2.pull(wt1.branch)
 
67
        file('branch1/foo', 'wb').write('foo')
 
68
        file('branch1/bar', 'wb').write('bar')
 
69
        wt1.add('foo')
 
70
        wt1.add('bar')
 
71
        wt1.commit('add foobar')
 
72
        os.chdir('branch2')
 
73
        self.run_bzr('merge', '../branch1/baz', retcode=3)
 
74
        self.run_bzr('merge', '../branch1/foo')
 
75
        self.failUnlessExists('foo')
 
76
        self.failIfExists('bar')
 
77
        wt2 = WorkingTree.open_containing('branch2')[0]
 
78
        self.assertEqual(wt2.pending_merges(), [])
 
79
 
 
80
    def test_pending_with_null(self):
 
81
        """When base is forced to revno 0, pending_merges is set"""
 
82
        wt2 = self.test_unrelated()
 
83
        wt1 = WorkingTree.open('.')
 
84
        br1 = wt1.branch
 
85
        br1.fetch(wt2.branch)
 
86
        # merge all of branch 2 into branch 1 even though they 
 
87
        # are not related.
 
88
        self.assertRaises(BzrCommandError, merge, ['branch2', -1], 
 
89
                          ['branch2', 0], reprocess=True, show_base=True)
 
90
        merge(['branch2', -1], ['branch2', 0], reprocess=True)
 
91
        self.assertEquals(len(wt1.pending_merges()), 1)
 
92
        return (wt1, wt2.branch)
 
93
 
 
94
    def test_two_roots(self):
 
95
        """Merge base is sane when two unrelated branches are merged"""
 
96
        wt1, br2 = self.test_pending_with_null()
 
97
        wt1.commit("blah")
 
98
        last = wt1.branch.last_revision()
 
99
        self.assertEquals(common_ancestor(last, last, wt1.branch.repository), last)
 
100
 
 
101
    def test_create_rename(self):
 
102
        """Rename an inventory entry while creating the file"""
 
103
        tree =self.make_branch_and_tree('.')
 
104
        file('name1', 'wb').write('Hello')
 
105
        tree.add('name1')
 
106
        tree.commit(message="hello")
 
107
        tree.rename_one('name1', 'name2')
 
108
        os.unlink('name2')
 
109
        transform_tree(tree, tree.branch.basis_tree())
 
110
 
 
111
    def test_layered_rename(self):
 
112
        """Rename both child and parent at same time"""
 
113
        tree =self.make_branch_and_tree('.')
 
114
        os.mkdir('dirname1')
 
115
        tree.add('dirname1')
 
116
        filename = pathjoin('dirname1', 'name1')
 
117
        file(filename, 'wb').write('Hello')
 
118
        tree.add(filename)
 
119
        tree.commit(message="hello")
 
120
        filename2 = pathjoin('dirname1', 'name2')
 
121
        tree.rename_one(filename, filename2)
 
122
        tree.rename_one('dirname1', 'dirname2')
 
123
        transform_tree(tree, tree.branch.basis_tree())
 
124
 
 
125
    def test_ignore_zero_merge_inner(self):
 
126
        # Test that merge_inner's ignore zero paramter is effective
 
127
        tree_a =self.make_branch_and_tree('a')
 
128
        tree_a.commit(message="hello")
 
129
        dir_b = tree_a.bzrdir.sprout('b')
 
130
        tree_b = dir_b.open_workingtree()
 
131
        tree_a.commit(message="hello again")
 
132
        log = StringIO()
 
133
        merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(), 
 
134
                    this_tree=tree_b, ignore_zero=True)
 
135
        log = self._get_log()
 
136
        self.failUnless('All changes applied successfully.\n' not in log)
 
137
        tree_b.revert([])
 
138
        merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(), 
 
139
                    this_tree=tree_b, ignore_zero=False)
 
140
        log = self._get_log()
 
141
        self.failUnless('All changes applied successfully.\n' in log)