Skip to content

Commit

Permalink
Fix handling of zero-major versions in outdated --major-only flag, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Aug 30, 2022
1 parent 13421f7 commit 2d48c7d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Composer/Command/ShowCommand.php
Expand Up @@ -1356,8 +1356,8 @@ private function findLatestPackage(PackageInterface $package, Composer $composer
}

if ($targetVersion === null) {
if ($majorOnly && Preg::isMatch('{^(\d+)\.}', $package->getVersion(), $match)) {
$targetVersion = '>='.($match[1] + 1).',<9999999-dev';
if ($majorOnly && Preg::isMatch('{^(?P<zero_major>0\.)?(?P<first_meaningful>\d+)\.}', $package->getVersion(), $match)) {

This comment has been minimized.

Copy link
@stof

stof Aug 30, 2022

Contributor

This should allow multiple 0. parts to match the behavior of the caret operator (^0.0.1 will not accept 0.0.2 either)

This comment has been minimized.

Copy link
@Seldaek

Seldaek Aug 31, 2022

Author Member

Ah yeah good point, fixed in 3177b21

$targetVersion = '>='.$match['zero_major'].($match['first_meaningful'] + 1).',<9999999-dev';
}

if ($minorOnly) {
Expand Down
55 changes: 55 additions & 0 deletions tests/Composer/Test/Command/ShowCommandTest.php
Expand Up @@ -192,6 +192,61 @@ public function testShowPlatformOnlyShowsPlatformPackages(): void
}
}

public function testOutdatedWithZeroMajor(): void
{
$this->initTempComposer([
'repositories' => [
'packages' => [
'type' => 'package',
'package' => [
['name' => 'zero/major', 'description' => 'generic description', 'version' => '0.1.0'],
['name' => 'zero/major', 'description' => 'generic description', 'version' => '0.2.0'],
['name' => 'zero/minor', 'description' => 'generic description', 'version' => '0.1.0'],
['name' => 'zero/minor', 'description' => 'generic description', 'version' => '0.1.2'],
['name' => 'zero/patch', 'description' => 'generic description', 'version' => '0.1.2'],
['name' => 'zero/patch', 'description' => 'generic description', 'version' => '0.1.2.1'],
],
],
],
'require' => [
'zero/major' => '^0.1',
'zero/minor' => '^0.1',
'zero/patch' => '^0.1',
],
]);

$this->createInstalledJson([
$this->getPackage('zero/major', '0.1.0'),
$this->getPackage('zero/minor', '0.1.0'),
$this->getPackage('zero/patch', '0.1.2'),
]);

$appTester = $this->getApplicationTester();
$appTester->run(['command' => 'outdated', '--direct' => true, '--patch-only' => true]);
self::assertSame(
'Legend:
! patch or minor release available - update recommended
~ major release available - update possible
zero/patch 0.1.2 <highlight>! 0.1.2.1</highlight>', trim($appTester->getDisplay(true)));

$appTester = $this->getApplicationTester();
$appTester->run(['command' => 'outdated', '--direct' => true, '--minor-only' => true]);
self::assertSame(
'Legend:
! patch or minor release available - update recommended
~ major release available - update possible
zero/minor 0.1.0 <highlight>! 0.1.2 </highlight>
zero/patch 0.1.2 <highlight>! 0.1.2.1</highlight>', trim($appTester->getDisplay(true)));

$appTester = $this->getApplicationTester();
$appTester->run(['command' => 'outdated', '--direct' => true, '--major-only' => true]);
self::assertSame(
'Legend:
! patch or minor release available - update recommended
~ major release available - update possible
zero/major 0.1.0 ~ 0.2.0', trim($appTester->getDisplay(true)));
}

public function testShowAllShowsAllSections(): void
{
$this->initTempComposer([
Expand Down

0 comments on commit 2d48c7d

Please sign in to comment.