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