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"""
22
from dulwich.repo import (
22
28
from bzrlib import (
25
32
from bzrlib.branch import (
28
36
from bzrlib.bzrdir import (
44
55
_test_needs_features = [tests.GitCommandFeature]
46
57
def test_open_existing(self):
49
thebranch = Branch.open('.')
60
thebranch = d.create_branch()
50
61
self.assertIsInstance(thebranch, branch.GitBranch)
66
thebranch = d.create_branch()
67
self.assertEquals("<LocalGitBranch('file://%s/', 'refs/heads/master')>" % self.test_dir, repr(thebranch))
52
69
def test_last_revision_is_null(self):
55
thebranch = Branch.open('.')
71
thedir = BzrDir.open('.')
72
thebranch = thedir.create_branch()
56
73
self.assertEqual(revision.NULL_REVISION, thebranch.last_revision())
57
74
self.assertEqual((0, revision.NULL_REVISION),
58
75
thebranch.last_revision_info())
60
77
def simple_commit_a(self):
62
79
self.build_tree(['a'])
63
80
tests.run_git('add', 'a')
64
81
tests.run_git('commit', '-m', 'a')
107
123
tests.TestCaseWithTransport.setUp(self)
108
git.repo.Repo.create(self.test_dir)
109
self.git_branch = Branch.open(self.test_dir)
124
dulwich.repo.Repo.create(self.test_dir)
125
d = BzrDir.open(self.test_dir)
126
self.git_branch = d.create_branch()
111
128
def test_get_parent(self):
112
129
self.assertIs(None, self.git_branch.get_parent())
114
131
def test_get_stacked_on_url(self):
115
self.assertIs(None, self.git_branch.get_stacked_on_url())
132
self.assertRaises(errors.UnstackableBranchFormat,
133
self.git_branch.get_stacked_on_url)
117
135
def test_get_physical_lock_status(self):
118
136
self.assertFalse(self.git_branch.get_physical_lock_status())
143
161
return "d", gitsha
163
def make_tworev_branch(self):
167
bb = tests.GitBranchBuilder()
168
bb.set_file("foobar", "foo\nbar\n", False)
169
mark1 = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
170
mark2 = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
173
return "d", (marks[mark1], marks[mark2])
145
175
def clone_git_branch(self, from_url, to_url):
146
176
from_dir = BzrDir.open(from_url)
147
177
to_dir = from_dir.sprout(to_url)
164
194
newbranch = self.clone_git_branch(path, "f")
165
195
self.assertEquals({"lala": revid}, newbranch.tags.get_tag_dict())
166
196
self.assertEquals([revid], newbranch.repository.all_revision_ids())
198
def test_interbranch_pull(self):
199
path, (gitsha1, gitsha2) = self.make_tworev_branch()
200
oldrepo = Repository.open(path)
201
revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
202
newbranch = self.make_branch('g')
203
inter_branch = InterBranch.get(Branch.open(path), newbranch)
205
self.assertEquals(revid2, newbranch.last_revision())
207
def test_interbranch_pull_noop(self):
208
path, (gitsha1, gitsha2) = self.make_tworev_branch()
209
oldrepo = Repository.open(path)
210
revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
211
newbranch = self.make_branch('g')
212
inter_branch = InterBranch.get(Branch.open(path), newbranch)
214
# This is basically "assertNotRaises"
216
self.assertEquals(revid2, newbranch.last_revision())
218
def test_interbranch_pull_stop_revision(self):
219
path, (gitsha1, gitsha2) = self.make_tworev_branch()
220
oldrepo = Repository.open(path)
221
revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
222
newbranch = self.make_branch('g')
223
inter_branch = InterBranch.get(Branch.open(path), newbranch)
224
inter_branch.pull(stop_revision=revid1)
225
self.assertEquals(revid1, newbranch.last_revision())
227
def test_interbranch_limited_pull(self):
228
path, (gitsha1, gitsha2) = self.make_tworev_branch()
229
oldrepo = Repository.open(path)
230
revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
231
revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
232
newbranch = self.make_branch('g')
233
inter_branch = InterBranch.get(Branch.open(path), newbranch)
234
inter_branch.pull(limit=1)
235
self.assertEquals(revid1, newbranch.last_revision())
236
inter_branch.pull(limit=1)
237
self.assertEquals(revid2, newbranch.last_revision())
240
class ForeignTestsBranchFactory(object):
242
def make_empty_branch(self, transport):
243
d = LocalGitBzrDirFormat().initialize_on_transport(transport)
244
return d.create_branch()
246
make_branch = make_empty_branch