Skip to content

Commit

Permalink
Fix package filter on bump command, fixes #11053
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Sep 14, 2022
1 parent 564f8be commit ec8bbe9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Composer/Command/BumpCommand.php
Expand Up @@ -13,8 +13,10 @@
namespace Composer\Command;

use Composer\Package\AliasPackage;
use Composer\Package\BasePackage;
use Composer\Package\Locker;
use Composer\Package\Version\VersionBumper;
use Composer\Pcre\Preg;
use Composer\Util\Filesystem;
use Symfony\Component\Console\Input\InputInterface;
use Composer\Console\Input\InputArgument;
Expand Down Expand Up @@ -129,6 +131,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
$tasks['require'] = $composer->getPackage()->getRequires();
}

$packagesFilter = $input->getArgument('packages');
if (count($packagesFilter) > 0) {
$pattern = BasePackage::packageNamesToRegexp(array_unique(array_map('strtolower', $packagesFilter)));
foreach ($tasks as $key => $reqs) {
foreach ($reqs as $pkgName => $link) {
if (!Preg::isMatch($pattern, $pkgName)) {
unset($tasks[$key][$pkgName]);
}
}
}
}

$updates = [];
foreach ($tasks as $key => $reqs) {
foreach ($reqs as $pkgName => $link) {
Expand Down
22 changes: 22 additions & 0 deletions tests/Composer/Test/Command/BumpCommandTest.php
Expand Up @@ -115,6 +115,28 @@ public function provideTests(): \Generator
],
];

yield 'bump only listed with packages arg' => [
[
'require' => [
'first/pkg' => '^2.0',
'second/pkg' => '3.*',
],
'require-dev' => [
'dev/pkg' => '~2.0',
],
],
['packages' => ['first/pkg', 'dev/*']],
[
'require' => [
'first/pkg' => '^2.3.4',
'second/pkg' => '3.*',
],
'require-dev' => [
'dev/pkg' => '^2.3.4.5',
],
],
];

yield 'bump works from installed repo without lock file' => [
[
'require' => [
Expand Down

0 comments on commit ec8bbe9

Please sign in to comment.