~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge.py

  • Committer: Erik Bågfors
  • Date: 2006-02-03 19:50:59 UTC
  • mto: (1185.50.77 bzr-jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1554.
  • Revision ID: erik@bagfors.nu-20060203195059-1cf8ff5aa68de0ea
Support for plugins to register log formatters and set default formatter
Also, change one command line option for "log"

Show diffs side-by-side

added added

removed removed

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