From 4d84f62cd988eb6612872a37db13c437cf704702 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 18 Aug 2012 16:01:44 +0200 Subject: [PATCH] Improve consistency and formatting of verbose output for update/install --- src/Composer/Command/InstallCommand.php | 1 + src/Composer/Command/UpdateCommand.php | 1 + src/Composer/Downloader/FileDownloader.php | 5 +-- src/Composer/Downloader/GitDownloader.php | 7 +++-- src/Composer/Downloader/HgDownloader.php | 7 +++-- src/Composer/Downloader/SvnDownloader.php | 7 +++-- src/Composer/Downloader/VcsDownloader.php | 36 +++++++++++++++++----- src/Composer/Installer.php | 5 +-- 8 files changed, 52 insertions(+), 17 deletions(-) diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index be5824a64..7039cfd10 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -35,6 +35,7 @@ class InstallCommand extends Command new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables installation of dev-require packages.'), new InputOption('no-custom-installers', null, InputOption::VALUE_NONE, 'Disables all custom installers.'), new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Skips the execution of all scripts defined in composer.json file.'), + new InputOption('verbose', 'v', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'), )) ->setHelp(<<install command reads the composer.json file from the diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php index 7bede7d25..9a5d4a7aa 100644 --- a/src/Composer/Command/UpdateCommand.php +++ b/src/Composer/Command/UpdateCommand.php @@ -35,6 +35,7 @@ class UpdateCommand extends Command new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables installation of dev-require packages.'), new InputOption('no-custom-installers', null, InputOption::VALUE_NONE, 'Disables all custom installers.'), new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Skips the execution of all scripts defined in composer.json file.'), + new InputOption('verbose', 'v', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'), )) ->setHelp(<<update command reads the composer.json file from the diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index e6b0c1061..8dea3b075 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -14,6 +14,7 @@ namespace Composer\Downloader; use Composer\IO\IOInterface; use Composer\Package\PackageInterface; +use Composer\Package\Version\VersionParser; use Composer\Util\Filesystem; use Composer\Util\RemoteFilesystem; @@ -64,7 +65,7 @@ class FileDownloader implements DownloaderInterface $fileName = $this->getFileName($package, $path); - $this->io->write(" - Installing " . $package->getName() . " (" . $package->getPrettyVersion() . ")"); + $this->io->write(" - Installing " . $package->getName() . " (" . VersionParser::formatVersion($package) . ")"); $processUrl = $this->processUrl($url); @@ -101,7 +102,7 @@ class FileDownloader implements DownloaderInterface */ public function remove(PackageInterface $package, $path) { - $this->io->write(" - Removing " . $package->getName() . " (" . $package->getPrettyVersion() . ")"); + $this->io->write(" - Removing " . $package->getName() . " (" . VersionParser::formatVersion($package) . ")"); if (!$this->filesystem->removeDirectory($path)) { throw new \RuntimeException('Could not completely delete '.$path.', aborting.'); } diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index a32a87960..d765f2e9f 100755 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -234,9 +234,12 @@ class GitDownloader extends VcsDownloader } } - protected function getCommitLogs($sourceReference, $targetReference, $path) + /** + * {@inheritDoc} + */ + protected function getCommitLogs($fromReference, $toReference, $path) { - $command = sprintf('cd %s && git log %s..%s --pretty=format:"%%h - %%an: %%s"', escapeshellarg($path), $sourceReference, $targetReference); + $command = sprintf('cd %s && git log %s..%s --pretty=format:"%%h - %%an: %%s"', escapeshellarg($path), $fromReference, $toReference); if (0 !== $this->process->execute($command, $output)) { throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); diff --git a/src/Composer/Downloader/HgDownloader.php b/src/Composer/Downloader/HgDownloader.php index d414916fd..fc66e40eb 100755 --- a/src/Composer/Downloader/HgDownloader.php +++ b/src/Composer/Downloader/HgDownloader.php @@ -59,9 +59,12 @@ class HgDownloader extends VcsDownloader return trim($output) ?: null; } - protected function getCommitLogs($sourceReference, $targetReference, $path) + /** + * {@inheritDoc} + */ + protected function getCommitLogs($fromReference, $toReference, $path) { - $command = sprintf('cd %s && hg log -r %s:%s --style compact', escapeshellarg($path), $sourceReference, $targetReference); + $command = sprintf('cd %s && hg log -r %s:%s --style compact', escapeshellarg($path), $fromReference, $toReference); if (0 !== $this->process->execute($command, $output)) { throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); diff --git a/src/Composer/Downloader/SvnDownloader.php b/src/Composer/Downloader/SvnDownloader.php index 81e655fce..47322d9f5 100755 --- a/src/Composer/Downloader/SvnDownloader.php +++ b/src/Composer/Downloader/SvnDownloader.php @@ -79,9 +79,12 @@ class SvnDownloader extends VcsDownloader } } - protected function getCommitLogs($sourceReference, $targetReference, $path) + /** + * {@inheritDoc} + */ + protected function getCommitLogs($fromReference, $toReference, $path) { - $command = sprintf('cd %s && svn log -r%s:%s --incremental', escapeshellarg($path), $sourceReference, $targetReference); + $command = sprintf('cd %s && svn log -r%s:%s --incremental', escapeshellarg($path), $fromReference, $toReference); if (0 !== $this->process->execute($command, $output)) { throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); diff --git a/src/Composer/Downloader/VcsDownloader.php b/src/Composer/Downloader/VcsDownloader.php index a9821fdb9..c1cf2050f 100644 --- a/src/Composer/Downloader/VcsDownloader.php +++ b/src/Composer/Downloader/VcsDownloader.php @@ -13,6 +13,7 @@ namespace Composer\Downloader; use Composer\Package\PackageInterface; +use Composer\Package\Version\VersionParser; use Composer\Util\ProcessExecutor; use Composer\IO\IOInterface; use Composer\Util\Filesystem; @@ -50,7 +51,7 @@ abstract class VcsDownloader implements DownloaderInterface throw new \InvalidArgumentException('Package '.$package->getPrettyName().' is missing reference information'); } - $this->io->write(" - Installing " . $package->getName() . " (" . $package->getPrettyVersion() . ")"); + $this->io->write(" - Installing " . $package->getName() . " (" . VersionParser::formatVersion($package) . ")"); $this->filesystem->removeDirectory($path); $this->doDownload($package, $path); $this->io->write(''); @@ -65,23 +66,44 @@ abstract class VcsDownloader implements DownloaderInterface throw new \InvalidArgumentException('Package '.$target->getPrettyName().' is missing reference information'); } + $name = $target->getName(); if ($initial->getPrettyVersion() == $target->getPrettyVersion()) { - $from = $initial->getSourceReference(); - $to = $target->getSourceReference(); + if ($target->getSourceType() === 'svn') { + $from = $initial->getSourceReference(); + $to = $target->getSourceReference(); + } else { + $from = substr($initial->getSourceReference(), 0, 6); + $to = substr($target->getSourceReference(), 0, 6); + } + $name .= ' '.$initial->getPrettyVersion(); } else { - $from = $initial->getPrettyVersion(); - $to = $target->getPrettyVersion(); + $from = VersionParser::formatVersion($initial); + $to = VersionParser::formatVersion($target); } - $this->io->write(" - Updating " . $target->getName() . " from (" . $from . ") to (" . $to . ")"); + $this->io->write(" - Updating " . $name . " (" . $from . " => " . $to . ")"); $this->enforceCleanDirectory($path); $this->doUpdate($initial, $target, $path); //print the commit logs if in verbose mode if ($this->io->isVerbose()) { + $message = 'Pulling in changes:'; $logs = $this->getCommitLogs($initial->getSourceReference(), $target->getSourceReference(), $path); - $this->io->write($logs); + + if (!trim($logs)) { + $message = 'Rolling back changes:'; + $logs = $this->getCommitLogs($target->getSourceReference(), $initial->getSourceReference(), $path); + } + + if (trim($logs)) { + $logs = implode("\n", array_map(function ($line) { + return ' ' . $line; + }, explode("\n", $logs))); + + $this->io->write(' '.$message); + $this->io->write($logs); + } } $this->io->write(''); diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index a52055a67..0fb1a2f1f 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -465,8 +465,9 @@ class Installer } } - if ($this->verbose) { - $this->io->write((string) $operation); + // output alias operations in verbose mode, or all ops in dry run + if ($this->dryRun || ($this->verbose && false !== strpos($operation->getJobType(), 'Alias'))) { + $this->io->write(' - ' . $operation); } $this->installationManager->execute($localRepo, $operation);