瀏覽代碼

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
bogdan 9 年之前
父節點
當前提交
581ce91f90
共有 2 個文件被更改,包括 27 次插入4 次删除
  1. 2 0
      src/Composer/Command/InstallCommand.php
  2. 25 4
      src/Composer/Downloader/DownloadManager.php

+ 2 - 0
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(<<<EOT
@@ -83,6 +84,7 @@ EOT
 
         $composer = $this->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);

+ 25 - 4
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);
     }
 
     /**