From aba94fe0a1245232fa4a67a0a6ae93c2576871c6 Mon Sep 17 00:00:00 2001 From: HausCloud Date: Tue, 7 Sep 2021 03:01:33 +0000 Subject: [PATCH] Add warning for git version parse failures --- news/10361.enhancement.rst | 1 + src/pip/_internal/vcs/git.py | 1 + tests/unit/test_vcs.py | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 news/10361.enhancement.rst diff --git a/news/10361.enhancement.rst b/news/10361.enhancement.rst new file mode 100644 index 00000000000..4104b072f5f --- /dev/null +++ b/news/10361.enhancement.rst @@ -0,0 +1 @@ +Add a warning upon failing to match (via regex) the current system's git version. \ No newline at end of file diff --git a/src/pip/_internal/vcs/git.py b/src/pip/_internal/vcs/git.py index 3186553e705..2ca4e91f6f5 100644 --- a/src/pip/_internal/vcs/git.py +++ b/src/pip/_internal/vcs/git.py @@ -94,6 +94,7 @@ def get_git_version(self) -> Tuple[int, ...]: version = self.run_command(["version"], show_stdout=False, stdout_only=True) match = GIT_VERSION_REGEX.match(version) if not match: + logger.warning("Unable to parse '%s'.", version) return () return tuple(int(c) for c in match.groups()) diff --git a/tests/unit/test_vcs.py b/tests/unit/test_vcs.py index 0f41ba1d7c1..069ebd89ec6 100644 --- a/tests/unit/test_vcs.py +++ b/tests/unit/test_vcs.py @@ -299,6 +299,25 @@ def test_git_is_commit_id_equal(mock_get_revision, rev_name, result): assert Git.is_commit_id_equal("/path", rev_name) is result +@pytest.mark.parametrize( + "version_out,result", + ( + ("git version -2.25.1", ()), + ("git version 2.a.1", ()), + ("git ver. 2.25.1", ()), + ), +) +@patch("pip._internal.vcs.versioncontrol.VersionControl.run_command") +def test_git_parse_fail_warning(mock_run_command, caplog, version_out, result): + """ + Test Git.get_git_version(). + """ + mock_run_command.return_value = version_out + git_tuple = Git().get_git_version() + assert git_tuple == result + assert caplog.messages == ["Unable to parse '%s'." % version_out] + + # The non-SVN backends all use the same get_netloc_and_auth(), so only test # Git as a representative. @pytest.mark.parametrize(