Skip to contentSkip to conversation

fetch2/git: verify if local clone contains tag

PATCH In review Gyorgy Sarvari 2 participants 2 messages Aug 15, 2025 – Aug 19, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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/lib/bb/fetch2/git.py  | 10 +++++---
 bitbake/lib/bb/tests/fetch.py | 44 +++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 3 deletions(-)
bitbake/lib/bb/fetch2/git.py +7 -3
index ecaf0a49af..52fffe21d7 100644
@@ -323,6 +323,8 @@ class Git(FetchMethod):
             return True
         if not self._contains_ref(ud, d, ud.name, ud.clonedir):
             return True
+        if 'tag' in ud.parm and not self._contains_ref(ud, d, ud.name, ud.clonedir, tag=True):
+            return True
         return False
 
     def lfs_need_update(self, ud, d):
@@ -775,14 +777,16 @@ class Git(FetchMethod):
     def supports_srcrev(self):
         return True
 
-    def _contains_ref(self, ud, d, name, wd):
+    def _contains_ref(self, ud, d, name, wd, tag=False):
         cmd = ""
+        git_ref_name = 'refs/tags/%s' % ud.parm['tag'] if tag else ud.revision
+
         if ud.nobranch:
             cmd = "%s log --pretty=oneline -n 1 %s -- 2> /dev/null | wc -l" % (
-                ud.basecmd, ud.revision)
+                ud.basecmd, git_ref_name)
         else:
             cmd =  "%s branch --contains %s --list %s 2> /dev/null | wc -l" % (
-                ud.basecmd, ud.revision, ud.branch)
+                ud.basecmd, git_ref_name, ud.branch)
         try:
             output = runfetchcmd(cmd, d, quiet=True, workdir=wd)
         except bb.fetch2.FetchError:
bitbake/lib/bb/tests/fetch.py +44 -0

50 lines not on this page · raw message

#1 lore raw
Quoted 9 lines · Gyorgy Sarvari via lists.openembedded.org

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.

Quoted 8 lines

To avoid this, check also if the tag is present in the local repository, when the "tag" tag is specified.

---
 bitbake/lib/bb/fetch2/git.py  | 10 +++++--- bitbake/lib/bb/tests/fetch.py | 44 +++++++++++++++++++++++++++++++++++

 2 files changed, 51 insertions(+), 3 deletions(-)

Thanks for this. I suspected there was this problem and your patch confirms what I suspected. I really appreciate adding a test case too, thanks!

Cheers,

Richard