From 209d3ebfc44af7429cb1e54080910d8f6bdc893a Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 18 Aug 2012 14:34:24 +0200 Subject: [PATCH] Show detailed changes in verbose mode, refs #842 --- src/Composer/Command/StatusCommand.php | 27 ++++++++++++++++++----- src/Composer/Downloader/GitDownloader.php | 4 ++-- src/Composer/Downloader/HgDownloader.php | 4 ++-- src/Composer/Downloader/SvnDownloader.php | 4 ++-- src/Composer/Downloader/VcsDownloader.php | 8 +++---- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/Composer/Command/StatusCommand.php b/src/Composer/Command/StatusCommand.php index 879ae7578..b0c873189 100644 --- a/src/Composer/Command/StatusCommand.php +++ b/src/Composer/Command/StatusCommand.php @@ -29,8 +29,11 @@ class StatusCommand extends Command $this ->setName('status') ->setDescription('Show a list of locally modified packages') + ->setDefinition(array( + new InputOption('verbose', 'v', InputOption::VALUE_NONE, 'Show modified files for each directory that contains changes.'), + )) ->setHelp(<<getInstallPath($package); - if ($downloader->hasLocalChanges($targetDir)) { - $errors[] = $targetDir; + if ($changes = $downloader->getLocalChanges($targetDir)) { + $errors[$targetDir] = $changes; } } } @@ -66,11 +69,23 @@ EOT if (!$errors) { $output->writeln('No local changes'); } else { - $output->writeln('You have changes in the following packages:'); + $output->writeln('You have changes in the following dependencies:'); } - foreach ($errors as $error) { - $output->writeln($error); + foreach ($errors as $path => $changes) { + if ($input->getOption('verbose')) { + $indentedChanges = implode("\n", array_map(function ($line) { + return ' ' . $line; + }, explode("\n", $changes))); + $output->writeln(''.$path.':'); + $output->writeln($indentedChanges); + } else { + $output->writeln($path); + } + } + + if ($errors && !$input->getOption('verbose')) { + $output->writeln('Use --verbose (-v) to see modified files'); } return $errors ? 1 : 0; diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index a5a101186..86a75eeab 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -66,14 +66,14 @@ class GitDownloader extends VcsDownloader /** * {@inheritDoc} */ - public function hasLocalChanges($path) + public function getLocalChanges($path) { $command = sprintf('cd %s && git status --porcelain --untracked-files=no', escapeshellarg($path)); if (0 !== $this->process->execute($command, $output)) { throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); } - return (bool) trim($output); + return trim($output) ?: null; } protected function updateToCommit($path, $reference, $branch, $date) diff --git a/src/Composer/Downloader/HgDownloader.php b/src/Composer/Downloader/HgDownloader.php index a2b4fe9df..deb748d90 100644 --- a/src/Composer/Downloader/HgDownloader.php +++ b/src/Composer/Downloader/HgDownloader.php @@ -52,10 +52,10 @@ class HgDownloader extends VcsDownloader /** * {@inheritDoc} */ - public function hasLocalChanges($path) + public function getLocalChanges($path) { $this->process->execute(sprintf('cd %s && hg st', escapeshellarg($path)), $output); - return (bool) trim($output); + return trim($output) ?: null; } } diff --git a/src/Composer/Downloader/SvnDownloader.php b/src/Composer/Downloader/SvnDownloader.php index 2b4d77fee..39c4b8e6c 100644 --- a/src/Composer/Downloader/SvnDownloader.php +++ b/src/Composer/Downloader/SvnDownloader.php @@ -48,11 +48,11 @@ class SvnDownloader extends VcsDownloader /** * {@inheritDoc} */ - public function hasLocalChanges($path) + public function getLocalChanges($path) { $this->process->execute('svn status --ignore-externals', $output, $path); - return preg_match('{^ *[^X ] +}m', $output); + return preg_match('{^ *[^X ] +}m', $output) ? $output : null; } /** diff --git a/src/Composer/Downloader/VcsDownloader.php b/src/Composer/Downloader/VcsDownloader.php index 45ee17768..5a9577672 100644 --- a/src/Composer/Downloader/VcsDownloader.php +++ b/src/Composer/Downloader/VcsDownloader.php @@ -90,7 +90,7 @@ abstract class VcsDownloader implements DownloaderInterface */ protected function enforceCleanDirectory($path) { - if ($this->hasLocalChanges($path)) { + if (null !== $this->getLocalChanges($path)) { throw new \RuntimeException('Source directory ' . $path . ' has uncommitted changes.'); } } @@ -115,8 +115,8 @@ abstract class VcsDownloader implements DownloaderInterface /** * Checks for changes to the local copy * - * @param string $path package directory - * @return boolean whether package has local changes + * @param string $path package directory + * @return string|null changes or null */ - abstract public function hasLocalChanges($path); + abstract public function getLocalChanges($path); }