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
from bzrlib.plugins.git.mapping import default_mapping
46
from bzrlib.plugins.git.mapping import (
31
51
class TestGitBranch(tests.TestCaseInTempDir):
33
53
_test_needs_features = [tests.GitCommandFeature]
35
55
def test_open_existing(self):
38
58
thebranch = Branch.open('.')
39
59
self.assertIsInstance(thebranch, branch.GitBranch)
63
thebranch = Branch.open('.')
64
self.assertEquals("LocalGitBranch('file://%s/', 'HEAD')" % self.test_dir, repr(thebranch))
41
66
def test_last_revision_is_null(self):
44
69
thebranch = Branch.open('.')
45
70
self.assertEqual(revision.NULL_REVISION, thebranch.last_revision())
47
72
thebranch.last_revision_info())
49
74
def simple_commit_a(self):
51
76
self.build_tree(['a'])
52
77
tests.run_git('add', 'a')
53
78
tests.run_git('commit', '-m', 'a')
72
97
self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)],
73
98
thebranch.revision_history())
100
def test_tag_annotated(self):
76
101
self.simple_commit_a()
77
102
reva = tests.run_git('rev-parse', 'HEAD').strip()
79
103
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())
104
thebranch = Branch.open('.')
105
self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
106
thebranch.tags.get_tag_dict())
109
self.simple_commit_a()
110
reva = tests.run_git('rev-parse', 'HEAD').strip()
111
tests.run_git('tag', '-m', 'add tag', 'foo')
112
thebranch = Branch.open('.')
113
self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
114
thebranch.tags.get_tag_dict())
86
118
class TestWithGitBranch(tests.TestCaseWithTransport):
89
121
tests.TestCaseWithTransport.setUp(self)
90
git.repo.Repo.create(self.test_dir)
122
dulwich.repo.Repo.create(self.test_dir)
91
123
self.git_branch = Branch.open(self.test_dir)
93
125
def test_get_parent(self):
109
141
def test_get_format_description(self):
110
142
self.assertEquals("Git Branch", self.format.get_format_description())
146
class BranchTests(tests.TestCaseInTempDir):
148
def make_onerev_branch(self):
152
bb = tests.GitBranchBuilder()
153
bb.set_file("foobar", "foo\nbar\n", False)
154
mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
155
gitsha = bb.finish()[mark]
159
def clone_git_branch(self, from_url, to_url):
160
from_dir = BzrDir.open(from_url)
161
to_dir = from_dir.sprout(to_url)
162
return to_dir.open_branch()
164
def test_single_rev(self):
165
path, gitsha = self.make_onerev_branch()
166
oldrepo = Repository.open(path)
167
revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
168
newbranch = self.clone_git_branch(path, "f")
169
self.assertEquals([revid], newbranch.repository.all_revision_ids())
171
def test_sprouted_tags(self):
172
path, gitsha = self.make_onerev_branch()
174
tests.run_git("tag", "lala")
175
os.chdir(self.test_dir)
176
oldrepo = Repository.open(path)
177
revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
178
newbranch = self.clone_git_branch(path, "f")
179
self.assertEquals({"lala": revid}, newbranch.tags.get_tag_dict())
180
self.assertEquals([revid], newbranch.repository.all_revision_ids())
183
class ForeignTestsBranchFactory(object):
185
def make_empty_branch(self, transport):
186
return LocalGitBzrDirFormat().initialize_on_transport(transport).open_branch()
188
make_branch = make_empty_branch