From 6f8031ac9025d7aeb38bd097bf25a60384e5c703 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 6 Apr 2012 13:21:04 +0200 Subject: [PATCH] Fix error reporting for missing git process --- src/Composer/Downloader/GitDownloader.php | 20 +++++++++++-------- src/Composer/Repository/Vcs/GitDriver.php | 10 +++++----- .../Test/Downloader/GitDownloaderTest.php | 2 +- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index ec63cefda..6f2434a27 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -93,19 +93,14 @@ class GitDownloader extends VcsDownloader $this->filesystem->removeDirectory($path); } } - - // failed to checkout, first check git accessibility - $output = $this->process->getErrorOutput(); - if (127 === $this->process->execute('git --version', $handler)) { - throw new \RuntimeException('Failed to checkout ' . $url . ' via git, it isn\'t accessible through the console, please check your installation and your PATH env.' . "\n\n" . $this->process->getErrorOutput()); - } - throw new \RuntimeException('Failed to checkout ' . $url .' via git, https and http protocols, aborting.' . "\n\n" . $output); + // failed to checkout, first check git accessibility + $this->throwException('Failed to clone ' . $url .' via git, https and http protocols, aborting.' . "\n\n" . $this->process->getErrorOutput(), $url); } $command = call_user_func($commandCallable, $url); if (0 !== $this->process->execute($command, $handler)) { - throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); + $this->throwException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput(), $url); } } @@ -119,6 +114,15 @@ class GitDownloader extends VcsDownloader } } + protected function throwException($message, $url) + { + if (0 !== $this->process->execute('git --version', $ignoredOutput)) { + throw new \RuntimeException('Failed to clone '.$url.', git was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput()); + } + + throw new \RuntimeException($message); + } + protected function setPushUrl(PackageInterface $package, $path) { // set push url for github projects diff --git a/src/Composer/Repository/Vcs/GitDriver.php b/src/Composer/Repository/Vcs/GitDriver.php index 645feea4e..956785716 100644 --- a/src/Composer/Repository/Vcs/GitDriver.php +++ b/src/Composer/Repository/Vcs/GitDriver.php @@ -54,12 +54,12 @@ class GitDriver extends VcsDriver $command = sprintf('git clone --mirror %s %s', escapeshellarg($this->url), escapeshellarg($this->repoDir)); if (0 !== $this->process->execute($command, $output)) { $output = $this->process->getErrorOutput(); - - if (127 === $this->process->execute('git --version', $handler)) { - throw new \RuntimeException('Failed to clone '.$this->url.', git isn\'t accessible through the console, please check your installation and your PATH env.' . "\n\n" . $this->process->getErrorOutput()); + + if (0 !== $this->process->execute('git --version', $ignoredOutput)) { + throw new \RuntimeException('Failed to clone '.$this->url.', git was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput()); } - - throw new \RuntimeException('Failed to clone '.$this->url.', could not read packages from it ('.$output.')'); + + throw new \RuntimeException('Failed to clone '.$this->url.', could not read packages from it' . "\n\n" .$output); } } } diff --git a/tests/Composer/Test/Downloader/GitDownloaderTest.php b/tests/Composer/Test/Downloader/GitDownloaderTest.php index c7fb4d659..8efb1e027 100644 --- a/tests/Composer/Test/Downloader/GitDownloaderTest.php +++ b/tests/Composer/Test/Downloader/GitDownloaderTest.php @@ -113,7 +113,7 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase ->method('getSourceUrl') ->will($this->returnValue('https://example.com/composer/composer')); $processExecutor = $this->getMock('Composer\Util\ProcessExecutor'); - $processExecutor->expects($this->once()) + $processExecutor->expects($this->at(0)) ->method('execute') ->with($this->equalTo($expectedGitCommand)) ->will($this->returnValue(1));