Skip to contentSkip to conversation

fetch2/git: fix shallow clone for tag containing slash

PATCH Superseded [email protected] 3 participants 5 messages May 14, 2025 – May 15, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fetch2/git: fix shallow clone for tag containing slash

From: Chen Qi <[email protected]>

If a tag contains slash, e.g., debian/5.22, then shallow clone fails because it's using a wrong ref.

To reproduce the issue, add the following lines in local.conf:

BB_GIT_SHALLOW = "1"
BB_GENERATE_SHALLOW_TARBALLS = "1"

And then run 'bitbake debianutils -c fetch'.

What the original os.path.basename(ref) wanted to do is to remove the strings such as refs/heads/. So we do it explitly to fix this issue.

---
 bitbake/lib/bb/fetch2/git.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
bitbake/lib/bb/fetch2/git.py +1 -1
index 11cda2007d..784a45bda2 100644
@@ -639,7 +639,7 @@ class Git(FetchMethod):
                 extra_refs.append(r)
 
         for ref in extra_refs:
-            ref_fetch = os.path.basename(ref)
+            ref_fetch = ref.replace('refs/heads/', '').replace('refs/remotes/origin/', '').replace('refs/tags/', '')
             runfetchcmd("%s fetch origin --depth 1 %s" % (ud.basecmd, ref_fetch), d, workdir=dest)
             revision = runfetchcmd("%s rev-parse FETCH_HEAD" % ud.basecmd, d, workdir=dest)
             runfetchcmd("%s update-ref %s %s" % (ud.basecmd, ref, revision), d, workdir=dest)
Signature · 1 line
2.34.1
#1 lore raw
Quoted 27 lines · Chen Qi via lists.openembedded.org

From: Chen Qi <[email protected]>

If a tag contains slash, e.g., debian/5.22, then shallow clone fails because it's using a wrong ref.

To reproduce the issue, add the following lines in local.conf:

  BB_GIT_SHALLOW = "1"
  BB_GENERATE_SHALLOW_TARBALLS = "1"

And then run 'bitbake debianutils -c fetch'.

What the original os.path.basename(ref) wanted to do is to remove the strings such as refs/heads/. So we do it explitly to fix this issue.

---
 bitbake/lib/bb/fetch2/git.py | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
bitbake/lib/bb/fetch2/git.py +0 -0
index 11cda2007d..784a45bda2 100644
@@ -639,7 +639,7 @@ class Git(FetchMethod):
                  extra_refs.append(r)
Quoted 8 lines


         for ref in extra_refs:
-            ref_fetch = os.path.basename(ref)
+            ref_fetch = ref.replace('refs/heads/', '').replace('refs/remotes/origin/', '').replace('refs/tags/', '') runfetchcmd("%s fetch origin --depth 1 %s" % (ud.basecmd, ref_fetch), d, workdir=dest) revision = runfetchcmd("%s rev-parse FETCH_HEAD" % ud.basecmd, d, workdir=dest) runfetchcmd("%s update-ref %s %s" % (ud.basecmd, ref, revision), d, workdir=dest)

Thanks, I just saw a few people reporting this.

Would it be possible to add a test case to bitbake-selftest so we can esure this doesn't regress in future?

Cheers,

Richard

author
#2 lore raw
Quoted 38 lines · Richard Purdie via lists.openembedded.org
Quoted 27 lines · Chen Qi via lists.openembedded.org

From: Chen Qi <[email protected]>

If a tag contains slash, e.g., debian/5.22, then shallow clone fails because it's using a wrong ref.

To reproduce the issue, add the following lines in local.conf:

  BB_GIT_SHALLOW = "1"
  BB_GENERATE_SHALLOW_TARBALLS = "1"

And then run 'bitbake debianutils -c fetch'.

What the original os.path.basename(ref) wanted to do is to remove the strings such as refs/heads/. So we do it explitly to fix this issue.

---
  bitbake/lib/bb/fetch2/git.py | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
bitbake/lib/bb/fetch2/git.py +0 -0
index 11cda2007d..784a45bda2 100644

bitbake/lib/bb/fetch2/git.py class Git(FetchMethod): · line 645

Quoted 8 lines
bitbake/lib/bb/fetch2/git.py +1 -1
@@ -639,7 +639,7 @@ class Git(FetchMethod):
                  extra_refs.append(r)
 
          for ref in extra_refs:
-            ref_fetch = os.path.basename(ref)
+            ref_fetch = ref.replace('refs/heads/', '').replace('refs/remotes/origin/', '').replace('refs/tags/', '')
              runfetchcmd("%s fetch origin --depth 1 %s" % (ud.basecmd, ref_fetch), d, workdir=dest)
              revision = runfetchcmd("%s rev-parse FETCH_HEAD" % ud.basecmd, d, workdir=dest)
              runfetchcmd("%s update-ref %s %s" % (ud.basecmd, ref, revision), d, workdir=dest)

Thanks, I just saw a few people reporting this.

Quoted 2 lines

Would it be possible to add a test case to bitbake-selftest so we can esure this doesn't regress in future?

Got it. I'll add a testcase and send out a new patch.

