Permalink
Browse files

Merge remote-tracking branch 'fixe/status-command'

Conflicts:
	src/Composer/Console/Application.php
  • Loading branch information...
2 parents 7b3ce47 + aba2ab2 commit 5b4c6f6296fbad824721107da4592e417be85c05 @Seldaek Seldaek committed Aug 18, 2012
@@ -0,0 +1,78 @@
+<?php
+
+/*
+ * This file is part of Composer.
+ *
+ * (c) Nils Adermann <naderman@naderman.de>
+ * Jordi Boggiano <j.boggiano@seld.be>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Command;
+
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+use Composer\Downloader\VcsDownloader;
+
+/**
+ * @author Tiago Ribeiro <tiago.ribeiro@seegno.com>
+ * @author Rui Marinho <rui.marinho@seegno.com>
+ */
+class StatusCommand extends Command
+{
+ protected function configure()
+ {
+ $this
+ ->setName('status')
+ ->setDescription('Show a list of locally modified packages')
+ ->setHelp(<<<EOT
+The status command displays a list of packages that have
+been modified locally.
+
+EOT
+ )
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ // init repos
+ $composer = $this->getComposer();
+ $installedRepo = $composer->getRepositoryManager()->getLocalRepository();
+
+ $dm = $composer->getDownloadManager();
+ $im = $composer->getInstallationManager();
+
+ $errors = array();
+
+ // list packages
+ foreach ($installedRepo->getPackages() as $package) {
+ $downloader = $dm->getDownloaderForInstalledPackage($package);
+
+ if ($downloader instanceof VcsDownloader) {
+ $targetDir = $im->getInstallPath($package);
+
+ if ($downloader->hasLocalChanges($targetDir)) {
+ $errors[] = $targetDir;
+ }
+ }
+ }
+
+ // output errors/warnings
+ if (!$errors) {
+ $output->writeln('<info>No local changes</info>');
+ } else {
+ $output->writeln('<error>You have changes in the following packages:</error>');
+ }
+
+ foreach ($errors as $error) {
+ $output->writeln($error);
+ }
+
+ return $errors ? 1 : 0;
+ }
+}
@@ -131,6 +131,7 @@ protected function getDefaultCommands()
$commands[] = new Command\ShowCommand();
$commands[] = new Command\RequireCommand();
$commands[] = new Command\DumpAutoloadCommand();
+ $commands[] = new Command\StatusCommand();
if ('phar:' === substr(__FILE__, 0, 5)) {
$commands[] = new Command\SelfUpdateCommand();
@@ -63,6 +63,19 @@ public function doUpdate(PackageInterface $initial, PackageInterface $target, $p
$this->updateToCommit($path, $ref, $target->getPrettyVersion(), $target->getReleaseDate());
}
+ /**
+ * {@inheritDoc}
+ */
+ public function hasLocalChanges($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);
+ }
+
protected function updateToCommit($path, $reference, $branch, $date)
{
$template = 'git checkout %s && git reset --hard %1$s';
@@ -125,21 +138,6 @@ protected function updateToCommit($path, $reference, $branch, $date)
}
/**
- * {@inheritDoc}
- */
- protected function enforceCleanDirectory($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());
- }
-
- if (trim($output)) {
- throw new \RuntimeException('Source directory ' . $path . ' has uncommitted changes');
- }
- }
-
- /**
* Runs a command doing attempts for each protocol supported by github.
*
* @param callable $commandCallable A callable building the command for the given url
@@ -52,11 +52,10 @@ public function doUpdate(PackageInterface $initial, PackageInterface $target, $p
/**
* {@inheritDoc}
*/
- protected function enforceCleanDirectory($path)
+ public function hasLocalChanges($path)
{
$this->process->execute(sprintf('cd %s && hg st', escapeshellarg($path)), $output);
- if (trim($output)) {
- throw new \RuntimeException('Source directory ' . $path . ' has uncommitted changes');
- }
+
+ return (bool) trim($output);
}
}
@@ -48,12 +48,11 @@ public function doUpdate(PackageInterface $initial, PackageInterface $target, $p
/**
* {@inheritDoc}
*/
- protected function enforceCleanDirectory($path)
+ public function hasLocalChanges($path)
{
$this->process->execute('svn status --ignore-externals', $output, $path);
- if (preg_match('{^ *[^X ] +}m', $output)) {
- throw new \RuntimeException('Source directory ' . $path . ' has uncommitted changes:'."\n\n".rtrim($output));
- }
+
+ return preg_match('{^ *[^X ] +}m', $output);
}
/**
@@ -84,6 +84,18 @@ public function remove(PackageInterface $package, $path)
}
/**
+ * Guarantee that no changes have been made to the local copy
+ *
+ * @throws \RuntimeException if the directory is not clean
+ */
+ protected function enforceCleanDirectory($path)
+ {
+ if ($this->hasLocalChanges($path)) {
+ throw new \RuntimeException('Source directory ' . $path . ' has uncommitted changes.');
+ }
+ }
+
+ /**
* Downloads specific package into specific folder.
*
* @param PackageInterface $package package instance
@@ -101,9 +113,10 @@ public function remove(PackageInterface $package, $path)
abstract protected function doUpdate(PackageInterface $initial, PackageInterface $target, $path);
/**
- * Checks that no changes have been made to the local copy
+ * Checks for changes to the local copy
*
- * @throws \RuntimeException if the directory is not clean
+ * @param string $path package directory
+ * @return boolean whether package has local changes
*/
- abstract protected function enforceCleanDirectory($path);
+ abstract public function hasLocalChanges($path);
}

0 comments on commit 5b4c6f6

Please sign in to comment.