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
83
d = BzrDir.open('.')
67
89
d = BzrDir.open('.')
68
90
thebranch = d.create_branch()
69
self.assertEquals("<LocalGitBranch('file://%s/', 'HEAD')>" % self.test_dir, repr(thebranch))
92
"<LocalGitBranch('%s/', u'master')>" % (
93
urlutils.local_path_to_url(self.test_dir),),
71
96
def test_last_revision_is_null(self):
96
121
revb = r.do_commit("b", committer="Somebody <foo@example.com>")
98
123
thebranch = Branch.open('.')
124
(warnings, history) = self.callCatchWarnings(thebranch.revision_history)
127
(len(warnings) == 1 and isinstance(warnings[0], DeprecationWarning)),
99
129
self.assertEqual([default_mapping.revision_id_foreign_to_bzr(r) for r in (reva, revb)],
100
thebranch.revision_history())
102
132
def test_tag_annotated(self):
103
133
reva = self.simple_commit_a()
171
201
mark = bb.commit("Somebody <somebody@someorg.org>", "mymsg")
172
202
gitsha = bb.finish()[mark]
204
return os.path.abspath("d"), gitsha
176
206
def make_tworev_branch(self):
194
224
path, gitsha = self.make_onerev_branch()
195
225
oldrepo = Repository.open(path)
196
226
revid = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha)
227
self.assertEquals(gitsha, oldrepo._git.get_refs()["refs/heads/master"])
197
228
newbranch = self.clone_git_branch(path, "f")
198
229
self.assertEquals([revid], newbranch.repository.all_revision_ids())
236
267
inter_branch.pull(stop_revision=revid1)
237
268
self.assertEquals(revid1, newbranch.last_revision())
239
def test_interbranch_limited_pull(self):
270
def test_interbranch_pull_with_tags(self):
240
271
path, (gitsha1, gitsha2) = self.make_tworev_branch()
272
gitrepo = GitRepo(path)
273
gitrepo.refs["refs/tags/sometag"] = gitsha2
241
274
oldrepo = Repository.open(path)
242
275
revid1 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha1)
243
276
revid2 = oldrepo.get_mapping().revision_id_foreign_to_bzr(gitsha2)
244
277
newbranch = self.make_branch('g')
245
inter_branch = InterBranch.get(Branch.open(path), newbranch)
246
inter_branch.pull(limit=1)
278
source_branch = Branch.open(path)
279
source_branch.get_config().set_user_option("branch.fetch_tags", True)
280
inter_branch = InterBranch.get(source_branch, newbranch)
281
inter_branch.pull(stop_revision=revid1)
247
282
self.assertEquals(revid1, newbranch.last_revision())
248
inter_branch.pull(limit=1)
249
self.assertEquals(revid2, newbranch.last_revision())
283
self.assertTrue(newbranch.repository.has_revision(revid2))
252
286
class ForeignTestsBranchFactory(object):