diff mbox series

[3/3] fetch2/git: Make latest_versionstring extract tags with slashes correctly

Message ID 20240219003805.3024867-3-pkj@axis.com
State Accepted, archived
Commit 8b21024b9966d5158ac4a77e87ffb935c2a57764
Headers show
Series [1/3] tests/fetch: Make test_git_latest_versionstring support a max version | expand

Commit Message

Peter Kjellerstedt Feb. 19, 2024, 12:38 a.m. UTC
Before, everything up to the last slash was removed when extracting the
names of the tags. This would lead to that a tag such as "agent/11.0.0"
would be incorrectly identified as "11.0.0", which would then be treated
as a correct version matching "^(?P<pver>\d+(\.\d+)+)".

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
---
 bitbake/lib/bb/fetch2/git.py  | 9 +++++++--
 bitbake/lib/bb/tests/fetch.py | 2 ++
 2 files changed, 9 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
index a69371a57e..9e09678494 100644
--- a/bitbake/lib/bb/fetch2/git.py
+++ b/bitbake/lib/bb/fetch2/git.py
@@ -818,6 +818,7 @@  class Git(FetchMethod):
             bb.note("Could not list remote: %s" % str(e))
             return pupver
 
+        rev_tag_re = re.compile(r"([0-9a-f]{40})\s+refs/tags/(.*)")
         pver_re = re.compile(d.getVar('UPSTREAM_CHECK_GITTAGREGEX') or r"(?P<pver>([0-9][\.|_]?)+)")
         nonrel_re = re.compile(r"(alpha|beta|rc|final)+")
 
@@ -826,7 +827,12 @@  class Git(FetchMethod):
             if not line:
                 break
 
-            tag = line.split("/")[-1]
+            m = rev_tag_re.match(line)
+            if not m:
+                continue
+
+            (revision, tag) = m.groups()
+
             # Ignore non-released branches
             if nonrel_re.search(tag):
                 continue
@@ -842,7 +848,6 @@  class Git(FetchMethod):
                 continue
 
             verstring = pver
-            revision = line.split()[0]
             pupver = (verstring, revision)
 
         return pupver
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index 7e7f26d003..832ae4d627 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -1401,6 +1401,8 @@  class FetchLatestVersionTest(FetcherTest):
             : "1.3.59",
         ("remake", "git://github.com/rocky/remake.git;protocol=https;branch=master", "f05508e521987c8494c92d9c2871aec46307d51d", r"(?P<pver>(\d+\.(\d+\.)*\d*(\+dbg\d+(\.\d+)*)*))", "")
             : "3.82+dbg0.9",
+        ("sysdig", "git://github.com/draios/sysdig.git;branch=dev;protocol=https", "4fb6288275f567f63515df0ff0a6518043ecfa9b", r"^(?P<pver>\d+(\.\d+)+)", "10.0.0")
+            : "0.28.0",
     }
 
     test_wget_uris = {