~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testmerge.py

  • Committer: Aaron Bentley
  • Date: 2005-09-19 02:52:24 UTC
  • mto: (1185.1.29)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: aaron.bentley@utoronto.ca-20050919025224-1cc3c70640086e09
TODO re tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import os
2
 
 
3
1
from bzrlib.branch import Branch
4
2
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
 
3
from bzrlib.selftest import TestCaseInTempDir
 
4
from bzrlib.merge import merge
 
5
from bzrlib.errors import UnrelatedBranches, NoCommits
8
6
from bzrlib.revision import common_ancestor
9
 
from bzrlib.fetch import fetch
10
 
 
11
 
 
 
7
import os
12
8
class TestMerge(TestCaseInTempDir):
13
9
    """Test appending more than one revision"""
14
10
    def test_pending(self):
15
 
        br = Branch.initialize(u".")
 
11
        br = Branch.initialize(".")
16
12
        commit(br, "lala!")
17
 
        self.assertEquals(len(br.working_tree().pending_merges()), 0)
18
 
        merge([u'.', -1], [None, None])
19
 
        self.assertEquals(len(br.working_tree().pending_merges()), 0)
 
13
        self.assertEquals(len(br.pending_merges()), 0)
 
14
        merge(['.', -1], [None, None])
 
15
        self.assertEquals(len(br.pending_merges()), 0)
20
16
 
21
17
    def test_nocommits(self):
22
18
        self.test_pending()
36
32
    def test_pending_with_null(self):
37
33
        """When base is forced to revno 0, pending_merges is set"""
38
34
        br2 = self.test_unrelated()
39
 
        br1 = Branch.open(u'.')
40
 
        fetch(from_branch=br2, to_branch=br1)
41
 
        # merge all of branch 2 into branch 1 even though they 
42
 
        # are not related.
43
 
        self.assertRaises(BzrCommandError, merge, ['branch2', -1], 
44
 
                          ['branch2', 0], reprocess=True, show_base=True)
45
 
        merge(['branch2', -1], ['branch2', 0], reprocess=True)
46
 
        self.assertEquals(len(br1.working_tree().pending_merges()), 1)
 
35
        br1 = Branch.open('.')
 
36
        merge(['branch2', -1], ['branch2', 0])
 
37
        self.assertEquals(len(br1.pending_merges()), 1)
47
38
        return (br1, br2)
48
39
 
49
40
    def test_two_roots(self):
50
41
        """Merge base is sane when two unrelated branches are merged"""
51
42
        br1, br2 = self.test_pending_with_null()
52
43
        commit(br1, "blah")
53
 
        last = br1.last_revision()
 
44
        last = br1.last_patch()
54
45
        self.assertEquals(common_ancestor(last, last, br1), last)
55
 
 
56
 
    def test_create_rename(self):
57
 
        """Rename an inventory entry while creating the file"""
58
 
        b = Branch.initialize(u'.')
59
 
        file('name1', 'wb').write('Hello')
60
 
        tree = b.working_tree()
61
 
        tree.add('name1')
62
 
        tree.commit(message="hello")
63
 
        tree.rename_one('name1', 'name2')
64
 
        os.unlink('name2')
65
 
        transform_tree(tree, b.basis_tree())
66
 
 
67
 
    def test_layered_rename(self):
68
 
        """Rename both child and parent at same time"""
69
 
        b = Branch.initialize(u'.')
70
 
        tree = b.working_tree()
71
 
        os.mkdir('dirname1')
72
 
        tree.add('dirname1')
73
 
        filename = os.path.join('dirname1', 'name1')
74
 
        file(filename, 'wb').write('Hello')
75
 
        tree.add(filename)
76
 
        tree.commit(message="hello")
77
 
        filename2 = os.path.join('dirname1', 'name2')
78
 
        tree.rename_one(filename, filename2)
79
 
        tree.rename_one('dirname1', 'dirname2')
80
 
        transform_tree(tree, b.basis_tree())