8000 Add support for --minimal-changes with full updates by Seldaek · Pull Request #12349 · composer/composer · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add support for --minimal-changes with full updates #12349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions doc/03-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,10 @@ php composer.phar update vendor/package:2.0.1 vendor/package2:3.0.*
* **--prefer-lowest:** Prefer lowest versions of dependencies. Useful for testing minimal
versions of requirements, generally used with `--prefer-stable`. Can also be set via the
COMPOSER_PREFER_LOWEST=1 env var.
* **--minimal-changes (-m):** During a partial update with `-w`/`-W`, only perform absolutely necessary
changes to transitive dependencies. Can also be set via the COMPOSER_MINIMAL_CHANGES=1 env var.
* **--minimal-changes (-m):** Only perform absolutely necessary changes to dependencies.
If packages cannot be kept at their currently locked version they are updated. For partial
updates the allow-listed packages are always updated fully. Can also be set via
the COMPOSER_MINIMAL_CHANGES=1 env var.
* **--patch-only:** Only allow patch version updates for currently installed dependencies.
* **--interactive:** Interactive interface with autocompletion to select the packages to update.
* **--root-reqs:** Restricts the update to your first degree dependencies.
Expand Down
2 changes: 1 addition & 1 deletion src/Composer/Command/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function configure()
new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore all platform requirements (php & ext- packages).'),
new InputOption('prefer-stable', null, InputOption::VALUE_NONE, 'Prefer stable versions of dependencies (can also be set via the COMPOSER_PREFER_STABLE=1 env var).'),
new InputOption('prefer-lowest', null, InputOption::VALUE_NONE, 'Prefer lowest versions of dependencies (can also be set via the COMPOSER_PREFER_LOWEST=1 env var).'),
new InputOption('minimal-changes', 'm', InputOption::VALUE_NONE, 'During a partial update with -w/-W, only perform absolutely necessary changes to transitive dependencies (can also be set via the COMPOSER_MINIMAL_CHANGES=1 env var).'),
new InputOption('minimal-changes', 'm', InputOption::VALUE_NONE, 'Only perform absolutely necessary changes to dependencies. If packages cannot be kept at their currently locked version they are updated. For partial updates the allow-listed packages are always updated fully. (can also be set via the COMPOSER_MINIMAL_CHANGES=1 env var).'),
new InputOption('patch-only', null, InputOption::VALUE_NONE, 'Only allow patch version updates for currently installed dependencies.'),
new InputOption('interactive', 'i', InputOption::VALUE_NONE, 'Interactive interface with autocompletion to select the packages to update.'),
new InputOption('root-reqs', null, InputOption::VALUE_NONE, 'Restricts the update to your first degree dependencies.'),
Expand Down
4 changes: 2 additions & 2 deletions src/Composer/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -957,10 +957,10 @@ private function createPolicy(bool $forUpdate, ?LockArrayRepository $lockedRepo
}

$preferredVersions = null;
if ($forUpdate && $this->minimalUpdate && $this->updateAllowList !== null && $lockedRepo !== null) {
if ($forUpdate && $this->minimalUpdate && $lockedRepo !== null) {
$preferredVersions = [];
foreach ($lockedRepo->getPackages() as $pkg) {
if ($pkg instanceof AliasPackage || in_array($pkg->getName(), $this->updateAllowList, true)) {
if ($pkg instanceof AliasPackage || ($this->updateAllowList !== null && in_array($pkg->getName(), $this->updateAllowList, true))) {
continue;
}
$preferredVersions[$pkg->getName()] = $pkg->getVersion();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
--TEST--
Updating all dependencies only updates what really must change when a minimal update is requested

* root/dep has to upgrade to 2.x
* root/dep2 remains at 1.0.0 and does not upgrade to 1.1.0 even though it would without minimal update
* dependency/pkg has to upgrade to 2.0.0
* dependency/pkg2 remains at 1.0.0 and does not upgrade to 1.1.0 even though it would without minimal update
--COMPOSER--
{
"repositories": [
{
"type": "package",
"package": [
{ "name": "root/dep", "version": "2.0.0", "require": { "dependency/pkg": "2.*", "dependency/pkg2": "1.*" } },
{ "name": "root/dep", "version": "1.0.0", "require": { "dependency/pkg": "1.*", "dependency/pkg2": "1.*" } },
{ "name": "root/dep2", "version": "1.1.0" },
{ "name": "root/dep2", "version": "1.0.0" },
{ "name": "dependency/pkg", "version": "2.1.0" },
{ "name": "dependency/pkg", "version": "2.0.0" },
{ "name": "dependency/pkg", "version": "1.1.0" },
{ "name": "dependency/pkg", "version": "1.0.0" },
{ "name": "dependency/pkg2", "version": "2.1.0" },
{ "name": "dependency/pkg2", "version": "2.0.0" },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest having both 2.0.0 and 2.1.0 (which would both match the requirement), to cover that --minimal-changes will still update to 2.1.0 and not to 2.0.0 (i.e. it is not the --minimal-deviation that was suggested in the discussion)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 12221a3 (I think that's what you meant anyway)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

{ "name": "dependency/pkg2", "version": "1.1.0" },
{ "name": "dependency/pkg2", "version": "1.0.0" }
]
}
],
"require": {
"root/dep": "2.*",
"root/dep2": "1.*"
}
}
--INSTALLED--
[
{ "name": "root/dep", "version": "1.0.0", "require": { "dependency/pkg": "1.*", "dependency/pkg2": "1.*" } },
{ "name": "dependency/pkg", "version": "1.0.0" },
{ "name": "dependency/pkg2", "version": "1.0.0" },
{ "name": "root/dep2", "version": "1.0.0" }
]
--LOCK--
{
"packages": [
{ "name": "root/dep", "version": "1.0.0", "require": { "dependency/pkg": "1.*", "dependency/pkg2": "1.*" } },
{ "name": "dependency/pkg", "version": "1.0.0" },
{ "name": "dependency/pkg2", "version": "1.0.0" },
{ "name": "root/dep2", "version": "1.0.0" }
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "dev",
"stability-flags": {},
"prefer-stable": false,
"prefer-lowest": false,
"platform": {},
"platform-dev": {}
}
--RUN--
update --minimal-changes
--EXPECT--
Upgrading dependency/pkg (1.0.0 => 2.1.0)
Upgrading root/dep (1.0.0 => 2.0.0)
0