/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

Add exception for ghost revisions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
 
17
 
17
18
"""Tests for interfacing with a Git Branch"""
18
19
 
19
 
from bzrlib import revision
20
 
from bzrlib.branch import Branch
 
20
 
 
21
import dulwich
 
22
import os
 
23
 
 
24
from bzrlib import (
 
25
    revision,
 
26
    )
 
27
from bzrlib.branch import (
 
28
    Branch,
 
29
    )
 
30
from bzrlib.bzrdir import (
 
31
    BzrDir,
 
32
    )
 
33
from bzrlib.repository import (
 
34
    Repository,
 
35
    )
21
36
 
22
37
from bzrlib.plugins.git import (
23
38
    branch,
24
39
    tests,
25
40
    )
26
41
from bzrlib.plugins.git.mapping import default_mapping
27
 
from bzrlib.plugins.git import git
28
 
 
29
42
 
30
43
 
31
44
class TestGitBranch(tests.TestCaseInTempDir):
38
51
        thebranch = Branch.open('.')
39
52
        self.assertIsInstance(thebranch, branch.GitBranch)
40
53
 
 
54
    def test_repr(self):
 
55
        tests.run_git('init')
 
56
        thebranch = Branch.open('.')
 
57
        self.assertEquals("LocalGitBranch('file://%s/', 'HEAD')" % self.test_dir, repr(thebranch))
 
58
 
41
59
    def test_last_revision_is_null(self):
42
60
        tests.run_git('init')
43
61
 
72
90
        self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)],
73
91
                         thebranch.revision_history())
74
92
 
75
 
    def test_tags(self):
 
93
    def test_tag_annotated(self):
76
94
        self.simple_commit_a()
77
95
        reva = tests.run_git('rev-parse', 'HEAD').strip()
78
 
        
79
96
        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.revision_id_foreign_to_bzr(newid)},
85
 
                          thebranch.tags.get_tag_dict())
 
97
        thebranch = Branch.open('.')
 
98
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
 
99
                          thebranch.tags.get_tag_dict())
 
100
 
 
101
    def test_tag(self):
 
102
        self.simple_commit_a()
 
103
        reva = tests.run_git('rev-parse', 'HEAD').strip()
 
104
        tests.run_git('tag', '-m', 'add tag', 'foo')
 
105
        thebranch = Branch.open('.')
 
106
        self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
 
107
                          thebranch.tags.get_tag_dict())
 
108
 
86
109
        
87
110
 
88
111
class TestWithGitBranch(tests.TestCaseWithTransport):
89
112
 
90
113
    def setUp(self):
91
114
        tests.TestCaseWithTransport.setUp(self)
92
 
        git.repo.Repo.create(self.test_dir)
 
115
        dulwich.repo.Repo.create(self.test_dir)
93
116
        self.git_branch = Branch.open(self.test_dir)
94
117
 
95
118
    def test_get_parent(self):
110
133
 
111
134
    def test_get_format_description(self):
112
135
        self.assertEquals("Git Branch", self.format.get_format_description())
 
136
 
 
137
 
 
138
 
 
139
class BranchTests(tests.TestCaseInTempDir):
 
140
 
 
141
    def make_onerev_branch(self):
 
142
        os.mkdir("d")
 
143
        os.chdir("d")
 
144
        tests.run_git("init")
 
145
        bb = tests.GitBranchBuilder()
 
146
        bb.set_file("foobar", "foo\nbar\n", False)
 
147
        mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
 
148
        gitsha = bb.finish()[mark]
 
149
        os.chdir("..")
 
150
        return "d", gitsha
 
151
 
 
152
    def clone_git_branch(self, from_url, to_url):
 
153
        from_dir = BzrDir.open(from_url)
 
154
        to_dir = from_dir.sprout(to_url)
 
155
        return to_dir.open_branch()
 
156
 
 
157
    def test_single_rev(self):
 
158
        path, gitsha = self.make_onerev_branch()
 
159
        oldrepo = Repository.open(path)
 
160
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
 
161
        newbranch = self.clone_git_branch(path, "f")
 
162
        self.assertEquals([revid], newbranch.repository.all_revision_ids())
 
163
 
 
164
    def test_sprouted_tags(self):
 
165
        path, gitsha = self.make_onerev_branch()
 
166
        os.chdir(path)
 
167
        tests.run_git("tag", "lala")
 
168
        os.chdir(self.test_dir)
 
169
        oldrepo = Repository.open(path)
 
170
        revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
 
171
        newbranch = self.clone_git_branch(path, "f")
 
172
        self.assertEquals({"lala": revid}, newbranch.tags.get_tag_dict())
 
173
        self.assertEquals([revid], newbranch.repository.all_revision_ids())