From 5bb0433a51b160c06aef212e8d18cb19a2b62087 Mon Sep 17 00:00:00 2001 From: Marco Villegas Date: Sun, 29 May 2016 12:22:55 -0500 Subject: [PATCH] Provide a way to retirve git version from the related util class. --- src/Composer/Util/Git.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Composer/Util/Git.php b/src/Composer/Util/Git.php index 8d0c423bd..19e0a8e46 100644 --- a/src/Composer/Util/Git.php +++ b/src/Composer/Util/Git.php @@ -271,4 +271,20 @@ class Git throw new \RuntimeException(self::sanitizeUrl($message)); } + + /** + * Retrieves the current git version. + * + * @return string + * The git version number. + */ + public function getVersion() { + if (0 !== $this->process->execute('git --version', $output)) { + throw new \RuntimeException(self::sanitizeUrl('Failed retrieve git version, git was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput())); + } + if (strpos($output, 'git version ') === FALSE) { + throw new \RuntimeException('git --version output seems to have changed, expected "git version x.y.z".'); + } + return substr($output, 12); + } }