From 667176d1d0a49166eff4bf6505748a48bcd3bbe5 Mon Sep 17 00:00:00 2001 From: Sascha Egerer Date: Wed, 31 Jul 2013 19:17:37 +0200 Subject: [PATCH 1/3] Add ChangeReport Interface Added a ChangeReport Interface to allow also non VCS-Downloaders to check the status of there package --- src/Composer/Command/StatusCommand.php | 5 +-- .../Downloader/ChangeReportInterface.php | 32 +++++++++++++++++++ src/Composer/Downloader/GitDownloader.php | 2 +- src/Composer/Downloader/HgDownloader.php | 2 +- src/Composer/Downloader/SvnDownloader.php | 2 +- src/Composer/Downloader/VcsDownloader.php | 10 +----- 6 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 src/Composer/Downloader/ChangeReportInterface.php diff --git a/src/Composer/Command/StatusCommand.php b/src/Composer/Command/StatusCommand.php index 0458ad658..5a07cee8b 100644 --- a/src/Composer/Command/StatusCommand.php +++ b/src/Composer/Command/StatusCommand.php @@ -15,6 +15,7 @@ namespace Composer\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Composer\Downloader\ChangeReportInterface; use Composer\Downloader\VcsDownloader; /** @@ -55,10 +56,10 @@ EOT foreach ($installedRepo->getPackages() as $package) { $downloader = $dm->getDownloaderForInstalledPackage($package); - if ($downloader instanceof VcsDownloader) { + if ($downloader instanceof ChangeReportInterface) { $targetDir = $im->getInstallPath($package); - if ($changes = $downloader->getLocalChanges($targetDir)) { + if ($changes = $downloader->getLocalChanges($targetDir, $package)) { $errors[$targetDir] = $changes; } } diff --git a/src/Composer/Downloader/ChangeReportInterface.php b/src/Composer/Downloader/ChangeReportInterface.php new file mode 100644 index 000000000..dba90ebbb --- /dev/null +++ b/src/Composer/Downloader/ChangeReportInterface.php @@ -0,0 +1,32 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Downloader; + +use Composer\Package\PackageInterface; + +/** + * ChangeReport interface. + * + * @author Sascha Egerer + */ +interface ChangeReportInterface +{ + /** + * Checks for changes to the local copy + * + * @param string $path package directory + * @param PackageInterface $package package instance + * @return string|null changes or null + */ + public function getLocalChanges($path, PackageInterface $package); +} diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index edc55bc3b..dbed51177 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -78,7 +78,7 @@ class GitDownloader extends VcsDownloader /** * {@inheritDoc} */ - public function getLocalChanges($path) + public function getLocalChanges($path, PackageInterface $package) { $this->cleanEnv(); $path = $this->normalizePath($path); diff --git a/src/Composer/Downloader/HgDownloader.php b/src/Composer/Downloader/HgDownloader.php index a3fc7da76..011b401a7 100644 --- a/src/Composer/Downloader/HgDownloader.php +++ b/src/Composer/Downloader/HgDownloader.php @@ -59,7 +59,7 @@ class HgDownloader extends VcsDownloader /** * {@inheritDoc} */ - public function getLocalChanges($path) + public function getLocalChanges($path, PackageInterface $package) { if (!is_dir($path.'/.hg')) { return; diff --git a/src/Composer/Downloader/SvnDownloader.php b/src/Composer/Downloader/SvnDownloader.php index 2e894908a..c3cc5436e 100644 --- a/src/Composer/Downloader/SvnDownloader.php +++ b/src/Composer/Downloader/SvnDownloader.php @@ -52,7 +52,7 @@ class SvnDownloader extends VcsDownloader /** * {@inheritDoc} */ - public function getLocalChanges($path) + public function getLocalChanges($path, PackageInterface $package) { if (!is_dir($path.'/.svn')) { return; diff --git a/src/Composer/Downloader/VcsDownloader.php b/src/Composer/Downloader/VcsDownloader.php index 081bd2c2b..2b44ba5f0 100644 --- a/src/Composer/Downloader/VcsDownloader.php +++ b/src/Composer/Downloader/VcsDownloader.php @@ -22,7 +22,7 @@ use Composer\Util\Filesystem; /** * @author Jordi Boggiano */ -abstract class VcsDownloader implements DownloaderInterface +abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterface { protected $io; protected $config; @@ -187,14 +187,6 @@ abstract class VcsDownloader implements DownloaderInterface */ abstract protected function doUpdate(PackageInterface $initial, PackageInterface $target, $path); - /** - * Checks for changes to the local copy - * - * @param string $path package directory - * @return string|null changes or null - */ - abstract public function getLocalChanges($path); - /** * Fetches the commit logs between two commits * From 49d89bbbfc88f8e4cad7aea1883d34f8d6fac0c6 Mon Sep 17 00:00:00 2001 From: Sascha Egerer Date: Wed, 31 Jul 2013 19:41:29 +0200 Subject: [PATCH 2/3] CGL fix --- src/Composer/Downloader/ChangeReportInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Downloader/ChangeReportInterface.php b/src/Composer/Downloader/ChangeReportInterface.php index dba90ebbb..1d770ec8e 100644 --- a/src/Composer/Downloader/ChangeReportInterface.php +++ b/src/Composer/Downloader/ChangeReportInterface.php @@ -28,5 +28,5 @@ interface ChangeReportInterface * @param PackageInterface $package package instance * @return string|null changes or null */ - public function getLocalChanges($path, PackageInterface $package); + public function getLocalChanges($path, PackageInterface $package); } From 80cebbd4bed65f5980ff5ac9d937c9c648174347 Mon Sep 17 00:00:00 2001 From: Sascha Egerer Date: Wed, 31 Jul 2013 19:56:49 +0200 Subject: [PATCH 3/3] Fixed getLocalChanges calls in VCS downloaders to match new function interface --- src/Composer/Downloader/GitDownloader.php | 8 ++++---- src/Composer/Downloader/SvnDownloader.php | 6 +++--- src/Composer/Downloader/VcsDownloader.php | 25 ++++++++++++----------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index dbed51177..e25da3ee6 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -97,11 +97,11 @@ class GitDownloader extends VcsDownloader /** * {@inheritDoc} */ - protected function cleanChanges($path, $update) + protected function cleanChanges($path, $update, $package) { $this->cleanEnv(); $path = $this->normalizePath($path); - if (!$changes = $this->getLocalChanges($path)) { + if (!$changes = $this->getLocalChanges($path, $package)) { return; } @@ -112,13 +112,13 @@ class GitDownloader extends VcsDownloader } if ('stash' === $discardChanges) { if (!$update) { - return parent::cleanChanges($path, $update); + return parent::cleanChanges($path, $update, $package); } return $this->stashChanges($path); } - return parent::cleanChanges($path, $update); + return parent::cleanChanges($path, $update, $package); } $changes = array_map(function ($elem) { diff --git a/src/Composer/Downloader/SvnDownloader.php b/src/Composer/Downloader/SvnDownloader.php index c3cc5436e..4fca4949a 100644 --- a/src/Composer/Downloader/SvnDownloader.php +++ b/src/Composer/Downloader/SvnDownloader.php @@ -90,9 +90,9 @@ class SvnDownloader extends VcsDownloader /** * {@inheritDoc} */ - protected function cleanChanges($path, $update) + protected function cleanChanges($path, $update, $package) { - if (!$changes = $this->getLocalChanges($path)) { + if (!$changes = $this->getLocalChanges($path, $package)) { return; } @@ -101,7 +101,7 @@ class SvnDownloader extends VcsDownloader return $this->discardChanges($path); } - return parent::cleanChanges($path, $update); + return parent::cleanChanges($path, $update, $package); } $changes = array_map(function ($elem) { diff --git a/src/Composer/Downloader/VcsDownloader.php b/src/Composer/Downloader/VcsDownloader.php index 2b44ba5f0..7adfbb65d 100644 --- a/src/Composer/Downloader/VcsDownloader.php +++ b/src/Composer/Downloader/VcsDownloader.php @@ -86,7 +86,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa $this->io->write(" - Updating " . $name . " (" . $from . " => " . $to . ")"); - $this->cleanChanges($path, true); + $this->cleanChanges($path, true, $initial); try { $this->doUpdate($initial, $target, $path); } catch (\Exception $e) { @@ -126,7 +126,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa public function remove(PackageInterface $package, $path) { $this->io->write(" - Removing " . $package->getName() . " (" . $package->getPrettyVersion() . ")"); - $this->cleanChanges($path, false); + $this->cleanChanges($path, false, $package); if (!$this->filesystem->removeDirectory($path)) { // retry after a bit on windows since it tends to be touchy with mass removals if (!defined('PHP_WINDOWS_VERSION_BUILD') || (usleep(250) && !$this->filesystem->removeDirectory($path))) { @@ -144,18 +144,19 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa return $this; } - /** - * Prompt the user to check if changes should be stashed/removed or the operation aborted - * - * @param string $path - * @param bool $update if true (update) the changes can be stashed and reapplied after an update, - * if false (remove) the changes should be assumed to be lost if the operation is not aborted - * @throws \RuntimeException in case the operation must be aborted - */ - protected function cleanChanges($path, $update) + /** + * Prompt the user to check if changes should be stashed/removed or the operation aborted + * + * @param string $path + * @param bool $update if true (update) the changes can be stashed and reapplied after an update, + * if false (remove) the changes should be assumed to be lost if the operation is not aborted + * @param PackageInterface $package + * @throws \RuntimeException in case the operation must be aborted + */ + protected function cleanChanges($path, $update, $package) { // the default implementation just fails if there are any changes, override in child classes to provide stash-ability - if (null !== $this->getLocalChanges($path)) { + if (null !== $this->getLocalChanges($path, $package)) { throw new \RuntimeException('Source directory ' . $path . ' has uncommitted changes.'); } }