From c2421db7d9311e74e71990e43b62e37781ea9f5e Mon Sep 17 00:00:00 2001 From: Dave Marshall Date: Wed, 29 Feb 2012 11:05:25 +0000 Subject: [PATCH] Add stderr to exceptions for GitDownloader --- src/Composer/Downloader/GitDownloader.php | 6 +++--- src/Composer/Util/ProcessExecutor.php | 14 ++++++++++++++ tests/Composer/Test/Util/ProcessExecutorTest.php | 7 +++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index d5c413dd3..4e0ea0c29 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -31,7 +31,7 @@ class GitDownloader extends VcsDownloader $this->io->write(" Cloning ".$package->getSourceReference()); $command = sprintf('git clone %s %s && cd %2$s && git checkout %3$s && git reset --hard %3$s', $url, $path, $ref); if (0 !== $this->process->execute($command, $ignoredOutput)) { - throw new \RuntimeException('Failed to execute ' . $command); + throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); } } @@ -45,7 +45,7 @@ class GitDownloader extends VcsDownloader $this->io->write(" Checking out ".$target->getSourceReference()); $command = sprintf('cd %s && git fetch && git checkout %2$s && git reset --hard %2$s', $path, $ref); if (0 !== $this->process->execute($command, $ignoredOutput)) { - throw new \RuntimeException('Failed to execute ' . $command); + throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); } } @@ -56,7 +56,7 @@ class GitDownloader extends VcsDownloader { $command = sprintf('cd %s && git status --porcelain', escapeshellarg($path)); if (0 !== $this->process->execute($command, $output)) { - throw new \RuntimeException('Failed to execute ' . $command); + throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); } if (trim($output)) { diff --git a/src/Composer/Util/ProcessExecutor.php b/src/Composer/Util/ProcessExecutor.php index 5bce6c73c..3cc51d7ba 100644 --- a/src/Composer/Util/ProcessExecutor.php +++ b/src/Composer/Util/ProcessExecutor.php @@ -21,6 +21,8 @@ class ProcessExecutor { static protected $timeout = 300; + protected $errorOutput; + /** * runs a process on the commandline * @@ -44,6 +46,8 @@ class ProcessExecutor $output = $process->getOutput(); } + $this->errorOutput = $process->getErrorOutput(); + return $process->getExitCode(); } @@ -52,6 +56,16 @@ class ProcessExecutor return ((string) $output === '') ? array() : preg_split('{\r?\n}', $output); } + /** + * Get any error output from the last command + * + * @return string + */ + public function getErrorOutput() + { + return $this->errorOutput; + } + static public function getTimeout() { return static::$timeout; diff --git a/tests/Composer/Test/Util/ProcessExecutorTest.php b/tests/Composer/Test/Util/ProcessExecutorTest.php index 0ec924bb4..f2b394d9f 100644 --- a/tests/Composer/Test/Util/ProcessExecutorTest.php +++ b/tests/Composer/Test/Util/ProcessExecutorTest.php @@ -33,6 +33,13 @@ class ProcessExecutorTest extends TestCase $this->assertEquals("foo".PHP_EOL, $output); } + public function testExecuteCapturesStderr() + { + $process = new ProcessExecutor; + $process->execute('cat foo', $output); + $this->assertNotNull($process->getErrorOutput()); + } + public function testTimeout() { ProcessExecutor::setTimeout(1);