/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

Avoid invoking git directly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
 
21
21
import dulwich
 
22
from dulwich.objects import (
 
23
    Commit,
 
24
    Tag,
 
25
    )
22
26
from dulwich.repo import (
23
27
    Repo as GitRepo,
24
28
    )
52
56
 
53
57
class TestGitBranch(tests.TestCaseInTempDir):
54
58
 
55
 
    _test_needs_features = [tests.GitCommandFeature]
56
 
 
57
59
    def test_open_existing(self):
58
60
        GitRepo.init('.')
59
61
        d = BzrDir.open('.')
75
77
                         thebranch.last_revision_info())
76
78
 
77
79
    def simple_commit_a(self):
78
 
        GitRepo.init('.')
 
80
        r = GitRepo.init('.')
79
81
        self.build_tree(['a'])
80
 
        tests.run_git('add', 'a')
81
 
        tests.run_git('commit', '-m', 'a')
 
82
        r.stage(["a"])
 
83
        return r.do_commit("a", committer="Somebody <foo@example.com>")
82
84
 
83
85
    def test_last_revision_is_valid(self):
84
 
        self.simple_commit_a()
85
 
        head = tests.run_git('rev-parse', 'HEAD').strip()
 
86
        head = self.simple_commit_a()
86
87
        thebranch = Branch.open('.')
87
88
        self.assertEqual(default_mapping.revision_id_foreign_to_bzr(head),
88
89
                         thebranch.last_revision())
89
90
 
90
91
    def test_revision_history(self):
91
 
        self.simple_commit_a()
92
 
        reva = tests.run_git('rev-parse', 'HEAD').strip()
 
92
        reva = self.simple_commit_a()
93
93
        self.build_tree(['b'])
94
 
        tests.run_git('add', 'b')
95
 
        tests.run_git('commit', '-m', 'b')
96
 
        revb = tests.run_git('rev-parse', 'HEAD').strip()
 
94
        r = GitRepo(".")
 
95
        r.stage("b")
 
96
        revb = r.do_commit("b", committer="Somebody <foo@example.com>")
97
97
 
98
98
        thebranch = Branch.open('.')
99
99
        self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)],
100
100
                         thebranch.revision_history())
101
101
 
102
102
    def test_tag_annotated(self):
103
 
        self.simple_commit_a()
104
 
        reva = tests.run_git('rev-parse', 'HEAD').strip()
105
 
        tests.run_git('tag', '-a', '-m', 'add tag', 'foo')
 
103
        reva = self.simple_commit_a()
 
104
        o = Tag()
 
105
        o.name = "foo"
 
106
        o.tagger = "Jelmer <foo@example.com>"
 
107
        o.message = "add tag"
 
108
        o.object = (Commit, reva)
 
109
        o.tag_timezone = 0
 
110
        o.tag_time = 42
 
111
        r = GitRepo(".")
 
112
        r.object_store.add_object(o)
 
113
        r['refs/tags/foo'] = o.id
106
114
        thebranch = Branch.open('.')
107
115
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
108
116
                          thebranch.tags.get_tag_dict())
109
117
 
110
118
    def test_tag(self):
111
 
        self.simple_commit_a()
112
 
        reva = tests.run_git('rev-parse', 'HEAD').strip()
113
 
        tests.run_git('tag', '-m', 'add tag', 'foo')
 
119
        reva = self.simple_commit_a()
 
120
        r = GitRepo(".")
 
121
        r.refs["refs/tags/foo"] = reva
114
122
        thebranch = Branch.open('.')
115
123
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
116
124
                          thebranch.tags.get_tag_dict())
191
199
 
192
200
    def test_sprouted_tags(self):
193
201
        path, gitsha = self.make_onerev_branch()
194
 
        os.chdir(path)
195
 
        tests.run_git("tag", "lala")
196
 
        os.chdir(self.test_dir)
 
202
        r = GitRepo(path)
 
203
        r.refs["refs/tags/lala"] = r.head()
197
204
        oldrepo = Repository.open(path)
198
205
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
199
206
        newbranch = self.clone_git_branch(path, "f")