/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tests/test_branch.py

Merge foreign branch utility code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import git
20
20
 
21
 
from bzrlib import branch, revision
 
21
from bzrlib import revision
 
22
from bzrlib.branch import Branch
22
23
 
23
 
from bzrlib.plugins.git import tests
24
24
from bzrlib.plugins.git import (
25
 
    git_branch,
26
 
    ids,
 
25
    branch,
 
26
    tests,
27
27
    )
 
28
from bzrlib.plugins.git.mapping import default_mapping
28
29
 
29
30
 
30
31
class TestGitBranch(tests.TestCaseInTempDir):
34
35
    def test_open_existing(self):
35
36
        tests.run_git('init')
36
37
 
37
 
        thebranch = branch.Branch.open('.')
38
 
        self.assertIsInstance(thebranch, git_branch.GitBranch)
 
38
        thebranch = Branch.open('.')
 
39
        self.assertIsInstance(thebranch, branch.GitBranch)
39
40
 
40
41
    def test_last_revision_is_null(self):
41
42
        tests.run_git('init')
42
43
 
43
 
        thebranch = branch.Branch.open('.')
 
44
        thebranch = Branch.open('.')
44
45
        self.assertEqual(revision.NULL_REVISION, thebranch.last_revision())
45
46
        self.assertEqual((0, revision.NULL_REVISION),
46
47
                         thebranch.last_revision_info())
47
48
 
 
49
    def simple_commit_a(self):
 
50
        tests.run_git('init')
 
51
        self.build_tree(['a'])
 
52
        tests.run_git('add', 'a')
 
53
        tests.run_git('commit', '-m', 'a')
 
54
 
48
55
    def test_last_revision_is_valid(self):
49
 
        tests.run_git('init')
50
 
        self.build_tree(['a'])
51
 
        tests.run_git('add', 'a')
52
 
        tests.run_git('commit', '-m', 'a')
 
56
        self.simple_commit_a()
53
57
        head = tests.run_git('rev-parse', 'HEAD').strip()
54
58
 
55
 
        thebranch = branch.Branch.open('.')
56
 
        self.assertEqual(ids.convert_revision_id_git_to_bzr(head),
 
59
        thebranch = Branch.open('.')
 
60
        self.assertEqual(default_mapping.convert_revision_id_git_to_bzr(head),
57
61
                         thebranch.last_revision())
58
62
 
59
63
    def test_revision_history(self):
60
 
        tests.run_git('init')
61
 
        self.build_tree(['a'])
62
 
        tests.run_git('add', 'a')
63
 
        tests.run_git('commit', '-m', 'a')
 
64
        self.simple_commit_a()
64
65
        reva = tests.run_git('rev-parse', 'HEAD').strip()
65
66
        self.build_tree(['b'])
66
67
        tests.run_git('add', 'b')
67
68
        tests.run_git('commit', '-m', 'b')
68
69
        revb = tests.run_git('rev-parse', 'HEAD').strip()
69
70
 
70
 
        thebranch = branch.Branch.open('.')
71
 
        self.assertEqual([ids.convert_revision_id_git_to_bzr(r) for r in (reva, revb)],
 
71
        thebranch = Branch.open('.')
 
72
        self.assertEqual([default_mapping.convert_revision_id_git_to_bzr(r) for r in (reva, revb)],
72
73
                         thebranch.revision_history())
 
74
 
 
75
    def test_tags(self):
 
76
        self.simple_commit_a()
 
77
        reva = tests.run_git('rev-parse', 'HEAD').strip()
 
78
        
 
79
        tests.run_git('tag', '-a', '-m', 'add tag', 'foo')
 
80
        
 
81
        newid = open('.git/refs/tags/foo').read().rstrip()
 
82
 
 
83
        thebranch = Branch.open('.')
 
84
        self.assertEquals({"foo": default_mapping.convert_revision_id_git_to_bzr(newid)},
 
85
                          thebranch.tags.get_tag_dict())
73
86
        
74
87
 
75
88
class TestWithGitBranch(tests.TestCaseWithTransport):
77
90
    def setUp(self):
78
91
        tests.TestCaseWithTransport.setUp(self)
79
92
        git.repo.Repo.create(self.test_dir)
80
 
        self.git_branch = branch.Branch.open(self.test_dir)
 
93
        self.git_branch = Branch.open(self.test_dir)
81
94
 
82
95
    def test_get_parent(self):
83
96
        self.assertIs(None, self.git_branch.get_parent())
93
106
 
94
107
    def setUp(self):
95
108
        super(TestGitBranchFormat, self).setUp()
96
 
        self.format = git_branch.GitBranchFormat()
 
109
        self.format = branch.GitBranchFormat()
97
110
 
98
111
    def test_get_format_description(self):
99
112
        self.assertEquals("Git Branch", self.format.get_format_description())