Fix git version parsing issue

This commit is contained in:
Stéphane Bidoul 2023-09-17 20:02:47 +02:00
parent 0827d76bd2
commit 3b4738cf9a
3 changed files with 17 additions and 1 deletions

1
news/12280.bugfix.rst Normal file
View File

@ -0,0 +1 @@
Fix crash when the git version number contains something else than digits and dots.

View File

@ -101,7 +101,7 @@ class Git(VersionControl):
if not match:
logger.warning("Can't parse git version: %s", version)
return ()
return tuple(int(c) for c in match.groups())
return (int(match.group(1)), int(match.group(2)))
@classmethod
def get_current_branch(cls, location: str) -> Optional[str]:

View File

@ -598,6 +598,21 @@ def test_get_git_version() -> None:
assert git_version >= (1, 0, 0)
@pytest.mark.parametrize(
("version", "expected"),
[
("git version 2.17", (2, 17)),
("git version 2.18.1", (2, 18)),
("git version 2.35.GIT", (2, 35)), # gh:12280
("oh my git version 2.37.GIT", ()), # invalid version
("git version 2.GIT", ()), # invalid version
],
)
def test_get_git_version_parser(version: str, expected: Tuple[int, int]) -> None:
with mock.patch("pip._internal.vcs.git.Git.run_command", return_value=version):
assert Git().get_git_version() == expected
@pytest.mark.parametrize(
"use_interactive,is_atty,expected",
[