Skip to content

Commit

Permalink
Fix git version parsing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Sep 17, 2023
1 parent 0827d76 commit 3b4738c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/12280.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix crash when the git version number contains something else than digits and dots.
2 changes: 1 addition & 1 deletion src/pip/_internal/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def get_git_version(self) -> Tuple[int, ...]:
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]:
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down

0 comments on commit 3b4738c

Please sign in to comment.