43
46
from bzrlib.repository import (
49
from bzrlib.symbol_versioning import (
52
from bzrlib.tests import TestSkipped
47
54
from bzrlib.plugins.git import (
48
LocalGitControlDirFormat,
58
from bzrlib.plugins.git.dir import (
59
LocalGitControlDirFormat,
52
61
from bzrlib.plugins.git.mapping import (
57
66
class TestGitBranch(tests.TestCaseInTempDir):
68
def test_open_by_ref(self):
71
urlutils.local_path_to_url(self.test_dir),
72
urllib.quote("refs/remotes/origin/unstable", safe='')
74
if bzrlib_version < (2, 5, 0):
75
self.assertRaises(errors.NotBranchError, BzrDir.open, url)
76
raise TestSkipped("opening by ref not supported with bzr < 2.5")
79
self.assertEquals(b.ref, "refs/remotes/origin/unstable")
59
81
def test_open_existing(self):
61
84
d = BzrDir.open('.')
62
85
thebranch = d.create_branch()
63
86
self.assertIsInstance(thebranch, branch.GitBranch)
65
88
def test_repr(self):
67
91
d = BzrDir.open('.')
68
92
thebranch = d.create_branch()
69
self.assertEquals("<LocalGitBranch('file://%s/', 'HEAD')>" % self.test_dir, repr(thebranch))
94
"<LocalGitBranch('%s/', u'')>" % (
95
urlutils.local_path_to_url(self.test_dir),),
71
98
def test_last_revision_is_null(self):
73
101
thedir = BzrDir.open('.')
74
102
thebranch = thedir.create_branch()
75
103
self.assertEqual(revision.NULL_REVISION, thebranch.last_revision())
96
124
revb = r.do_commit("b", committer="Somebody <foo@example.com>")
98
126
thebranch = Branch.open('.')
127
(warnings, history) = self.callCatchWarnings(thebranch.revision_history)
130
(len(warnings) == 1 and isinstance(warnings[0], DeprecationWarning)),
99
132
self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)],
100
thebranch.revision_history())
102
135
def test_tag_annotated(self):
103
136
reva = self.simple_commit_a()
131
164
tests.TestCaseWithTransport.setUp(self)
132
dulwich.repo.Repo.create(self.test_dir)
165
r = dulwich.repo.Repo.create(self.test_dir)
133
167
d = BzrDir.open(self.test_dir)
134
168
self.git_branch = d.create_branch()
171
205
mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
172
206
gitsha = bb.finish()[mark]
208
return os.path.abspath("d"), gitsha
176
210
def make_tworev_branch(self):
194
228
path, gitsha = self.make_onerev_branch()
195
229
oldrepo = Repository.open(path)
196
230
revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
231
self.assertEquals(gitsha, oldrepo._git.get_refs()["refs/heads/master"])
197
232
newbranch = self.clone_git_branch(path, "f")
198
233
self.assertEquals([revid], newbranch.repository.all_revision_ids())
236
271
inter_branch.pull(stop_revision=revid1)
237
272
self.assertEquals(revid1, newbranch.last_revision())
239
def test_interbranch_limited_pull(self):
274
def test_interbranch_pull_with_tags(self):
240
275
path, (gitsha1, gitsha2) = self.make_tworev_branch()
276
gitrepo = GitRepo(path)
277
gitrepo.refs["refs/tags/sometag"] = gitsha2
241
278
oldrepo = Repository.open(path)
242
279
revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
243
280
revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
244
281
newbranch = self.make_branch('g')
245
inter_branch = InterBranch.get(Branch.open(path), newbranch)
246
inter_branch.pull(limit=1)
282
source_branch = Branch.open(path)
283
source_branch.get_config().set_user_option("branch.fetch_tags", True)
284
inter_branch = InterBranch.get(source_branch, newbranch)
285
inter_branch.pull(stop_revision=revid1)
247
286
self.assertEquals(revid1, newbranch.last_revision())
248
inter_branch.pull(limit=1)
249
self.assertEquals(revid2, newbranch.last_revision())
287
self.assertTrue(newbranch.repository.has_revision(revid2))
252
290
class ForeignTestsBranchFactory(object):