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
17
18
"""Tests for interfacing with a Git Branch"""
19
from bzrlib import revision
20
from bzrlib.branch import Branch
22
from dulwich.repo import (
31
from bzrlib.branch import (
34
from bzrlib.bzrdir import (
37
from bzrlib.repository import (
22
41
from bzrlib.plugins.git import (
26
45
from bzrlib.plugins.git.mapping import default_mapping
31
48
class TestGitBranch(tests.TestCaseInTempDir):
33
50
_test_needs_features = [tests.GitCommandFeature]
35
52
def test_open_existing(self):
38
55
thebranch = Branch.open('.')
39
56
self.assertIsInstance(thebranch, branch.GitBranch)
60
thebranch = Branch.open('.')
61
self.assertEquals("LocalGitBranch('file://%s/', 'HEAD')" % self.test_dir, repr(thebranch))
41
63
def test_last_revision_is_null(self):
44
66
thebranch = Branch.open('.')
45
67
self.assertEqual(revision.NULL_REVISION, thebranch.last_revision())
47
69
thebranch.last_revision_info())
49
71
def simple_commit_a(self):
51
73
self.build_tree(['a'])
52
74
tests.run_git('add', 'a')
53
75
tests.run_git('commit', '-m', 'a')
72
94
self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)],
73
95
thebranch.revision_history())
97
def test_tag_annotated(self):
76
98
self.simple_commit_a()
77
99
reva = tests.run_git('rev-parse', 'HEAD').strip()
79
100
tests.run_git('tag', '-a', '-m', 'add tag', 'foo')
81
thebranch = Branch.open('.')
82
self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
83
thebranch.tags.get_tag_dict())
101
thebranch = Branch.open('.')
102
self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
103
thebranch.tags.get_tag_dict())
106
self.simple_commit_a()
107
reva = tests.run_git('rev-parse', 'HEAD').strip()
108
tests.run_git('tag', '-m', 'add tag', 'foo')
109
thebranch = Branch.open('.')
110
self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
111
thebranch.tags.get_tag_dict())
86
115
class TestWithGitBranch(tests.TestCaseWithTransport):
89
118
tests.TestCaseWithTransport.setUp(self)
90
git.repo.Repo.create(self.test_dir)
119
dulwich.repo.Repo.create(self.test_dir)
91
120
self.git_branch = Branch.open(self.test_dir)
93
122
def test_get_parent(self):
109
138
def test_get_format_description(self):
110
139
self.assertEquals("Git Branch", self.format.get_format_description())
143
class BranchTests(tests.TestCaseInTempDir):
145
def make_onerev_branch(self):
149
bb = tests.GitBranchBuilder()
150
bb.set_file("foobar", "foo\nbar\n", False)
151
mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
152
gitsha = bb.finish()[mark]
156
def clone_git_branch(self, from_url, to_url):
157
from_dir = BzrDir.open(from_url)
158
to_dir = from_dir.sprout(to_url)
159
return to_dir.open_branch()
161
def test_single_rev(self):
162
path, gitsha = self.make_onerev_branch()
163
oldrepo = Repository.open(path)
164
revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
165
newbranch = self.clone_git_branch(path, "f")
166
self.assertEquals([revid], newbranch.repository.all_revision_ids())
168
def test_sprouted_tags(self):
169
path, gitsha = self.make_onerev_branch()
171
tests.run_git("tag", "lala")
172
os.chdir(self.test_dir)
173
oldrepo = Repository.open(path)
174
revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
175
newbranch = self.clone_git_branch(path, "f")
176
self.assertEquals({"lala": revid}, newbranch.tags.get_tag_dict())
177
self.assertEquals([revid], newbranch.repository.all_revision_ids())