3
3
from bzrlib.branch import Branch
4
from bzrlib.builtins import merge
4
5
from bzrlib.commit import commit
5
from bzrlib.tests import TestCaseInTempDir
6
from bzrlib.builtins import merge
7
from bzrlib.merge import transform_tree
8
6
from bzrlib.errors import UnrelatedBranches, NoCommits, BzrCommandError
9
from bzrlib.revision import common_ancestor
10
7
from bzrlib.fetch import fetch
8
from bzrlib.merge import transform_tree
11
9
from bzrlib.osutils import pathjoin
14
class TestMerge(TestCaseInTempDir):
10
from bzrlib.revision import common_ancestor
11
from bzrlib.tests import TestCaseWithTransport
12
from bzrlib.workingtree import WorkingTree
15
class TestMerge(TestCaseWithTransport):
15
16
"""Test appending more than one revision"""
17
18
def test_pending(self):
18
br = Branch.initialize(u".")
20
self.assertEquals(len(br.working_tree().pending_merges()), 0)
19
wt = self.make_branch_and_tree('.')
21
self.assertEquals(len(wt.pending_merges()), 0)
21
22
merge([u'.', -1], [None, None])
22
self.assertEquals(len(br.working_tree().pending_merges()), 0)
23
self.assertEquals(len(wt.pending_merges()), 0)
24
25
def test_nocommits(self):
25
26
self.test_pending()
27
br2 = Branch.initialize('branch2')
27
wt2 = self.make_branch_and_tree('branch2')
28
28
self.assertRaises(NoCommits, merge, ['branch2', -1],
32
32
def test_unrelated(self):
33
br2 = self.test_nocommits()
33
wt2 = self.test_nocommits()
35
35
self.assertRaises(UnrelatedBranches, merge, ['branch2', -1],
39
39
def test_pending_with_null(self):
40
40
"""When base is forced to revno 0, pending_merges is set"""
41
br2 = self.test_unrelated()
42
br1 = Branch.open(u'.')
43
fetch(from_branch=br2, to_branch=br1)
41
wt2 = self.test_unrelated()
42
wt1 = WorkingTree('.')
44
fetch(from_branch=wt2.branch, to_branch=br1)
44
45
# merge all of branch 2 into branch 1 even though they
46
47
self.assertRaises(BzrCommandError, merge, ['branch2', -1],
47
48
['branch2', 0], reprocess=True, show_base=True)
48
49
merge(['branch2', -1], ['branch2', 0], reprocess=True)
49
self.assertEquals(len(br1.working_tree().pending_merges()), 1)
50
self.assertEquals(len(wt1.pending_merges()), 1)
51
return (wt1, wt2.branch)
52
53
def test_two_roots(self):
53
54
"""Merge base is sane when two unrelated branches are merged"""
54
br1, br2 = self.test_pending_with_null()
56
last = br1.last_revision()
57
self.assertEquals(common_ancestor(last, last, br1.repository), last)
55
wt1, br2 = self.test_pending_with_null()
57
last = wt1.branch.last_revision()
58
self.assertEquals(common_ancestor(last, last, wt1.branch.repository), last)
59
60
def test_create_rename(self):
60
61
"""Rename an inventory entry while creating the file"""
61
b = Branch.initialize(u'.')
62
tree =self.make_branch_and_tree('.')
62
63
file('name1', 'wb').write('Hello')
63
tree = b.working_tree()
65
65
tree.commit(message="hello")
66
66
tree.rename_one('name1', 'name2')
68
transform_tree(tree, b.basis_tree())
68
transform_tree(tree, tree.branch.basis_tree())
70
70
def test_layered_rename(self):
71
71
"""Rename both child and parent at same time"""
72
b = Branch.initialize(u'.')
73
tree = b.working_tree()
72
tree =self.make_branch_and_tree('.')
74
73
os.mkdir('dirname1')
75
74
tree.add('dirname1')
76
75
filename = pathjoin('dirname1', 'name1')