Skip to content

Commit

Permalink
Bump wildcard constraints to >=current (#11694)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden committed Oct 25, 2023
1 parent c2414c1 commit 7a09e05
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Composer/Package/Version/VersionBumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class VersionBumper
* * ^3@dev + 3.2.99999-dev -> ^3.2@dev
* * ~2 + 2.0-beta.1 -> ~2
* * dev-master + dev-master -> dev-master
* * * + 1.2.3 -> >=1.2.3
*/
public function bumpRequirement(ConstraintInterface $constraint, PackageInterface $package): string
{
Expand Down Expand Up @@ -86,6 +87,7 @@ public function bumpRequirement(ConstraintInterface $constraint, PackageInterfac
| ~'.$major.'(?:\.\d+){0,2} # e.g. ~2 or ~2.2 or ~2.2.2 but no more
| '.$major.'(?:\.[*x])+ # e.g. 2.* or 2.*.* or 2.x.x.x etc
| >=\d(?:\.\d+)* # e.g. >=2 or >=1.2 etc
| \* # full wildcard
)
(?=,|$|\ |\||@) # trailing separator
}x';
Expand All @@ -99,7 +101,7 @@ public function bumpRequirement(ConstraintInterface $constraint, PackageInterfac
}
if (str_starts_with($match[0], '~') && substr_count($match[0], '.') === 2) {
$replacement = '~'.$versionWithoutSuffix.$suffix;
} elseif (str_starts_with($match[0], '>=')) {
} elseif ($match[0] === '*' || str_starts_with($match[0], '>=')) {
$replacement = '>='.$versionWithoutSuffix.$suffix;
} else {
$replacement = $newPrettyConstraint.$suffix;
Expand Down
1 change: 1 addition & 0 deletions tests/Composer/Test/Package/Version/VersionBumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ public static function provideBumpRequirementTests(): Generator
yield 'leave extra-only-tilde alone' => ['~2.2.3.1', '2.2.4.5', '~2.2.3.1'];
yield 'upgrade bigger-or-eq to latest' => ['>=3.0', '3.4.5', '>=3.4.5'];
yield 'leave bigger-than untouched' => ['>2.2.3', '2.2.6', '>2.2.3'];
yield 'upgrade full wildcard to bigger-or-eq' => ['*', '1.2.3', '>=1.2.3'];
}
}

0 comments on commit 7a09e05

Please sign in to comment.