/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

Fix branch cloning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for interfacing with a Git Branch"""
18
18
 
19
 
import dulwich as git
20
 
import os
21
 
 
22
 
from bzrlib import (
23
 
    revision,
24
 
    )
25
 
from bzrlib.branch import (
26
 
    Branch,
27
 
    )
28
 
from bzrlib.bzrdir import (
29
 
    BzrDir,
30
 
    )
31
 
from bzrlib.repository import (
32
 
    Repository,
33
 
    )
 
19
from bzrlib import revision
 
20
from bzrlib.branch import Branch
34
21
 
35
22
from bzrlib.plugins.git import (
36
23
    branch,
37
24
    tests,
38
25
    )
39
26
from bzrlib.plugins.git.mapping import default_mapping
 
27
from bzrlib.plugins.git import git
 
28
 
40
29
 
41
30
 
42
31
class TestGitBranch(tests.TestCaseInTempDir):
83
72
        self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)],
84
73
                         thebranch.revision_history())
85
74
 
86
 
    def test_tag_annotated(self):
 
75
    def test_tags(self):
87
76
        self.simple_commit_a()
88
77
        reva = tests.run_git('rev-parse', 'HEAD').strip()
 
78
        
89
79
        tests.run_git('tag', '-a', '-m', 'add tag', 'foo')
90
 
        thebranch = Branch.open('.')
91
 
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
92
 
                          thebranch.tags.get_tag_dict())
93
 
 
94
 
    def test_tag(self):
95
 
        self.simple_commit_a()
96
 
        reva = tests.run_git('rev-parse', 'HEAD').strip()
97
 
        tests.run_git('tag', '-m', 'add tag', 'foo')
98
 
        thebranch = Branch.open('.')
99
 
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
100
 
                          thebranch.tags.get_tag_dict())
101
 
 
 
80
        
 
81
        newid = open('.git/refs/tags/foo').read().rstrip()
 
82
 
 
83
        thebranch = Branch.open('.')
 
84
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(newid)},
 
85
                          thebranch.tags.get_tag_dict())
102
86
        
103
87
 
104
88
class TestWithGitBranch(tests.TestCaseWithTransport):
126
110
 
127
111
    def test_get_format_description(self):
128
112
        self.assertEquals("Git Branch", self.format.get_format_description())
129
 
 
130
 
 
131
 
 
132
 
class BranchTests(tests.TestCaseInTempDir):
133
 
 
134
 
    def make_onerev_branch(self):
135
 
        os.mkdir("d")
136
 
        os.chdir("d")
137
 
        tests.run_git("init")
138
 
        bb = tests.GitBranchBuilder()
139
 
        bb.set_file("foobar", "foo\nbar\n", False)
140
 
        mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
141
 
        gitsha = bb.finish()[mark]
142
 
        os.chdir("..")
143
 
        return "d", gitsha
144
 
 
145
 
    def clone_git_branch(self, from_url, to_url):
146
 
        from_dir = BzrDir.open(from_url)
147
 
        to_dir = from_dir.sprout(to_url)
148
 
        return to_dir.open_branch()
149
 
 
150
 
    def test_single_rev(self):
151
 
        path, gitsha = self.make_onerev_branch()
152
 
        oldrepo = Repository.open(path)
153
 
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
154
 
        newbranch = self.clone_git_branch(path, "f")
155
 
        self.assertEquals([revid], newbranch.repository.all_revision_ids())
156
 
 
157
 
    def test_sprouted_tags(self):
158
 
        path, gitsha = self.make_onerev_branch()
159
 
        os.chdir(path)
160
 
        tests.run_git("tag", "lala")
161
 
        os.chdir(self.test_dir)
162
 
        oldrepo = Repository.open(path)
163
 
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
164
 
        newbranch = self.clone_git_branch(path, "f")
165
 
        self.assertEquals({"lala": revid}, newbranch.tags.get_tag_dict())
166
 
        self.assertEquals([revid], newbranch.repository.all_revision_ids())