~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testmerge.py

  • Committer: Lalo Martins
  • Date: 2005-09-16 12:53:47 UTC
  • mto: (1185.1.26)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: lalo@exoweb.net-20050916125347-e134440582d72d53
blackbox tests for diff

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
8
 
from bzrlib.revision import common_ancestor
9
 
from bzrlib.fetch import fetch
10
 
from bzrlib.osutils import pathjoin
11
 
 
12
 
 
 
3
from bzrlib.selftest import TestCaseInTempDir
 
4
from bzrlib.merge import merge
 
5
from bzrlib.errors import UnrelatedBranches, NoCommits
 
6
import os
13
7
class TestMerge(TestCaseInTempDir):
14
8
    """Test appending more than one revision"""
15
9
    def test_pending(self):
16
 
        br = Branch.initialize(u".")
 
10
        br = Branch.initialize(".")
17
11
        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)
 
12
        self.assertEquals(len(br.pending_merges()), 0)
 
13
        merge(['.', -1], [None, None])
 
14
        self.assertEquals(len(br.pending_merges()), 0)
21
15
 
22
16
    def test_nocommits(self):
23
17
        self.test_pending()
30
24
    def test_unrelated(self):
31
25
        br2 = self.test_nocommits()
32
26
        commit(br2, "blah")
 
27
        merge, ['branch2', -1], [None, None]
33
28
        self.assertRaises(UnrelatedBranches, merge, ['branch2', -1], 
34
29
                          [None, None])
35
 
        return br2
36
 
 
37
 
    def test_pending_with_null(self):
38
 
        """When base is forced to revno 0, pending_merges is set"""
39
 
        br2 = self.test_unrelated()
40
 
        br1 = Branch.open(u'.')
41
 
        fetch(from_branch=br2, to_branch=br1)
42
 
        # merge all of branch 2 into branch 1 even though they 
43
 
        # are not related.
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)
48
 
        return (br1, br2)
49
 
 
50
 
    def test_two_roots(self):
51
 
        """Merge base is sane when two unrelated branches are merged"""
52
 
        br1, br2 = self.test_pending_with_null()
53
 
        commit(br1, "blah")
54
 
        last = br1.last_revision()
55
 
        self.assertEquals(common_ancestor(last, last, br1.repository), last)
56
 
 
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()
62
 
        tree.add('name1')
63
 
        tree.commit(message="hello")
64
 
        tree.rename_one('name1', 'name2')
65
 
        os.unlink('name2')
66
 
        transform_tree(tree, b.basis_tree())
67
 
 
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()
72
 
        os.mkdir('dirname1')
73
 
        tree.add('dirname1')
74
 
        filename = pathjoin('dirname1', 'name1')
75
 
        file(filename, 'wb').write('Hello')
76
 
        tree.add(filename)
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())
 
30