~bzr-pqm/bzr/bzr.dev

1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
1
import os
2
974.1.56 by aaron.bentley at utoronto
Added merge test
3
from bzrlib.branch import Branch
4
from bzrlib.commit import commit
1185.31.25 by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py
5
from bzrlib.tests import TestCaseInTempDir
1185.46.1 by Aaron Bentley
Test case when file to be renamed is also deleted
6
from bzrlib.merge import merge, transform_tree
1185.24.3 by Aaron Bentley
Integrated reprocessing into the rest of the merge stuff
7
from bzrlib.errors import UnrelatedBranches, NoCommits, BzrCommandError
974.1.89 by Aaron Bentley
Fixed merging with multiple roots, by using null as graph root.
8
from bzrlib.revision import common_ancestor
1390 by Robert Collins
pair programming worx... merge integration and weave
9
from bzrlib.fetch import fetch
1185.31.32 by John Arbash Meinel
Updated the bzr sourcecode to use bzrlib.osutils.pathjoin rather than os.path.join to enforce internal use of / instead of \
10
from bzrlib.osutils import pathjoin
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
11
12
974.1.56 by aaron.bentley at utoronto
Added merge test
13
class TestMerge(TestCaseInTempDir):
14
    """Test appending more than one revision"""
15
    def test_pending(self):
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
16
        br = Branch.initialize(u".")
974.1.56 by aaron.bentley at utoronto
Added merge test
17
        commit(br, "lala!")
1457.1.14 by Robert Collins
Move pending_merges() to WorkingTree.
18
        self.assertEquals(len(br.working_tree().pending_merges()), 0)
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
19
        merge([u'.', -1], [None, None])
1457.1.14 by Robert Collins
Move pending_merges() to WorkingTree.
20
        self.assertEquals(len(br.working_tree().pending_merges()), 0)
974.1.80 by Aaron Bentley
Improved merge error handling and testing
21
22
    def test_nocommits(self):
23
        self.test_pending()
24
        os.mkdir('branch2')
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
25
        br2 = Branch.initialize('branch2')
974.1.80 by Aaron Bentley
Improved merge error handling and testing
26
        self.assertRaises(NoCommits, merge, ['branch2', -1], 
27
                          [None, None])
28
        return br2
29
30
    def test_unrelated(self):
31
        br2 = self.test_nocommits()
32
        commit(br2, "blah")
33
        self.assertRaises(UnrelatedBranches, merge, ['branch2', -1], 
34
                          [None, None])
974.1.88 by Aaron Bentley
Set a pending_merge if the merge base is forced to revno 0
35
        return br2
974.1.80 by Aaron Bentley
Improved merge error handling and testing
36
974.1.88 by Aaron Bentley
Set a pending_merge if the merge base is forced to revno 0
37
    def test_pending_with_null(self):
38
        """When base is forced to revno 0, pending_merges is set"""
39
        br2 = self.test_unrelated()
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
40
        br1 = Branch.open(u'.')
1390 by Robert Collins
pair programming worx... merge integration and weave
41
        fetch(from_branch=br2, to_branch=br1)
42
        # merge all of branch 2 into branch 1 even though they 
43
        # are not related.
1185.24.3 by Aaron Bentley
Integrated reprocessing into the rest of the merge stuff
44
        self.assertRaises(BzrCommandError, merge, ['branch2', -1], 
45
                          ['branch2', 0], reprocess=True, show_base=True)
46
        merge(['branch2', -1], ['branch2', 0], reprocess=True)
1457.1.14 by Robert Collins
Move pending_merges() to WorkingTree.
47
        self.assertEquals(len(br1.working_tree().pending_merges()), 1)
974.1.88 by Aaron Bentley
Set a pending_merge if the merge base is forced to revno 0
48
        return (br1, br2)
974.1.89 by Aaron Bentley
Fixed merging with multiple roots, by using null as graph root.
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")
1390 by Robert Collins
pair programming worx... merge integration and weave
54
        last = br1.last_revision()
974.1.89 by Aaron Bentley
Fixed merging with multiple roots, by using null as graph root.
55
        self.assertEquals(common_ancestor(last, last, br1), last)
1185.46.1 by Aaron Bentley
Test case when file to be renamed is also deleted
56
57
    def test_create_rename(self):
58
        """Rename an inventory entry while creating the file"""
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
59
        b = Branch.initialize(u'.')
1185.46.1 by Aaron Bentley
Test case when file to be renamed is also deleted
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())
1185.46.2 by Aaron Bentley
Added test for renaming both parent and child
67
68
    def test_layered_rename(self):
69
        """Rename both child and parent at same time"""
1185.33.66 by Martin Pool
[patch] use unicode literals for all hardcoded paths (Alexander Belchenko)
70
        b = Branch.initialize(u'.')
1185.46.2 by Aaron Bentley
Added test for renaming both parent and child
71
        tree = b.working_tree()
72
        os.mkdir('dirname1')
73
        tree.add('dirname1')
1185.31.32 by John Arbash Meinel
Updated the bzr sourcecode to use bzrlib.osutils.pathjoin rather than os.path.join to enforce internal use of / instead of \
74
        filename = pathjoin('dirname1', 'name1')
1185.46.2 by Aaron Bentley
Added test for renaming both parent and child
75
        file(filename, 'wb').write('Hello')
76
        tree.add(filename)
77
        tree.commit(message="hello")
1185.31.32 by John Arbash Meinel
Updated the bzr sourcecode to use bzrlib.osutils.pathjoin rather than os.path.join to enforce internal use of / instead of \
78
        filename2 = pathjoin('dirname1', 'name2')
1185.46.2 by Aaron Bentley
Added test for renaming both parent and child
79
        tree.rename_one(filename, filename2)
80
        tree.rename_one('dirname1', 'dirname2')
81
        transform_tree(tree, b.basis_tree())