From bd826d7644f38b161c5975f4d45ff4d928087db2 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 22 Oct 2012 15:50:40 +0200 Subject: [PATCH] Mock local repositories in dry-runs --- src/Composer/Installer.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index b38b4496f..f2a970f4f 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -32,6 +32,7 @@ use Composer\Package\PackageInterface; use Composer\Package\RootPackageInterface; use Composer\Repository\CompositeRepository; use Composer\Repository\InstalledArrayRepository; +use Composer\Repository\InstalledFilesystemRepository; use Composer\Repository\PlatformRepository; use Composer\Repository\RepositoryInterface; use Composer\Repository\RepositoryManager; @@ -144,6 +145,7 @@ class Installer $this->verbose = true; $this->runScripts = false; $this->installationManager->addInstaller(new NoopInstaller); + $this->mockLocalRepositories($this->repositoryManager); } if ($this->preferSource) { @@ -618,6 +620,40 @@ class Installer } } + /** + * Replace local repositories with InstalledArrayRepository instances + * + * This is to prevent any accidental modification of the existing repos on disk + * + * @param RepositoryManager $rm + */ + private function mockLocalRepositories(RepositoryManager $rm) + { + $packages = array_map(function ($p) { + return clone $p; + }, $rm->getLocalRepository()->getPackages()); + foreach ($packages as $key => $package) { + if ($package instanceof AliasPackage) { + unset($packages[$key]); + } + } + $rm->setLocalRepository( + new InstalledArrayRepository($packages) + ); + + $packages = array_map(function ($p) { + return clone $p; + }, $rm->getLocalDevRepository()->getPackages()); + foreach ($packages as $key => $package) { + if ($package instanceof AliasPackage) { + unset($packages[$key]); + } + } + $rm->setLocalDevRepository( + new InstalledArrayRepository($packages) + ); + } + /** * Create Installer *