Show detailed changes in verbose mode, refs #842

main
Jordi Boggiano 12 years ago
parent 756c7a04fd
commit 209d3ebfc4

@ -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(<<<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 @@ EOT
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 @@ EOT
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 @@ 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)

@ -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;
}
}

@ -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;
}
/**

@ -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);
}

Loading…
Cancel
Save