Permalink
Browse files

Show detailed changes in verbose mode, refs #842

  • Loading branch information...
1 parent 756c7a0 commit 209d3ebfc44af7429cb1e54080910d8f6bdc893a @Seldaek Seldaek committed Aug 18, 2012
@@ -29,8 +29,11 @@ protected function configure()
$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.'),
@stof

stof Aug 19, 2012

Contributor

no need to add this. The application itself has a verbose option ($ouput->getVerbosity())

@Seldaek

Seldaek Aug 19, 2012

Owner

There is a need: for clarity, to override the docs with details.

+ ))
->setHelp(<<<EOT
-The status command displays a list of packages that have
+The status command displays a list of dependencies that have
been modified locally.
EOT
@@ -56,8 +59,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($downloader instanceof VcsDownloader) {
$targetDir = $im->getInstallPath($package);
- if ($downloader->hasLocalChanges($targetDir)) {
- $errors[] = $targetDir;
+ if ($changes = $downloader->getLocalChanges($targetDir)) {
+ $errors[$targetDir] = $changes;
}
}
}
@@ -66,11 +69,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!$errors) {
$output->writeln('<info>No local changes</info>');
} else {
- $output->writeln('<error>You have changes in the following packages:</error>');
+ $output->writeln('<error>You have changes in the following dependencies:</error>');
}
- 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('<info>'.$path.'</info>:');
+ $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;
@@ -66,14 +66,14 @@ public function doUpdate(PackageInterface $initial, PackageInterface $target, $p
/**
* {@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)
@@ -52,10 +52,10 @@ public function doUpdate(PackageInterface $initial, PackageInterface $target, $p
/**
* {@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;
}
}
@@ -48,11 +48,11 @@ public function doUpdate(PackageInterface $initial, PackageInterface $target, $p
/**
* {@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;
}
/**
@@ -90,7 +90,7 @@ public function remove(PackageInterface $package, $path)
*/
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 @@ protected function enforceCleanDirectory($path)
/**
* 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);
}

0 comments on commit 209d3eb

Please sign in to comment.