From 81043c5691352d3a0eb291982be3d864f089bd5a Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 22 Jun 2022 13:03:36 +0200 Subject: [PATCH] Add git version to diagnose command, and warn if <2.24, closes #10832 --- src/Composer/Command/DiagnoseCommand.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Composer/Command/DiagnoseCommand.php b/src/Composer/Command/DiagnoseCommand.php index ce5488291..97ecf1c6b 100644 --- a/src/Composer/Command/DiagnoseCommand.php +++ b/src/Composer/Command/DiagnoseCommand.php @@ -21,6 +21,7 @@ use Composer\Repository\PlatformRepository; use Composer\Plugin\CommandEvent; use Composer\Plugin\PluginEvents; use Composer\Util\ConfigValidator; +use Composer\Util\Git; use Composer\Util\IniHelper; use Composer\Util\ProcessExecutor; use Composer\Util\HttpDownloader; @@ -225,10 +226,7 @@ EOT return true; } - /** - * @return string|true - */ - private function checkGit() + private function checkGit(): string { if (!function_exists('proc_open')) { return 'proc_open is not available, git cannot be used'; @@ -239,7 +237,16 @@ EOT return 'Your git color.ui setting is set to always, this is known to create issues. Use "git config --global color.ui true" to set it correctly.'; } - return true; + $gitVersion = Git::getVersion($this->process); + if (version_compare('2.24.0', $gitVersion, '>')) { + return 'Your git version ('.$gitVersion.') is too old and possibly will cause issues. Please upgrade to git 2.24 or above'; + } + + if (null === $gitVersion) { + return 'No git process found'; + } + + return 'OK git version '.$gitVersion.''; } /**