47
41
from bzrlib.plugins.git import (
48
LocalGitControlDirFormat,
52
from bzrlib.plugins.git.mapping import (
45
from bzrlib.plugins.git.mapping import default_mapping
57
48
class TestGitBranch(tests.TestCaseInTempDir):
50
_test_needs_features = [tests.GitCommandFeature]
59
52
def test_open_existing(self):
62
thebranch = d.create_branch()
55
thebranch = Branch.open('.')
63
56
self.assertIsInstance(thebranch, branch.GitBranch)
65
58
def test_repr(self):
68
thebranch = d.create_branch()
69
self.assertEquals("<LocalGitBranch('file://%s/', 'HEAD')>" % self.test_dir, repr(thebranch))
60
thebranch = Branch.open('.')
61
self.assertEquals("LocalGitBranch('file://%s/', 'HEAD')" % self.test_dir, repr(thebranch))
71
63
def test_last_revision_is_null(self):
73
thedir = BzrDir.open('.')
74
thebranch = thedir.create_branch()
66
thebranch = Branch.open('.')
75
67
self.assertEqual(revision.NULL_REVISION, thebranch.last_revision())
76
68
self.assertEqual((0, revision.NULL_REVISION),
77
69
thebranch.last_revision_info())
79
71
def simple_commit_a(self):
81
73
self.build_tree(['a'])
83
return r.do_commit("a", committer="Somebody <foo@example.com>")
74
tests.run_git('add', 'a')
75
tests.run_git('commit', '-m', 'a')
85
77
def test_last_revision_is_valid(self):
86
head = self.simple_commit_a()
78
self.simple_commit_a()
79
head = tests.run_git('rev-parse', 'HEAD').strip()
87
81
thebranch = Branch.open('.')
88
82
self.assertEqual(default_mapping.revision_id_foreign_to_bzr(head),
89
83
thebranch.last_revision())
91
85
def test_revision_history(self):
92
reva = self.simple_commit_a()
86
self.simple_commit_a()
87
reva = tests.run_git('rev-parse', 'HEAD').strip()
93
88
self.build_tree(['b'])
96
revb = r.do_commit("b", committer="Somebody <foo@example.com>")
89
tests.run_git('add', 'b')
90
tests.run_git('commit', '-m', 'b')
91
revb = tests.run_git('rev-parse', 'HEAD').strip()
98
93
thebranch = Branch.open('.')
99
94
self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)],
100
95
thebranch.revision_history())
102
97
def test_tag_annotated(self):
103
reva = self.simple_commit_a()
106
o.tagger = "Jelmer <foo@example.com>"
107
o.message = "add tag"
108
o.object = (Commit, reva)
112
r.object_store.add_object(o)
113
r['refs/tags/foo'] = o.id
98
self.simple_commit_a()
99
reva = tests.run_git('rev-parse', 'HEAD').strip()
100
tests.run_git('tag', '-a', '-m', 'add tag', 'foo')
114
101
thebranch = Branch.open('.')
115
102
self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
116
103
thebranch.tags.get_tag_dict())
118
105
def test_tag(self):
119
reva = self.simple_commit_a()
121
r.refs["refs/tags/foo"] = reva
106
self.simple_commit_a()
107
reva = tests.run_git('rev-parse', 'HEAD').strip()
108
tests.run_git('tag', '-m', 'add tag', 'foo')
122
109
thebranch = Branch.open('.')
123
110
self.assertEquals({"foo": default_mapping.revision_id_foreign_to_bzr(reva)},
124
111
thebranch.tags.get_tag_dict())
128
115
class TestWithGitBranch(tests.TestCaseWithTransport):
131
118
tests.TestCaseWithTransport.setUp(self)
132
119
dulwich.repo.Repo.create(self.test_dir)
133
d = BzrDir.open(self.test_dir)
134
self.git_branch = d.create_branch()
120
self.git_branch = Branch.open(self.test_dir)
136
122
def test_get_parent(self):
137
123
self.assertIs(None, self.git_branch.get_parent())
139
125
def test_get_stacked_on_url(self):
140
self.assertRaises(errors.UnstackableBranchFormat,
141
self.git_branch.get_stacked_on_url)
126
self.assertIs(None, self.git_branch.get_stacked_on_url())
143
128
def test_get_physical_lock_status(self):
144
129
self.assertFalse(self.git_branch.get_physical_lock_status())
200
168
def test_sprouted_tags(self):
201
169
path, gitsha = self.make_onerev_branch()
203
r.refs["refs/tags/lala"] = r.head()
171
tests.run_git("tag", "lala")
172
os.chdir(self.test_dir)
204
173
oldrepo = Repository.open(path)
205
174
revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
206
175
newbranch = self.clone_git_branch(path, "f")
207
176
self.assertEquals({"lala": revid}, newbranch.tags.get_tag_dict())
208
177
self.assertEquals([revid], newbranch.repository.all_revision_ids())
210
def test_interbranch_pull(self):
211
path, (gitsha1, gitsha2) = self.make_tworev_branch()
212
oldrepo = Repository.open(path)
213
revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
214
newbranch = self.make_branch('g')
215
inter_branch = InterBranch.get(Branch.open(path), newbranch)
217
self.assertEquals(revid2, newbranch.last_revision())
219
def test_interbranch_pull_noop(self):
220
path, (gitsha1, gitsha2) = self.make_tworev_branch()
221
oldrepo = Repository.open(path)
222
revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
223
newbranch = self.make_branch('g')
224
inter_branch = InterBranch.get(Branch.open(path), newbranch)
226
# This is basically "assertNotRaises"
228
self.assertEquals(revid2, newbranch.last_revision())
230
def test_interbranch_pull_stop_revision(self):
231
path, (gitsha1, gitsha2) = self.make_tworev_branch()
232
oldrepo = Repository.open(path)
233
revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
234
newbranch = self.make_branch('g')
235
inter_branch = InterBranch.get(Branch.open(path), newbranch)
236
inter_branch.pull(stop_revision=revid1)
237
self.assertEquals(revid1, newbranch.last_revision())
239
def test_interbranch_limited_pull(self):
240
path, (gitsha1, gitsha2) = self.make_tworev_branch()
241
oldrepo = Repository.open(path)
242
revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
243
revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
244
newbranch = self.make_branch('g')
245
inter_branch = InterBranch.get(Branch.open(path), newbranch)
246
inter_branch.pull(limit=1)
247
self.assertEquals(revid1, newbranch.last_revision())
248
inter_branch.pull(limit=1)
249
self.assertEquals(revid2, newbranch.last_revision())
252
class ForeignTestsBranchFactory(object):
254
def make_empty_branch(self, transport):
255
d = LocalGitControlDirFormat().initialize_on_transport(transport)
256
return d.create_branch()
258
make_branch = make_empty_branch