Regards,
Qi

Quoted 14 lines

Cheers,

Richard

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#17606): https://lists.openembedded.org/g/bitbake-devel/message/17606
Mute This Topic: https://lists.openembedded.org/mt/113103962/7304865
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#3 lore raw

there is a bug as well - this should help with
https://bugzilla.yoctoproject.org/show_bug.cgi?id=15862
so referring to that would be good

Quoted 66 lines · Chen Qi via lists.openembedded.org
Quoted 38 lines · Richard Purdie via lists.openembedded.org
Quoted 27 lines · Chen Qi via lists.openembedded.org

From: Chen Qi <[email protected]>

If a tag contains slash, e.g., debian/5.22, then shallow clone fails because it's using a wrong ref.

To reproduce the issue, add the following lines in local.conf:

BB_GIT_SHALLOW = "1"
BB_GENERATE_SHALLOW_TARBALLS = "1"

And then run 'bitbake debianutils -c fetch'.

What the original os.path.basename(ref) wanted to do is to remove the strings such as refs/heads/. So we do it explitly to fix this issue.

---
  bitbake/lib/bb/fetch2/git.py | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
bitbake/lib/bb/fetch2/git.py +0 -0
index 11cda2007d..784a45bda2 100644

bitbake/lib/bb/fetch2/git.py class Git(FetchMethod): · line 645

Quoted 8 lines
bitbake/lib/bb/fetch2/git.py +1 -1
@@ -639,7 +639,7 @@ class Git(FetchMethod):
                  extra_refs.append(r)
 
          for ref in extra_refs:
-            ref_fetch = os.path.basename(ref)
+            ref_fetch = ref.replace('refs/heads/', '').replace('refs/remotes/origin/', '').replace('refs/tags/', '')
              runfetchcmd("%s fetch origin --depth 1 %s" % (ud.basecmd, ref_fetch), d, workdir=dest)
              revision = runfetchcmd("%s rev-parse FETCH_HEAD" % ud.basecmd, d, workdir=dest)
              runfetchcmd("%s update-ref %s %s" % (ud.basecmd, ref, revision), d, workdir=dest)

Thanks, I just saw a few people reporting this.

Quoted 2 lines

Would it be possible to add a test case to bitbake-selftest so we can esure this doesn't regress in future?

Got it. I'll add a testcase and send out a new patch.

Regards,
Qi

Quoted 8 lines

Cheers,

Richard

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#17607): https://lists.openembedded.org/g/bitbake-devel/message/17607
Mute This Topic: https://lists.openembedded.org/mt/113103962/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

author
#4 lore raw

Thanks for the informaton.
I've updated the commit messages and sent out V2 patchset.

Regards,
Qi

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Khem Raj via lists.openembedded.org
Sent: Thursday, May 15, 2025 12:55 AM
To: Chen, Qi <[email protected]>
Cc: [email protected]; [email protected]; Yang, Liezhi <[email protected]>
Subject: Re: [bitbake-devel][PATCH] fetch2/git: fix shallow clone for tag containing slash

there is a bug as well - this should help with
https://bugzilla.yoctoproject.org/show_bug.cgi?id=15862
so referring to that would be good

Quoted 62 lines · Chen Qi via lists.openembedded.org
Quoted 40 lines · Richard Purdie via lists.openembedded.org
Quoted 35 lines · Chen Qi via lists.openembedded.org

From: Chen Qi <[email protected]>

If a tag contains slash, e.g., debian/5.22, then shallow clone fails because it's using a wrong ref.

To reproduce the issue, add the following lines in local.conf:

BB_GIT_SHALLOW = "1"
BB_GENERATE_SHALLOW_TARBALLS = "1"

And then run 'bitbake debianutils -c fetch'.

What the original os.path.basename(ref) wanted to do is to remove the strings such as refs/heads/. So we do it explitly to fix this issue.

---
  bitbake/lib/bb/fetch2/git.py | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
(quoted diff) +0 -0

b/bitbake/lib/bb/fetch2/git.py index 11cda2007d..784a45bda2 100644

bitbake/lib/bb/fetch2/git.py +2 -1
@@ -639,7 +639,7 @@ class Git(FetchMethod):
                  extra_refs.append(r)
 
          for ref in extra_refs:
-            ref_fetch = os.path.basename(ref)
+            ref_fetch = ref.replace('refs/heads/', 
+ '').replace('refs/remotes/origin/', '').replace('refs/tags/', '')
              runfetchcmd("%s fetch origin --depth 1 %s" % (ud.basecmd, ref_fetch), d, workdir=dest)
              revision = runfetchcmd("%s rev-parse FETCH_HEAD" % ud.basecmd, d, workdir=dest)
              runfetchcmd("%s update-ref %s %s" % (ud.basecmd, ref, 
Quoted 2 lines

revision), d, workdir=dest)

Thanks, I just saw a few people reporting this.

Quoted 2 lines

Would it be possible to add a test case to bitbake-selftest so we can esure this doesn't regress in future?

Got it. I'll add a testcase and send out a new patch.

Regards,
Qi

Quoted 8 lines

Cheers,

Richard