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 (
32
from bzrlib.branch import (
35
from bzrlib.bzrdir import (
38
from bzrlib.repository import (
22
42
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):
94
126
self.assertIs(None, self.git_branch.get_parent())
96
128
def test_get_stacked_on_url(self):
97
self.assertIs(None, self.git_branch.get_stacked_on_url())
129
self.assertRaises(errors.UnstackableBranchFormat,
130
self.git_branch.get_stacked_on_url)
99
132
def test_get_physical_lock_status(self):
100
133
self.assertFalse(self.git_branch.get_physical_lock_status())
109
142
def test_get_format_description(self):
110
143
self.assertEquals("Git Branch", self.format.get_format_description())
147
class BranchTests(tests.TestCaseInTempDir):
149
def make_onerev_branch(self):
153
bb = tests.GitBranchBuilder()
154
bb.set_file("foobar", "foo\nbar\n", False)
155
mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
156
gitsha = bb.finish()[mark]
160
def clone_git_branch(self, from_url, to_url):
161
from_dir = BzrDir.open(from_url)
162
to_dir = from_dir.sprout(to_url)
163
return to_dir.open_branch()
165
def test_single_rev(self):
166
path, gitsha = self.make_onerev_branch()
167
oldrepo = Repository.open(path)
168
revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
169
newbranch = self.clone_git_branch(path, "f")
170
self.assertEquals([revid], newbranch.repository.all_revision_ids())
172
def test_sprouted_tags(self):
173
path, gitsha = self.make_onerev_branch()
175
tests.run_git("tag", "lala")
176
os.chdir(self.test_dir)
177
oldrepo = Repository.open(path)
178
revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
179
newbranch = self.clone_git_branch(path, "f")
180
self.assertEquals({"lala": revid}, newbranch.tags.get_tag_dict())
181
self.assertEquals([revid], newbranch.repository.all_revision_ids())