Skip to content

Commit 3b4738c

Browse files
committed
Fix git version parsing issue
1 parent 0827d76 commit 3b4738c

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

news/12280.bugfix.rst

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

src/pip/_internal/vcs/git.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def get_git_version(self) -> Tuple[int, ...]:
101101
if not match:
102102
logger.warning("Can't parse git version: %s", version)
103103
return ()
104-
return tuple(int(c) for c in match.groups())
104+
return (int(match.group(1)), int(match.group(2)))
105105

106106
@classmethod
107107
def get_current_branch(cls, location: str) -> Optional[str]:

tests/unit/test_vcs.py

+15
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,21 @@ def test_get_git_version() -> None:
598598
assert git_version >= (1, 0, 0)
599599

600600

601+
@pytest.mark.parametrize(
602+
("version", "expected"),
603+
[
604+
("git version 2.17", (2, 17)),
605+
("git version 2.18.1", (2, 18)),
606+
("git version 2.35.GIT", (2, 35)), # gh:12280
607+
("oh my git version 2.37.GIT", ()), # invalid version
608+
("git version 2.GIT", ()), # invalid version
609+
],
610+
)
611+
def test_get_git_version_parser(version: str, expected: Tuple[int, int]) -> None:
612+
with mock.patch("pip._internal.vcs.git.Git.run_command", return_value=version):
613+
assert Git().get_git_version() == expected
614+
615+
601616
@pytest.mark.parametrize(
602617
"use_interactive,is_atty,expected",
603618
[

0 commit comments

Comments
 (0)