1
# Copyright (C) 2005, 2006 by Canonical Ltd
1
# Copyright (C) 2005, 2006 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
18
18
from StringIO import StringIO
20
from bzrlib import conflicts
20
21
from bzrlib.branch import Branch
21
22
from bzrlib.builtins import merge
22
23
from bzrlib.conflicts import ConflictList, TextConflict
35
36
def test_pending(self):
36
37
wt = self.make_branch_and_tree('.')
38
self.assertEquals(len(wt.pending_merges()), 0)
38
rev_a = wt.commit("lala!")
39
self.assertEqual([rev_a], wt.get_parent_ids())
39
40
merge([u'.', -1], [None, None])
40
self.assertEquals(len(wt.pending_merges()), 0)
41
self.assertEqual([rev_a], wt.get_parent_ids())
42
43
def test_undo(self):
43
44
wt = self.make_branch_and_tree('.')
63
def test_merge_one(self):
64
def test_merge_one_file(self):
65
"""Do a partial merge of a tree which should not affect tree parents."""
64
66
wt1 = self.make_branch_and_tree('branch1')
65
wt1.commit('empty commit')
67
tip = wt1.commit('empty commit')
66
68
wt2 = self.make_branch_and_tree('branch2')
67
69
wt2.pull(wt1.branch)
68
70
file('branch1/foo', 'wb').write('foo')
75
77
self.run_bzr('merge', '../branch1/foo')
76
78
self.failUnlessExists('foo')
77
79
self.failIfExists('bar')
78
wt2 = WorkingTree.open_containing('branch2')[0]
79
self.assertEqual(wt2.pending_merges(), [])
80
wt2 = WorkingTree.open('.') # opens branch2
81
self.assertEqual([tip], wt2.get_parent_ids())
81
83
def test_pending_with_null(self):
82
"""When base is forced to revno 0, pending_merges is set"""
84
"""When base is forced to revno 0, parent_ids are set"""
83
85
wt2 = self.test_unrelated()
84
86
wt1 = WorkingTree.open('.')
86
88
br1.fetch(wt2.branch)
87
89
# merge all of branch 2 into branch 1 even though they
89
self.assertRaises(BzrCommandError, merge, ['branch2', -1],
91
self.assertRaises(BzrCommandError, merge, ['branch2', -1],
90
92
['branch2', 0], reprocess=True, show_base=True)
91
93
merge(['branch2', -1], ['branch2', 0], reprocess=True)
92
self.assertEquals(len(wt1.pending_merges()), 1)
94
self.assertEqual([br1.last_revision(), wt2.branch.last_revision()],
93
96
return (wt1, wt2.branch)
95
98
def test_two_roots(self):
97
100
wt1, br2 = self.test_pending_with_null()
98
101
wt1.commit("blah")
99
102
last = wt1.branch.last_revision()
100
self.assertEquals(common_ancestor(last, last, wt1.branch.repository), last)
103
self.assertEqual(common_ancestor(last, last, wt1.branch.repository), last)
102
105
def test_create_rename(self):
103
106
"""Rename an inventory entry while creating the file"""
124
127
transform_tree(tree, tree.branch.basis_tree())
126
129
def test_ignore_zero_merge_inner(self):
127
# Test that merge_inner's ignore zero paramter is effective
130
# Test that merge_inner's ignore zero parameter is effective
128
131
tree_a =self.make_branch_and_tree('a')
129
132
tree_a.commit(message="hello")
130
133
dir_b = tree_a.bzrdir.sprout('b')
134
137
merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(),
135
138
this_tree=tree_b, ignore_zero=True)
136
log = self._get_log()
139
log = self._get_log(keep_log_file=True)
137
140
self.failUnless('All changes applied successfully.\n' not in log)
138
141
tree_b.revert([])
139
142
merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(),
140
143
this_tree=tree_b, ignore_zero=False)
141
log = self._get_log()
144
log = self._get_log(keep_log_file=True)
142
145
self.failUnless('All changes applied successfully.\n' in log)
144
147
def test_merge_inner_conflicts(self):
146
149
tree_a.set_conflicts(ConflictList([TextConflict('patha')]))
147
150
merge_inner(tree_a.branch, tree_a, tree_a, this_tree=tree_a)
148
151
self.assertEqual(1, len(tree_a.conflicts()))
153
def test_rmdir_conflict(self):
154
tree_a = self.make_branch_and_tree('a')
155
self.build_tree(['a/b/'])
156
tree_a.add('b', 'b-id')
157
tree_a.commit('added b')
158
base_tree = tree_a.basis_tree()
159
tree_z = tree_a.bzrdir.sprout('z').open_workingtree()
160
self.build_tree(['a/b/c'])
162
tree_a.commit('added c')
164
tree_z.commit('removed b')
165
merge_inner(tree_z.branch, tree_a, base_tree, this_tree=tree_z)
167
conflicts.MissingParent('Created directory', 'b', 'b-id'),
168
conflicts.UnversionedParent('Versioned directory', 'b', 'b-id')],
170
merge_inner(tree_a.branch, tree_z.basis_tree(), base_tree,
173
conflicts.DeletingParent('Not deleting', 'b', 'b-id'),
174
conflicts.UnversionedParent('Versioned directory', 'b', 'b-id')],