From c50d236378c2538c6d08b66ea733c99e29a52553 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 7 Nov 2019 20:40:28 +0100 Subject: [PATCH] Correctly load branch aliases from lock file Root aliases are also stored in the lock file, so on install do not read them from composer.json. --- src/Composer/DependencyResolver/RuleSetGenerator.php | 2 +- src/Composer/Installer.php | 5 ++++- src/Composer/Package/Locker.php | 5 +++++ .../Test/Fixtures/installer/install-aliased-alias.test | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Composer/DependencyResolver/RuleSetGenerator.php b/src/Composer/DependencyResolver/RuleSetGenerator.php index d42617a7a..76f9270be 100644 --- a/src/Composer/DependencyResolver/RuleSetGenerator.php +++ b/src/Composer/DependencyResolver/RuleSetGenerator.php @@ -262,7 +262,7 @@ class RuleSetGenerator foreach ($request->getFixedPackages() as $package) { if ($package->id == -1) { - throw new \RuntimeException("Fixed package ".$package->getName()." was not added to solver pool."); + throw new \RuntimeException("Fixed package ".$package->getName()." ".$package->getVersion().($package instanceof AliasPackage ? " (alias)" : "")." was not added to solver pool."); } $this->addRulesForPackage($package, $ignorePlatformReqs); diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 86d251756..8cdf803c5 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -658,7 +658,8 @@ class Installer // creating repository set $policy = $this->createPolicy(false); - $repositorySet = $this->createRepositorySet($platformRepo, $aliases, $lockedRepository); + // use aliases from lock file only, so empty root aliases here + $repositorySet = $this->createRepositorySet($platformRepo, array(), $lockedRepository); $repositorySet->addRepository($lockedRepository); $this->io->writeError('Installing dependencies from lock file'.($this->devMode ? ' (including require-dev)' : '').''); @@ -708,6 +709,8 @@ class Installer // TODO should we warn people / error if plugins in vendor folder do not match contents of lock file before update? //$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $this->devMode, $policy, $repositorySet, $installedRepo, $request, $lockTransaction); + } else { + // need to still create the pool to reconstruct aliases } // TODO in how far do we need to do anything here to ensure dev packages being updated to latest in lock without version change are treated correctly? diff --git a/src/Composer/Package/Locker.php b/src/Composer/Package/Locker.php index 577f9caa3..8069ba50c 100644 --- a/src/Composer/Package/Locker.php +++ b/src/Composer/Package/Locker.php @@ -176,6 +176,11 @@ class Locker $package = $this->loader->load($info); $packages->addPackage($package); $packageByName[$package->getName()] = $package; + + if ($package instanceof AliasPackage) { + $packages->addPackage($package->getAliasOf()); + $packageByName[$package->getAliasOf()->getName()] = $package->getAliasOf(); + } } if (isset($lockData['aliases'])) { diff --git a/tests/Composer/Test/Fixtures/installer/install-aliased-alias.test b/tests/Composer/Test/Fixtures/installer/install-aliased-alias.test index 2c047f8bb..63410283d 100644 --- a/tests/Composer/Test/Fixtures/installer/install-aliased-alias.test +++ b/tests/Composer/Test/Fixtures/installer/install-aliased-alias.test @@ -31,6 +31,6 @@ Installing double aliased package install --EXPECT-- Installing b/b (dev-foo) -Marking b/b (1.0.x-dev) as installed, alias of b/b (dev-foo) Marking b/b (dev-master) as installed, alias of b/b (dev-foo) +Marking b/b (1.0.x-dev) as installed, alias of b/b (dev-foo) Installing a/a (dev-master)