diff mbox series

[1/2] fetch/gitsm: Store the original url data to fix relative gitsm paths

Message ID 20260907131034.3989354-1-richard.purdie@linuxfoundation.org
State Accepted, archived
Commit 58872250f72f5760b4126552bdec5497f5a1a1f4
Headers show
Series [1/2] fetch/gitsm: Store the original url data to fix relative gitsm paths | expand

Commit Message

Richard Purdie Sept. 7, 2026, 1:10 p.m. UTC
If the gitsm:// url contains a git submodule with a relative "../" path
and the fetcher is configured to use a premirror, it will fail as the
host name encoded in the original url is lost and the correct paths
can't be found.

Save the original url data in the new data so that it can be consulted to
fix this kind of edge case.

The test case change that follows this provides a test of this functionality.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/fetch/__init__.py | 1 +
 lib/bb/fetch/gitsm.py    | 5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/bb/fetch/__init__.py b/lib/bb/fetch/__init__.py
index 153700dfb4f..55ab710f3d3 100644
--- a/lib/bb/fetch/__init__.py
+++ b/lib/bb/fetch/__init__.py
@@ -1059,6 +1059,7 @@  def build_mirroruris(origud, mirrors, ld):
                     newud.setup_localpath(ld)
                     if hasattr(ud, 'unpack_tracer'):
                         newud.unpack_tracer = ud.unpack_tracer
+                    newud.origud = ud
                 except bb.fetch.BBFetchException as e:
                     logger.debug("Mirror fetch failure for url %s (original url: %s)" % (newuri, origud.url))
                     logger.debug(str(e))
diff --git a/lib/bb/fetch/gitsm.py b/lib/bb/fetch/gitsm.py
index 734b35364d9..d9facdd2706 100644
--- a/lib/bb/fetch/gitsm.py
+++ b/lib/bb/fetch/gitsm.py
@@ -88,7 +88,10 @@  class GitSM(Git):
 
             # Convert relative to absolute uri based on parent uri
             if  uris[m].startswith('..') or uris[m].startswith('./'):
-                newud = copy.copy(ud)
+                if hasattr(ud, "origud"):
+                    newud = copy.copy(ud.origud)
+                else:
+                    newud = copy.copy(ud)
                 newud.path = os.path.normpath(os.path.join(newud.path, uris[m]))
                 uris[m] = Git._get_repo_url(self, newud)