From 581ce91f9020b208b558802deaab34f6cbbaed17 Mon Sep 17 00:00:00 2001 From: bogdan Date: Thu, 4 Feb 2016 03:16:39 +0200 Subject: [PATCH] Implemented new option (ignore-missing-metadata) for composer install command The command allows to slightly change how repository updates are handled during install In the previous version composer failed to updated if .git|.svn|.hg folder was missing from the package In the current version, with the option enabled, if the update fails for exactly this reason, it'll try to remove the package completely and install it from remote --- src/Composer/Command/InstallCommand.php | 2 ++ src/Composer/Downloader/DownloadManager.php | 29 ++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index 3ae00c228..6763d24d6 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -48,6 +48,7 @@ class InstallCommand extends Command new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump'), new InputOption('classmap-authoritative', 'a', InputOption::VALUE_NONE, 'Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.'), new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore platform requirements (php & ext- packages).'), + new InputOption('ignore-missing-metadata', null, InputOption::VALUE_NONE, 'Ignore missing .git|.svn|.hg metadata repositories (when updating or reinstalling).'), new InputArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Should not be provided, use composer require instead to add a given package to composer.json.'), )) ->setHelp(<<getComposer(true, $input->getOption('no-plugins')); $composer->getDownloadManager()->setOutputProgress(!$input->getOption('no-progress')); + $composer->getDownloadManager()->setForceUpdate($input->getOption('ignore-missing-metadata')); $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'install', $input, $output); $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent); diff --git a/src/Composer/Downloader/DownloadManager.php b/src/Composer/Downloader/DownloadManager.php index 4d2e9c8f4..684b64111 100644 --- a/src/Composer/Downloader/DownloadManager.php +++ b/src/Composer/Downloader/DownloadManager.php @@ -26,6 +26,7 @@ class DownloadManager private $io; private $preferDist = false; private $preferSource = false; + private $forceUpdate = false; private $filesystem; private $downloaders = array(); @@ -69,6 +70,20 @@ class DownloadManager return $this; } + /** + * set force update mode + * forces to update the repository event when missing metadata + * + * @param $forceUpdate + * @return DownloadManager + */ + public function setForceUpdate($forceUpdate) + { + $this->forceUpdate = (boolean) $forceUpdate; + + return $this; + } + /** * Sets whether to output download progress information for all registered * downloaders @@ -250,11 +265,17 @@ class DownloadManager if ($initialType === $targetType) { $target->setInstallationSource($installationSource); - $downloader->update($initial, $target, $targetDir); - } else { - $downloader->remove($initial, $targetDir); - $this->download($target, $targetDir, 'source' === $installationSource); + try { + $downloader->update($initial, $target, $targetDir); + return; + } catch (VcsMissingMetadataException $ex) { + if ($this->forceUpdate === false) { + throw $ex; + } + } } + $downloader->remove($initial, $targetDir); + $this->download($target, $targetDir, 'source' === $installationSource); } /**