From 49ec431d9598a9a51bd08a15ee8ceb793042c3d3 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Wed, 2 Apr 2025 09:00:13 +0100 Subject: bitbake: fetch2/git: Handle srcrevs for annotated tags in tag check If SRCREV points at an annotated tag, the comparision code can fail as the resolved tag might not be the same sha. Handle this by also resolving the SRCREV. We only need to do this if they don't match in the first place for a minor performance win. Also add a test for this. (Bitbake rev: 136c06e251de68ed64355ec6b47a522ff3a372e3) Signed-off-by: Richard Purdie --- bitbake/lib/bb/fetch2/git.py | 7 ++++++- bitbake/lib/bb/tests/fetch.py | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'bitbake') diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py index 3a4ae6df45..5f4ec6128c 100644 --- a/bitbake/lib/bb/fetch2/git.py +++ b/bitbake/lib/bb/fetch2/git.py @@ -730,7 +730,12 @@ class Git(FetchMethod): output = runfetchcmd("%s rev-list -n 1 %s" % (ud.basecmd, ud.parm['tag']), d, workdir=destdir) output = output.strip() if output != ud.revision: - raise bb.fetch2.FetchError("The revision the git tag '%s' resolved to didn't match the SRCREV in use (%s vs %s)" % (ud.parm['tag'], output, ud.revision), ud.url) + # It is possible ud.revision is the revision on an annotated tag which won't match the output of rev-list + # If it resolves to the same thing there isn't a problem. + output2 = runfetchcmd("%s rev-list -n 1 %s" % (ud.basecmd, ud.revision), d, workdir=destdir) + output2 = output2.strip() + if output != output2: + raise bb.fetch2.FetchError("The revision the git tag '%s' resolved to didn't match the SRCREV in use (%s vs %s)" % (ud.parm['tag'], output, ud.revision), ud.url) repourl = self._get_repo_url(ud) runfetchcmd("%s remote set-url origin %s" % (ud.basecmd, shlex.quote(repourl)), d, workdir=destdir) diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py index 65339d1bb1..4b5439f525 100644 --- a/bitbake/lib/bb/tests/fetch.py +++ b/bitbake/lib/bb/tests/fetch.py @@ -3139,6 +3139,13 @@ class GitTagVerificationTests(FetcherTest): fetcher.download() fetcher.unpack(self.unpackdir) + def test_annotated_tag_rev_match(self): + # Test a url with rev= and tag= set works + # rev is the annotated tag revision in this case + fetcher = bb.fetch.Fetch(["git://git.openembedded.org/bitbake;branch=2.8;protocol=https;rev=6d363159e4b7dc566fc40d069b2615e61774a7d8;tag=2.8.7"], self.d) + fetcher.download() + fetcher.unpack(self.unpackdir) + @skipIfNoNetwork() def test_tag_rev_match2(self): # Test a url with SRCREV and tag= set works -- cgit v1.2.3-54-g00ecf