mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Fix git version parsing issue
This commit is contained in:
parent
0827d76bd2
commit
3b4738cf9a
3 changed files with 17 additions and 1 deletions
1
news/12280.bugfix.rst
Normal file
1
news/12280.bugfix.rst
Normal file
|
@ -0,0 +1 @@
|
|||
Fix crash when the git version number contains something else than digits and dots.
|
|
@ -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]:
|
||||
|
|
|
@ -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",
|
||||
[
|
||||
|
|
Loading…
Reference in a new issue