3
3
from bzrlib.branch import Branch
4
4
from bzrlib.commit import commit
5
from bzrlib.tests import TestCaseInTempDir
6
from bzrlib.merge import merge, transform_tree
7
from bzrlib.errors import UnrelatedBranches, NoCommits, BzrCommandError
5
from bzrlib.selftest import TestCaseInTempDir
6
from bzrlib.merge import merge
7
from bzrlib.errors import UnrelatedBranches, NoCommits
8
8
from bzrlib.revision import common_ancestor
9
9
from bzrlib.fetch import fetch
10
from bzrlib.osutils import pathjoin
13
12
class TestMerge(TestCaseInTempDir):
14
13
"""Test appending more than one revision"""
15
14
def test_pending(self):
16
br = Branch.initialize(u".")
15
br = Branch.initialize(".")
17
16
commit(br, "lala!")
18
self.assertEquals(len(br.working_tree().pending_merges()), 0)
19
merge([u'.', -1], [None, None])
20
self.assertEquals(len(br.working_tree().pending_merges()), 0)
17
self.assertEquals(len(br.pending_merges()), 0)
18
merge(['.', -1], [None, None])
19
self.assertEquals(len(br.pending_merges()), 0)
22
21
def test_nocommits(self):
23
22
self.test_pending()
37
36
def test_pending_with_null(self):
38
37
"""When base is forced to revno 0, pending_merges is set"""
39
38
br2 = self.test_unrelated()
40
br1 = Branch.open(u'.')
39
br1 = Branch.open('.')
41
40
fetch(from_branch=br2, to_branch=br1)
42
41
# merge all of branch 2 into branch 1 even though they
44
self.assertRaises(BzrCommandError, merge, ['branch2', -1],
45
['branch2', 0], reprocess=True, show_base=True)
46
merge(['branch2', -1], ['branch2', 0], reprocess=True)
47
self.assertEquals(len(br1.working_tree().pending_merges()), 1)
43
merge(['branch2', -1], ['branch2', 0])
44
self.assertEquals(len(br1.pending_merges()), 1)
50
47
def test_two_roots(self):
53
50
commit(br1, "blah")
54
51
last = br1.last_revision()
55
52
self.assertEquals(common_ancestor(last, last, br1), last)
57
def test_create_rename(self):
58
"""Rename an inventory entry while creating the file"""
59
b = Branch.initialize(u'.')
60
file('name1', 'wb').write('Hello')
61
tree = b.working_tree()
63
tree.commit(message="hello")
64
tree.rename_one('name1', 'name2')
66
transform_tree(tree, b.basis_tree())
68
def test_layered_rename(self):
69
"""Rename both child and parent at same time"""
70
b = Branch.initialize(u'.')
71
tree = b.working_tree()
74
filename = pathjoin('dirname1', 'name1')
75
file(filename, 'wb').write('Hello')
77
tree.commit(message="hello")
78
filename2 = pathjoin('dirname1', 'name2')
79
tree.rename_one(filename, filename2)
80
tree.rename_one('dirname1', 'dirname2')
81
transform_tree(tree, b.basis_tree())