diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php
index 7a5864ca7..5aab270ce 100644
--- a/src/Composer/Command/CreateProjectCommand.php
+++ b/src/Composer/Command/CreateProjectCommand.php
@@ -173,8 +173,9 @@ EOT
$installer->disablePlugins();
}
- if (!$installer->run()) {
- return 1;
+ $status = $installer->run();
+ if (0 !== $status) {
+ return $status;
}
}
diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php
index 6138009a3..a163d5ad5 100644
--- a/src/Composer/Command/InstallCommand.php
+++ b/src/Composer/Command/InstallCommand.php
@@ -107,6 +107,6 @@ EOT
$install->disablePlugins();
}
- return $install->run() ? 0 : 1;
+ return $install->run();
}
}
diff --git a/src/Composer/Command/RequireCommand.php b/src/Composer/Command/RequireCommand.php
index 11951dd08..f33c2fd00 100644
--- a/src/Composer/Command/RequireCommand.php
+++ b/src/Composer/Command/RequireCommand.php
@@ -123,14 +123,13 @@ EOT
->setUpdateWhitelist(array_keys($requirements));
;
- if (!$install->run()) {
+ $status = $install->run();
+ if ($status !== 0) {
$output->writeln("\n".'Installation failed, reverting '.$file.' to its original content.');
file_put_contents($json->getPath(), $composerBackup);
-
- return 1;
}
- return 0;
+ return $status;
}
private function updateFileCleanly($json, array $base, array $new, $requireKey)
diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php
index b2f8298e1..7a1471a65 100644
--- a/src/Composer/Command/UpdateCommand.php
+++ b/src/Composer/Command/UpdateCommand.php
@@ -115,6 +115,6 @@ EOT
$install->disablePlugins();
}
- return $install->run() ? 0 : 1;
+ return $install->run();
}
}
diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php
index 30766bb70..0970b75f4 100644
--- a/src/Composer/Installer.php
+++ b/src/Composer/Installer.php
@@ -146,6 +146,8 @@ class Installer
/**
* Run installation (or update)
+ *
+ * @return int 0 on success or a positive error code on failure
*/
public function run()
{
@@ -205,8 +207,9 @@ class Installer
try {
$this->suggestedPackages = array();
- if (!$this->doInstall($localRepo, $installedRepo, $platformRepo, $aliases, $this->devMode)) {
- return false;
+ $res = $this->doInstall($localRepo, $installedRepo, $platformRepo, $aliases, $this->devMode);
+ if ($res !== 0) {
+ return $res;
}
} catch (\Exception $e) {
$this->installationManager->notifyInstalls();
@@ -286,7 +289,7 @@ class Installer
}
}
- return true;
+ return 0;
}
protected function doInstall($localRepo, $installedRepo, $platformRepo, $aliases, $withDevReqs)
@@ -448,7 +451,7 @@ class Installer
$this->io->write('Your requirements could not be resolved to an installable set of packages.');
$this->io->write($e->getMessage());
- return false;
+ return max(1, $e->getCode());
}
// force dev packages to be updated if we update or install from a (potentially new) lock
@@ -533,7 +536,7 @@ class Installer
}
}
- return true;
+ return 0;
}
/**
diff --git a/tests/Composer/Test/InstallerTest.php b/tests/Composer/Test/InstallerTest.php
index 29c153e88..0cc17cfb0 100644
--- a/tests/Composer/Test/InstallerTest.php
+++ b/tests/Composer/Test/InstallerTest.php
@@ -72,7 +72,7 @@ class InstallerTest extends TestCase
$installer = new Installer($io, $config, clone $rootPackage, $downloadManager, $repositoryManager, $locker, $installationManager, $eventDispatcher, $autoloadGenerator);
$result = $installer->run();
- $this->assertTrue($result);
+ $this->assertSame(0, $result);
$expectedInstalled = isset($options['install']) ? $options['install'] : array();
$expectedUpdated = isset($options['update']) ? $options['update'] : array();
@@ -206,7 +206,7 @@ class InstallerTest extends TestCase
->setDevMode($input->getOption('dev'))
->setDryRun($input->getOption('dry-run'));
- return $installer->run() ? 0 : 1;
+ return $installer->run();
});
$application->get('update')->setCode(function ($input, $output) use ($installer) {
@@ -217,7 +217,7 @@ class InstallerTest extends TestCase
->setUpdateWhitelist($input->getArgument('packages'))
->setWhitelistDependencies($input->getOption('with-dependencies'));
- return $installer->run() ? 0 : 1;
+ return $installer->run();
});
if (!preg_match('{^(install|update)\b}', $run)) {