Skip to content

Commit

Permalink
Fix require regression with --fixed, fixes #11247
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Jan 19, 2023
1 parent 0d96fd8 commit f6f972a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Composer/Command/RequireCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
try {
$result = $this->doUpdate($input, $output, $io, $requirements, $requireKey, $removeKey);
if ($result === 0 && count($requirementsToGuess) > 0) {
$result = $this->updateRequirementsAfterResolution($requirementsToGuess, $requireKey, $removeKey, $sortPackages, $input->getOption('dry-run'));
$result = $this->updateRequirementsAfterResolution($requirementsToGuess, $requireKey, $removeKey, $sortPackages, $input->getOption('dry-run'), $input->getOption('fixed'));
}

return $result;
Expand Down Expand Up @@ -506,7 +506,7 @@ private function doUpdate(InputInterface $input, OutputInterface $output, IOInte
/**
* @param list<string> $requirementsToUpdate
*/
private function updateRequirementsAfterResolution(array $requirementsToUpdate, string $requireKey, string $removeKey, bool $sortPackages, bool $dryRun): int
private function updateRequirementsAfterResolution(array $requirementsToUpdate, string $requireKey, string $removeKey, bool $sortPackages, bool $dryRun, bool $fixed): int
{
$composer = $this->requireComposer();
$locker = $composer->getLocker();
Expand All @@ -523,7 +523,11 @@ private function updateRequirementsAfterResolution(array $requirementsToUpdate,
continue;
}

$requirements[$packageName] = $versionSelector->findRecommendedRequireVersion($package);
if ($fixed) {
$requirements[$packageName] = $package->getPrettyVersion();
} else {
$requirements[$packageName] = $versionSelector->findRecommendedRequireVersion($package);
}
$this->getIO()->writeError(sprintf(
'Using version <info>%s</info> for <info>%s</info>',
$requirements[$packageName],
Expand Down
24 changes: 24 additions & 0 deletions tests/Composer/Test/Command/RequireCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,30 @@ public static function provideRequire(): \Generator
- Locking existing/dep (1.1.0)
- Locking required/pkg (1.1.0)
Using version ^1.1 for required/pkg
OUTPUT
];

yield 'use exact constraint with --fixed' => [
[
'type' => 'project',
'repositories' => [
'packages' => [
'type' => 'package',
'package' => [
['name' => 'required/pkg', 'version' => '1.1.0'],
],
],
],
],
['packages' => ['required/pkg'], '--no-install' => true, '--fixed' => true],
<<<OUTPUT
./composer.json has been updated
Running composer update required/pkg
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
- Locking required/pkg (1.1.0)
Using version 1.1.0 for required/pkg
OUTPUT
];
}
Expand Down

0 comments on commit f6f972a

Please sign in to comment.