Skip to content

Commit

Permalink
Fix bump command not bumping versions with a v prefix e.g. ^v2.4, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Dec 19, 2023
1 parent e14d28b commit 4a209b7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Composer/Package/Version/VersionBumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public function bumpRequirement(ConstraintInterface $constraint, PackageInterfac
$pattern = '{
(?<=,|\ |\||^) # leading separator
(?P<constraint>
\^'.$major.'(?:\.\d+)* # e.g. ^2.anything
| ~'.$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
\^v?'.$major.'(?:\.\d+)* # e.g. ^2.anything
| ~v?'.$major.'(?:\.\d+){0,2} # e.g. ~2 or ~2.2 or ~2.2.2 but no more
| v?'.$major.'(?:\.[*x])+ # e.g. 2.* or 2.*.* or 2.x.x.x etc
| >=v?\d(?:\.\d+)* # e.g. >=2 or >=1.2 etc
)
(?=,|$|\ |\||@) # trailing separator
}x';
Expand Down
2 changes: 1 addition & 1 deletion tests/Composer/Test/Command/BumpCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static function provideTests(): \Generator
yield 'bump all by default' => [
[
'require' => [
'first/pkg' => '^2.0',
'first/pkg' => '^v2.0',
'second/pkg' => '3.*',
],
'require-dev' => [
Expand Down
3 changes: 3 additions & 0 deletions tests/Composer/Test/Package/Version/VersionBumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static function provideBumpRequirementTests(): Generator
{
// constraint, version, expected recommendation, [branch-alias]
yield 'upgrade caret' => ['^1.0', '1.2.1', '^1.2.1'];
yield 'upgrade caret with v' => ['^v1.0', '1.2.1', '^1.2.1'];
yield 'skip trailing .0s' => ['^1.0', '1.0.0', '^1.0'];
yield 'skip trailing .0s/2' => ['^1.2', '1.2.0', '^1.2'];
yield 'preserve major.minor.patch format when installed minor is 0' => ['^1.0.0', '1.2.0', '^1.2.0'];
Expand All @@ -58,6 +59,7 @@ public static function provideBumpRequirementTests(): Generator
yield 'dev version does not upgrade' => ['^3.2', 'dev-main', '^3.2'];
yield 'upgrade dev version if aliased' => ['^3.2', 'dev-main', '^3.3', '3.3.x-dev'];
yield 'upgrade major wildcard to caret' => ['2.*', '2.4.0', '^2.4'];
yield 'upgrade major wildcard to caret with v' => ['v2.*', '2.4.0', '^2.4'];
yield 'upgrade major wildcard as x to caret' => ['2.x', '2.4.0', '^2.4'];
yield 'upgrade major wildcard as x to caret/2' => ['2.x.x', '2.4.0', '^2.4.0'];
yield 'leave minor wildcard alone' => ['2.4.*', '2.4.3', '2.4.*'];
Expand All @@ -66,6 +68,7 @@ public static function provideBumpRequirementTests(): Generator
yield 'update patch-only-tilde alone' => ['~2.2.3', '2.2.6', '~2.2.6'];
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 'upgrade bigger-or-eq to latest with v' => ['>=v3.0', '3.4.5', '>=3.4.5'];
yield 'leave bigger-than untouched' => ['>2.2.3', '2.2.6', '>2.2.3'];
}
}

0 comments on commit 4a209b7

Please sign in to comment.