From 3976d9f242689a1aa148475f4309efad2bca9db2 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 1 Dec 2017 14:30:51 +0100 Subject: [PATCH] Fix require command picking of specific versions, fixes #6859 --- src/Composer/Command/InitCommand.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index f95c1a129..9910843be 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -376,7 +376,7 @@ EOT )); } else { // check that the specified version/constraint exists before we proceed - $this->findBestVersionForPackage($input, $requirement['name'], $phpVersion, 'dev', $requirement['version']); + $this->findBestVersionForPackage($input, $requirement['name'], $phpVersion, $preferredStability, $requirement['version'], 'dev'); } $result[] = $requirement['name'] . ' ' . $requirement['version']; @@ -596,10 +596,10 @@ EOT return false !== filter_var($email, FILTER_VALIDATE_EMAIL); } - private function getPool(InputInterface $input) + private function getPool(InputInterface $input, $minimumStability = null) { if (!$this->pool) { - $this->pool = new Pool($this->getMinimumStability($input)); + $this->pool = new Pool($minimumStability ?: $this->getMinimumStability($input)); $this->pool->addRepository($this->getRepos()); } @@ -631,13 +631,14 @@ EOT * @param string $name * @param string $phpVersion * @param string $preferredStability + * @param string $minimumStability * @throws \InvalidArgumentException * @return string */ - private function findBestVersionForPackage(InputInterface $input, $name, $phpVersion, $preferredStability = 'stable', $requiredVersion = null) + private function findBestVersionForPackage(InputInterface $input, $name, $phpVersion, $preferredStability = 'stable', $requiredVersion = null, $minimumStability = null) { // find the latest version allowed in this pool - $versionSelector = new VersionSelector($this->getPool($input)); + $versionSelector = new VersionSelector($this->getPool($input, $minimumStability)); $package = $versionSelector->findBestCandidate($name, $requiredVersion, $phpVersion, $preferredStability); if (!$package) {