summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorGyorgy Sarvari <skandigraun@gmail.com>2025-08-15 21:44:01 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-08-19 11:35:52 +0100
commit3d451f3452643a6fcaa7ff9345a6f955392daec3 (patch)
treeb833abc48bb9b3f27c30a5f8b6440b244396ec69 /bitbake
parent2f808c92cc8d09a42e66f522c6c3f798cabf52d3 (diff)
downloadpoky-3d451f3452643a6fcaa7ff9345a6f955392daec3.tar.gz
bitbake: fetch2/git: verify if local clone contains tag
In case a recipe specifies a git SRC_URI along with revision and tag, but only the revision is present in the local clone without the tag (because it was tagged after it was cloned), then unpacking fails with the following error: ... rev-list -n 1 1.0 failed with exit code 128, output:\nfatal: ambiguous argument \'1.0\': unknown revision or path not in the working tree This happens because the during the download step only the revision's presence is verified to decide if the repository needs to be updated. To avoid this, check also if the tag is present in the local repository, when the "tag" tag is specified. (Bitbake rev: 546b347b4d3d82c01ecc99f45296f66e44638adc) Signed-off-by: Gyorgy Sarvari <skandigraun@gmail.com> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/fetch2/git.py10
-rw-r--r--bitbake/lib/bb/tests/fetch.py44
2 files changed, 51 insertions, 3 deletions
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
index ecaf0a49af..52fffe21d7 100644
--- a/bitbake/lib/bb/fetch2/git.py
+++ b/bitbake/lib/bb/fetch2/git.py
@@ -323,6 +323,8 @@ class Git(FetchMethod):
323 return True 323 return True
324 if not self._contains_ref(ud, d, ud.name, ud.clonedir): 324 if not self._contains_ref(ud, d, ud.name, ud.clonedir):
325 return True 325 return True
326 if 'tag' in ud.parm and not self._contains_ref(ud, d, ud.name, ud.clonedir, tag=True):
327 return True
326 return False 328 return False
327 329
328 def lfs_need_update(self, ud, d): 330 def lfs_need_update(self, ud, d):
@@ -775,14 +777,16 @@ class Git(FetchMethod):
775 def supports_srcrev(self): 777 def supports_srcrev(self):
776 return True 778 return True
777 779
778 def _contains_ref(self, ud, d, name, wd): 780 def _contains_ref(self, ud, d, name, wd, tag=False):
779 cmd = "" 781 cmd = ""
782 git_ref_name = 'refs/tags/%s' % ud.parm['tag'] if tag else ud.revision
783
780 if ud.nobranch: 784 if ud.nobranch:
781 cmd = "%s log --pretty=oneline -n 1 %s -- 2> /dev/null | wc -l" % ( 785 cmd = "%s log --pretty=oneline -n 1 %s -- 2> /dev/null | wc -l" % (
782 ud.basecmd, ud.revision) 786 ud.basecmd, git_ref_name)
783 else: 787 else:
784 cmd = "%s branch --contains %s --list %s 2> /dev/null | wc -l" % ( 788 cmd = "%s branch --contains %s --list %s 2> /dev/null | wc -l" % (
785 ud.basecmd, ud.revision, ud.branch) 789 ud.basecmd, git_ref_name, ud.branch)
786 try: 790 try:
787 output = runfetchcmd(cmd, d, quiet=True, workdir=wd) 791 output = runfetchcmd(cmd, d, quiet=True, workdir=wd)
788 except bb.fetch2.FetchError: 792 except bb.fetch2.FetchError:
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index cde1bf3390..d216eac2ab 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -2647,6 +2647,50 @@ class GitURLWithSpacesTest(FetcherTest):
2647 self.assertEqual(ud.fullmirror, os.path.join(self.dldir, "git2_" + ref['gitsrcname'] + '.tar.gz')) 2647 self.assertEqual(ud.fullmirror, os.path.join(self.dldir, "git2_" + ref['gitsrcname'] + '.tar.gz'))
2648 self.assertEqual(ud.method._get_repo_url(ud), ref['repo_url']) 2648 self.assertEqual(ud.method._get_repo_url(ud), ref['repo_url'])
2649 2649
2650
2651class FetchLocallyMissingTagFromRemote(FetcherTest):
2652 def setUp(self):
2653 FetcherTest.setUp(self)
2654 self.gitdir = os.path.join(self.tempdir, 'git')
2655 self.srcdir = os.path.join(self.tempdir, 'gitsource')
2656
2657 bb.utils.mkdirhier(self.srcdir)
2658 self.git_init(cwd=self.srcdir)
2659 self.d.setVar('WORKDIR', self.tempdir)
2660 self.d.setVar('S', self.gitdir)
2661
2662 uri = 'git://%s;protocol=file;subdir=${S};branch=master' % self.srcdir
2663 self.d.setVar('SRC_URI', uri)
2664
2665 open(os.path.join(self.srcdir, 'dummyfile'), 'w').close()
2666 self.git(['add', 'dummyfile'], self.srcdir)
2667 self.git(['commit', '-m', 'dummymsg', 'dummyfile'], self.srcdir)
2668
2669 def _fetch_and_unpack(self, uri_to_fetch):
2670 fetcher = bb.fetch2.Fetch([uri_to_fetch], self.d)
2671 fetcher.download()
2672 fetcher.unpack(self.d.getVar('WORKDIR'))
2673
2674 def test_tag_present_in_remote_but_not_local(self):
2675 # fetch a repo that has no tag in it
2676 # then add a tag to this repo, and fetch it again, without
2677 # changing SRC_REV, but by adding ';tag=tag1` to SRC_URI
2678 # the new tag should be fetched and unpacked
2679 srcrev = self.git('rev-parse HEAD', cwd=self.srcdir).strip()
2680 self.d.setVar('SRCREV', srcrev)
2681 src_uri = self.d.getVar('SRC_URI')
2682 self._fetch_and_unpack(src_uri)
2683
2684 self.git('tag -m -a tag1', cwd=self.srcdir)
2685
2686 src_uri = '%s;tag=tag1' % self.d.getVar('SRC_URI').split()[0]
2687 self.d.setVar('SRC_URI', src_uri)
2688 self._fetch_and_unpack(src_uri)
2689
2690 output = self.git('log --pretty=oneline -n 1 refs/tags/tag1', cwd=self.gitdir)
2691 assert "fatal: ambiguous argument" not in output
2692
2693
2650class CrateTest(FetcherTest): 2694class CrateTest(FetcherTest):
2651 @skipIfNoNetwork() 2695 @skipIfNoNetwork()
2652 def test_crate_url(self): 2696 def test_crate_url(self):