Fix some edge cases of tilde constraints in bump command (#12038)
* Fix: Add test case for not dropping patch version for tilde * Fix some edge cases of tilde constraints in bump command, fixes #11218 --------- Co-authored-by: Matthias Vogel <git@kanti.de>pull/12043/head
parent
e61d4ad986
commit
b2832867e6
|
@ -39,6 +39,8 @@ class VersionBumper
|
||||||
* * ^1.2 || ^2.3 + 2.4.0 -> ^1.2 || ^2.4
|
* * ^1.2 || ^2.3 + 2.4.0 -> ^1.2 || ^2.4
|
||||||
* * ^3@dev + 3.2.99999-dev -> ^3.2@dev
|
* * ^3@dev + 3.2.99999-dev -> ^3.2@dev
|
||||||
* * ~2 + 2.0-beta.1 -> ~2
|
* * ~2 + 2.0-beta.1 -> ~2
|
||||||
|
* * ~2.0.0 + 2.0.3 -> ~2.0.3
|
||||||
|
* * ~2.0 + 2.0.3 -> ^2.0.3
|
||||||
* * dev-master + dev-master -> dev-master
|
* * dev-master + dev-master -> dev-master
|
||||||
* * * + 1.2.3 -> >=1.2.3
|
* * * + 1.2.3 -> >=1.2.3
|
||||||
*/
|
*/
|
||||||
|
@ -84,7 +86,7 @@ class VersionBumper
|
||||||
(?<=,|\ |\||^) # leading separator
|
(?<=,|\ |\||^) # leading separator
|
||||||
(?P<constraint>
|
(?P<constraint>
|
||||||
\^v?'.$major.'(?:\.\d+)* # e.g. ^2.anything
|
\^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.'(?:\.\d+){1,3} # e.g. ~2.2 or ~2.2.2 or ~2.2.2.2
|
||||||
| v?'.$major.'(?:\.[*x])+ # e.g. 2.* or 2.*.* or 2.x.x.x etc
|
| v?'.$major.'(?:\.[*x])+ # e.g. 2.* or 2.*.* or 2.x.x.x etc
|
||||||
| >=v?\d(?:\.\d+)* # e.g. >=2 or >=1.2 etc
|
| >=v?\d(?:\.\d+)* # e.g. >=2 or >=1.2 etc
|
||||||
| \* # full wildcard
|
| \* # full wildcard
|
||||||
|
@ -99,8 +101,11 @@ class VersionBumper
|
||||||
if (substr_count($match[0], '.') === 2 && substr_count($versionWithoutSuffix, '.') === 1) {
|
if (substr_count($match[0], '.') === 2 && substr_count($versionWithoutSuffix, '.') === 1) {
|
||||||
$suffix = '.0';
|
$suffix = '.0';
|
||||||
}
|
}
|
||||||
if (str_starts_with($match[0], '~') && substr_count($match[0], '.') === 2) {
|
if (str_starts_with($match[0], '~') && substr_count($match[0], '.') !== 1) {
|
||||||
$replacement = '~'.$versionWithoutSuffix.$suffix;
|
// take as many version bits from the current version as we have in the constraint to bump it without making it more specific
|
||||||
|
$versionBits = explode('.', $versionWithoutSuffix);
|
||||||
|
$versionBits = array_pad($versionBits, substr_count($match[0], '.') + 1, '0');
|
||||||
|
$replacement = '~'.implode('.', array_slice($versionBits, 0, substr_count($match[0], '.') + 1));
|
||||||
} elseif ($match[0] === '*' || str_starts_with($match[0], '>=')) {
|
} elseif ($match[0] === '*' || str_starts_with($match[0], '>=')) {
|
||||||
$replacement = '>='.$versionWithoutSuffix.$suffix;
|
$replacement = '>='.$versionWithoutSuffix.$suffix;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -64,9 +64,14 @@ class VersionBumperTest extends TestCase
|
||||||
yield 'upgrade major wildcard as x to caret/2' => ['2.x.x', '2.4.0', '^2.4.0'];
|
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.*'];
|
yield 'leave minor wildcard alone' => ['2.4.*', '2.4.3', '2.4.*'];
|
||||||
yield 'leave patch wildcard alone' => ['2.4.3.*', '2.4.3.2', '2.4.3.*'];
|
yield 'leave patch wildcard alone' => ['2.4.3.*', '2.4.3.2', '2.4.3.*'];
|
||||||
|
yield 'leave single tilde alone' => ['~2', '2.4.3', '~2'];
|
||||||
yield 'upgrade tilde to caret when compatible' => ['~2.2', '2.4.3', '^2.4.3'];
|
yield 'upgrade tilde to caret when compatible' => ['~2.2', '2.4.3', '^2.4.3'];
|
||||||
yield 'update patch-only-tilde alone' => ['~2.2.3', '2.2.6', '~2.2.6'];
|
yield 'upgrade patch-only-tilde, longer version' => ['~2.2.3', '2.2.6.2', '~2.2.6'];
|
||||||
yield 'leave extra-only-tilde alone' => ['~2.2.3.1', '2.2.4.5', '~2.2.3.1'];
|
yield 'upgrade patch-only-tilde' => ['~2.2.3', '2.2.6', '~2.2.6'];
|
||||||
|
yield 'upgrade patch-only-tilde, also .0s' => ['~2.0.0', '2.0.0', '~2.0.0'];
|
||||||
|
yield 'upgrade 4 bits tilde' => ['~2.2.3.1', '2.2.4', '~2.2.4.0'];
|
||||||
|
yield 'upgrade 4 bits tilde/2' => ['~2.2.3.1', '2.2.4.0', '~2.2.4.0'];
|
||||||
|
yield 'upgrade 4 bits tilde/3' => ['~2.2.3.1', '2.2.4.5', '~2.2.4.5'];
|
||||||
yield 'upgrade bigger-or-eq to latest' => ['>=3.0', '3.4.5', '>=3.4.5'];
|
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 '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'];
|
yield 'leave bigger-than untouched' => ['>2.2.3', '2.2.6', '>2.2.3'];
|
||||||
|
|
Loading…
Reference in New Issue