Skip to contentSkip to conversation

fetch2/git: Improve shallow clone tag fetching

PATCH New Richard Purdie 1 participant 2 messages Jun 25, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 fetch2/git: Improve shallow clone tag fetching

Currently, tags are fetched as just a name, which works but means they're not seen as tags by git commands like git describe. Instead, fetch them as refs/tags/XXX which means such commands then work correctly.

---
 lib/bb/fetch2/git.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/fetch2/git.py +1 -1
index 0af8070080b..e7b030998c0 100644
@@ -634,7 +634,7 @@ class Git(FetchMethod):
             all_refs.append(line.split()[-1])
         extra_refs = []
         if 'tag' in ud.parm:
-            extra_refs.append(ud.parm['tag'])
+            extra_refs.append("refs/tags/" + ud.parm['tag'])
         for r in ud.shallow_extra_refs:
             if not ud.bareclone:
                 r = r.replace('refs/heads/', 'refs/remotes/origin/')
#1 lore raw

PATCH 2/2 fetch2/git: Add tag to shallow clone tarball name

It makes sense to allow the shallow clone mirror tarball name to include the tag name so that tags can be added to existing urls and the tarballs will be maintained correctly. The code already allows this to be done easily just by moving the tag handling code.

---
 lib/bb/fetch2/git.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/bb/fetch2/git.py +2 -2
index e7b030998c0..14ec45a3f67 100644
@@ -199,6 +199,8 @@ class Git(FetchMethod):
         ud.shallow_skip_fast = False
         ud.shallow = d.getVar("BB_GIT_SHALLOW") == "1"
         ud.shallow_extra_refs = (d.getVar("BB_GIT_SHALLOW_EXTRA_REFS") or "").split()
+        if 'tag' in ud.parm:
+            ud.shallow_extra_refs.append("refs/tags/" + ud.parm['tag'])
 
         depth_default = d.getVar("BB_GIT_SHALLOW_DEPTH")
         if depth_default is not None:
@@ -633,8 +635,6 @@ class Git(FetchMethod):
         for line in all_refs_remote:
             all_refs.append(line.split()[-1])
         extra_refs = []
-        if 'tag' in ud.parm:
-            extra_refs.append("refs/tags/" + ud.parm['tag'])
         for r in ud.shallow_extra_refs:
             if not ud.bareclone:
                 r = r.replace('refs/heads/', 'refs/remotes/origin/')