|
|
@ -16,10 +16,15 @@ use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Composer\Downloader\ChangeReportInterface;
|
|
|
|
use Composer\Downloader\ChangeReportInterface;
|
|
|
|
|
|
|
|
use Composer\Downloader\DvcsDownloaderInterface;
|
|
|
|
|
|
|
|
use Composer\Downloader\VcsCapableDownloaderInterface;
|
|
|
|
|
|
|
|
use Composer\Package\Dumper\ArrayDumper;
|
|
|
|
|
|
|
|
use Composer\Package\Version\VersionGuesser;
|
|
|
|
|
|
|
|
use Composer\Package\Version\VersionParser;
|
|
|
|
use Composer\Plugin\CommandEvent;
|
|
|
|
use Composer\Plugin\CommandEvent;
|
|
|
|
use Composer\Plugin\PluginEvents;
|
|
|
|
use Composer\Plugin\PluginEvents;
|
|
|
|
use Composer\Script\ScriptEvents;
|
|
|
|
use Composer\Script\ScriptEvents;
|
|
|
|
use Composer\Downloader\DvcsDownloaderInterface;
|
|
|
|
use Composer\Util\ProcessExecutor;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @author Tiago Ribeiro <tiago.ribeiro@seegno.com>
|
|
|
|
* @author Tiago Ribeiro <tiago.ribeiro@seegno.com>
|
|
|
@ -27,6 +32,11 @@ use Composer\Downloader\DvcsDownloaderInterface;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class StatusCommand extends BaseCommand
|
|
|
|
class StatusCommand extends BaseCommand
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const EXIT_CODE_ERRORS = 1;
|
|
|
|
|
|
|
|
const EXIT_CODE_UNPUSHED_CHANGES = 2;
|
|
|
|
|
|
|
|
const EXIT_CODE_VERSION_CHANGES = 4;
|
|
|
|
|
|
|
|
|
|
|
|
protected function configure()
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
$this
|
|
|
@ -63,6 +73,11 @@ EOT
|
|
|
|
$errors = array();
|
|
|
|
$errors = array();
|
|
|
|
$io = $this->getIO();
|
|
|
|
$io = $this->getIO();
|
|
|
|
$unpushedChanges = array();
|
|
|
|
$unpushedChanges = array();
|
|
|
|
|
|
|
|
$vcsVersionChanges = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$parser = new VersionParser;
|
|
|
|
|
|
|
|
$guesser = new VersionGuesser($composer->getConfig(), new ProcessExecutor($io), $parser);
|
|
|
|
|
|
|
|
$dumper = new ArrayDumper;
|
|
|
|
|
|
|
|
|
|
|
|
// list packages
|
|
|
|
// list packages
|
|
|
|
foreach ($installedRepo->getCanonicalPackages() as $package) {
|
|
|
|
foreach ($installedRepo->getCanonicalPackages() as $package) {
|
|
|
@ -78,31 +93,64 @@ EOT
|
|
|
|
if ($changes = $downloader->getLocalChanges($package, $targetDir, true)) {
|
|
|
|
if ($changes = $downloader->getLocalChanges($package, $targetDir, true)) {
|
|
|
|
$errors[$targetDir] = $changes;
|
|
|
|
$errors[$targetDir] = $changes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($downloader instanceof VcsCapableDownloaderInterface) {
|
|
|
|
|
|
|
|
if ($currentRef = $downloader->getVcsReference($package, $targetDir)) {
|
|
|
|
|
|
|
|
switch ($package->getInstallationSource()) {
|
|
|
|
|
|
|
|
case 'source':
|
|
|
|
|
|
|
|
$previousRef = $package->getSourceReference();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'dist':
|
|
|
|
|
|
|
|
$previousRef = $package->getDistReference();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
$previousRef = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($downloader instanceof DvcsDownloaderInterface) {
|
|
|
|
$currentVersion = $guesser->guessVersion($dumper->dump($package), $targetDir);
|
|
|
|
if ($unpushed = $downloader->getUnpushedChanges($package, $targetDir)) {
|
|
|
|
|
|
|
|
$unpushedChanges[$targetDir] = $unpushed;
|
|
|
|
if ($previousRef && $currentVersion['commit'] !== $previousRef) {
|
|
|
|
|
|
|
|
$vcsVersionChanges[$targetDir] = array(
|
|
|
|
|
|
|
|
'previous' => array(
|
|
|
|
|
|
|
|
'version' => $package->getVersion(),
|
|
|
|
|
|
|
|
'ref' => $previousRef
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
'current' => array(
|
|
|
|
|
|
|
|
'version' => $currentVersion['version'],
|
|
|
|
|
|
|
|
'ref' => $currentVersion['commit'],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($downloader instanceof DvcsDownloaderInterface) {
|
|
|
|
|
|
|
|
if ($unpushed = $downloader->getUnpushedChanges($package, $targetDir)) {
|
|
|
|
|
|
|
|
$unpushedChanges[$targetDir] = $unpushed;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// output errors/warnings
|
|
|
|
// output errors/warnings
|
|
|
|
if (!$errors && !$unpushedChanges) {
|
|
|
|
if (!$errors && !$unpushedChanges && !$vcsVersionChanges) {
|
|
|
|
$io->writeError('<info>No local changes</info>');
|
|
|
|
$io->writeError('<info>No local changes</info>');
|
|
|
|
} elseif ($errors) {
|
|
|
|
return 0;
|
|
|
|
$io->writeError('<error>You have changes in the following dependencies:</error>');
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($errors as $path => $changes) {
|
|
|
|
if ($errors) {
|
|
|
|
if ($input->getOption('verbose')) {
|
|
|
|
$io->writeError('<error>You have changes in the following dependencies:</error>');
|
|
|
|
$indentedChanges = implode("\n", array_map(function ($line) {
|
|
|
|
|
|
|
|
return ' ' . ltrim($line);
|
|
|
|
foreach ($errors as $path => $changes) {
|
|
|
|
}, explode("\n", $changes)));
|
|
|
|
if ($input->getOption('verbose')) {
|
|
|
|
$io->write('<info>'.$path.'</info>:');
|
|
|
|
$indentedChanges = implode("\n", array_map(function ($line) {
|
|
|
|
$io->write($indentedChanges);
|
|
|
|
return ' ' . ltrim($line);
|
|
|
|
} else {
|
|
|
|
}, explode("\n", $changes)));
|
|
|
|
$io->write($path);
|
|
|
|
$io->write('<info>'.$path.'</info>:');
|
|
|
|
|
|
|
|
$io->write($indentedChanges);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$io->write($path);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -122,13 +170,34 @@ EOT
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (($errors || $unpushedChanges) && !$input->getOption('verbose')) {
|
|
|
|
if ($vcsVersionChanges) {
|
|
|
|
|
|
|
|
$io->writeError('<warning>You have version variations in the following dependencies:</warning>');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($vcsVersionChanges as $path => $changes) {
|
|
|
|
|
|
|
|
if ($input->getOption('verbose')) {
|
|
|
|
|
|
|
|
$currentVersion = $changes['current']['version'];
|
|
|
|
|
|
|
|
$previousVersion = $changes['previous']['version'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($io->isVeryVerbose()) {
|
|
|
|
|
|
|
|
$currentVersion .= sprintf(' (%s)', $changes['current']['ref']);
|
|
|
|
|
|
|
|
$previousVersion .= sprintf(' (%s)', $changes['previous']['ref']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$io->write('<info>'.$path.'</info>:');
|
|
|
|
|
|
|
|
$io->write(sprintf(' From <comment>%s</comment> to <comment>%s</comment>', $previousVersion, $currentVersion));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$io->write($path);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (($errors || $unpushedChanges || $vcsVersionChanges) && !$input->getOption('verbose')) {
|
|
|
|
$io->writeError('Use --verbose (-v) to see a list of files');
|
|
|
|
$io->writeError('Use --verbose (-v) to see a list of files');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Dispatch post-status-command
|
|
|
|
// Dispatch post-status-command
|
|
|
|
$composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_STATUS_CMD, true);
|
|
|
|
$composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_STATUS_CMD, true);
|
|
|
|
|
|
|
|
|
|
|
|
return ($errors ? 1 : 0) + ($unpushedChanges ? 2 : 0);
|
|
|
|
return ($errors ? self::EXIT_CODE_ERRORS : 0) + ($unpushedChanges ? self::EXIT_CODE_UNPUSHED_CHANGES : 0) + ($vcsVersionChanges ? self::EXIT_CODE_VERSION_CHANGES : 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|