StatusCommand.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Command;
  12. use Symfony\Component\Console\Input\InputInterface;
  13. use Symfony\Component\Console\Input\InputArgument;
  14. use Symfony\Component\Console\Input\InputOption;
  15. use Symfony\Component\Console\Output\OutputInterface;
  16. use Composer\Downloader\VcsDownloader;
  17. /**
  18. * @author Tiago Ribeiro <tiago.ribeiro@seegno.com>
  19. * @author Rui Marinho <rui.marinho@seegno.com>
  20. */
  21. class StatusCommand extends Command
  22. {
  23. protected function configure()
  24. {
  25. $this
  26. ->setName('status')
  27. ->setDescription('Show a list of locally modified packages')
  28. ->setHelp(<<<EOT
  29. The status command displays a list of packages that have
  30. been modified locally.
  31. EOT
  32. )
  33. ;
  34. }
  35. protected function execute(InputInterface $input, OutputInterface $output)
  36. {
  37. // init repos
  38. $composer = $this->getComposer();
  39. $installedRepo = $composer->getRepositoryManager()->getLocalRepository();
  40. $dm = $composer->getDownloadManager();
  41. $im = $composer->getInstallationManager();
  42. $errors = array();
  43. // list packages
  44. foreach ($installedRepo->getPackages() as $package) {
  45. $downloader = $dm->getDownloaderForInstalledPackage($package);
  46. if ($downloader instanceof VcsDownloader) {
  47. $targetDir = $im->getInstallPath($package);
  48. if ($downloader->hasLocalChanges($targetDir)) {
  49. $errors[] = $targetDir;
  50. }
  51. }
  52. }
  53. // output errors/warnings
  54. if (!$errors) {
  55. $output->writeln('<info>No local changes</info>');
  56. } else {
  57. $output->writeln('<error>You have changes in the following packages:</error>');
  58. }
  59. foreach ($errors as $error) {
  60. $output->writeln($error);
  61. }
  62. return $errors ? 1 : 0;
  63. }
  64. }