Skip to contentSkip to conversation

Don't parse nonstandard git-version suffix

PATCH Applied Jonas Rebmann 2 participants 2 messages Sep 5, 2025 – Sep 8, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Don't parse nonstandard git-version suffix

In snapshot builds of git, git-version yields a nonstandard version format like 2.51.0.178.g2462961280. packaging.version.parse() errors out on this with an InvalidVersion exception.

Since we only need to compare major and minor version, and packaging.version is intended for a different version scheme, resort to comparing the two numbers manually.

Fixes 2e5aec1cd7ec ("Add Git version check to prevent crash with '--default-prefix' parameter")

---
Changes in v2:
- Update commit message after git patch to change output was rejected
- Ignore patch version and regex-match git-version text (Thanks, Konstantin)
- Manually parse version instead of regex-filtering before a version.parse()
- Link to v1: https://patch.msgid.link/[email protected]

---
 requirements.txt   | 1 -
 src/b4/__init__.py | 6 +++---
 2 files changed, 3 insertions(+), 4 deletions(-)
requirements.txt +0 -1
index ed9b832..3781f49 100644
@@ -210,4 +210,3 @@ urllib3==2.4.0 \
     --hash=sha256:414bc6535b787febd7567804cc015fee39daab8ad86268f1310a9250697de466 \
     --hash=sha256:4e16665048960a0900c702d4a66415956a584919c03361cac9f1df5c5dd7e813
     # via requests
-packaging
\ No newline at end of file
src/b4/__init__.py +3 -3
index 33aee1f..07e1cb0 100644
@@ -43,7 +43,6 @@ ConfigDictT = Dict[str, Union[str, List[str], None]]
 from email.message import EmailMessage
 
 from email import charset
-from packaging import version
 
 charset.add_charset('utf-8', None)
 # Policy we use for saving mail locally
@@ -2841,8 +2840,9 @@ def git_run_command(gitdir: Optional[Union[str, Path]], args: List[str], stdin:
 
 def git_check_minimal_version(min_version: str) -> bool:
     ecode, out = git_run_command(None, ["version"])
-    current_version = out.split()[2]
-    return version.parse(current_version) >= version.parse(min_version)
+    current_version = re.sub(r"git version (\d+\.\d+)\..*", r"\1", out)
+    return tuple(map(int, current_version.split(".")[:2])) >= tuple(map(int, min_version.split(".")[:2]))
+
 
 
 def git_credential_fill(gitdir: Optional[str], protocol: str, host: str, username: str) -> Optional[str]:

---
base-commit: 94e36c1a56583d2113cec6eaa99d5a28aab80009
change-id: 20250905-versionparse-2f675a50c2fb

Best regards,

Signature · 1 line
Jonas Rebmann <[email protected]>
#1 lore raw
Quoted 9 lines · Jonas Rebmann

In snapshot builds of git, git-version yields a nonstandard version format like 2.51.0.178.g2462961280. packaging.version.parse() errors out on this with an InvalidVersion exception.

Since we only need to compare major and minor version, and packaging.version is intended for a different version scheme, resort to comparing the two numbers manually.

[...]

Applied, thanks!

[1/1] Don't parse nonstandard git-version suffix

      commit: 5618363ab0142358a7a6a45e381fb6b7c10fe9b5

Best regards,

Signature · 1 line
Konstantin Ryabitsev <[email protected]>