Navigation Menu

Skip to content

Commit

Permalink
Add stderr to exceptions for GitDownloader
Browse files Browse the repository at this point in the history
  • Loading branch information
davedevelopment committed Feb 29, 2012
1 parent 0e6cf61 commit c2421db
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Composer/Downloader/GitDownloader.php
Expand Up @@ -31,7 +31,7 @@ public function doDownload(PackageInterface $package, $path)
$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());
}
}

Expand All @@ -45,7 +45,7 @@ public function doUpdate(PackageInterface $initial, PackageInterface $target, $p
$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());
}
}

Expand All @@ -56,7 +56,7 @@ protected function enforceCleanDirectory($path)
{
$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)) {
Expand Down
14 changes: 14 additions & 0 deletions src/Composer/Util/ProcessExecutor.php
Expand Up @@ -21,6 +21,8 @@ class ProcessExecutor
{
static protected $timeout = 300;

protected $errorOutput;

/**
* runs a process on the commandline
*
Expand All @@ -44,6 +46,8 @@ public function execute($command, &$output = null)
$output = $process->getOutput();
}

$this->errorOutput = $process->getErrorOutput();

return $process->getExitCode();
}

Expand All @@ -52,6 +56,16 @@ public function splitLines($output)
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;
Expand Down
7 changes: 7 additions & 0 deletions tests/Composer/Test/Util/ProcessExecutorTest.php
Expand Up @@ -33,6 +33,13 @@ public function testExecuteOutputsIfNotCaptured()
$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);
Expand Down

0 comments on commit c2421db

Please sign in to comment.