Skip to content

Commit 6b55179

Browse files
authored
Add support for --minimal-changes with full updates (composer#12349)
Refs composer#12341
1 parent e954c51 commit 6b55179

File tree

4 files changed

+69
-5
lines changed

4 files changed

+69
-5
lines changed

doc/03-cli.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,10 @@ php composer.phar update vendor/package:2.0.1 vendor/package2:3.0.*
230230
* **--prefer-lowest:** Prefer lowest versions of dependencies. Useful for testing minimal
231231
versions of requirements, generally used with `--prefer-stable`. Can also be set via the
232232
COMPOSER_PREFER_LOWEST=1 env var.
233-
* **--minimal-changes (-m):** During a partial update with `-w`/`-W`, only perform absolutely necessary
234-
changes to transitive dependencies. Can also be set via the COMPOSER_MINIMAL_CHANGES=1 env var.
233+
* **--minimal-changes (-m):** Only perform absolutely necessary changes to dependencies.
234+
If packages cannot be kept at their currently locked version they are updated. For partial
235+
updates the allow-listed packages are always updated fully. Can also be set via
236+
the COMPOSER_MINIMAL_CHANGES=1 env var.
235237
* **--patch-only:** Only allow patch version updates for currently installed dependencies.
236238
* **--interactive:** Interactive interface with autocompletion to select the packages to update.
237239
* **--root-reqs:** Restricts the update to your first degree dependencies.

src/Composer/Command/UpdateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected function configure()
8383
new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore all platform requirements (php & ext- packages).'),
8484
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).'),
8585
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).'),
86-
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).'),
86+
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).'),
8787
new InputOption('patch-only', null, InputOption::VALUE_NONE, 'Only allow patch version updates for currently installed dependencies.'),
8888
new InputOption('interactive', 'i', InputOption::VALUE_NONE, 'Interactive interface with autocompletion to select the packages to update.'),
8989
new InputOption('root-reqs', null, InputOption::VALUE_NONE, 'Restricts the update to your first degree dependencies.'),

src/Composer/Installer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,10 +957,10 @@ private function createPolicy(bool $forUpdate, ?LockArrayRepository $lockedRepo
957957
}
958958

959959
$preferredVersions = null;
960-
if ($forUpdate && $this->minimalUpdate && $this->updateAllowList !== null && $lockedRepo !== null) {
960+
if ($forUpdate && $this->minimalUpdate && $lockedRepo !== null) {
961961
$preferredVersions = [];
962962
foreach ($lockedRepo->getPackages() as $pkg) {
963-
if ($pkg instanceof AliasPackage || in_array($pkg->getName(), $this->updateAllowList, true)) {
963+
if ($pkg instanceof AliasPackage || ($this->updateAllowList !== null && in_array($pkg->getName(), $this->updateAllowList, true))) {
964964
continue;
965965
}
966966
$preferredVersions[$pkg->getName()] = $pkg->getVersion();
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--TEST--
2+
Updating all dependencies only updates what really must change when a minimal update is requested
3+
4+
* root/dep has to upgrade to 2.x
5+
* root/dep2 remains at 1.0.0 and does not upgrade to 1.1.0 even though it would without minimal update
6+
* dependency/pkg has to upgrade to 2.0.0
7+
* dependency/pkg2 remains at 1.0.0 and does not upgrade to 1.1.0 even though it would without minimal update
8+
--COMPOSER--
9+
{
10+
"repositories": [
11+
{
12+
"type": "package",
13+
"package": [
14+
{ "name": "root/dep", "version": "2.0.0", "require": { "dependency/pkg": "2.*", "dependency/pkg2": "1.*" } },
15+
{ "name": "root/dep", "version": "1.0.0", "require": { "dependency/pkg": "1.*", "dependency/pkg2": "1.*" } },
16+
{ "name": "root/dep2", "version": "1.1.0" },
17+
{ "name": "root/dep2", "version": "1.0.0" },
18+
{ "name": "dependency/pkg", "version": "2.1.0" },
19+
{ "name": "dependency/pkg", "version": "2.0.0" },
20+
{ "name": "dependency/pkg", "version": "1.1.0" },
21+
{ "name": "dependency/pkg", "version": "1.0.0" },
22+
{ "name": "dependency/pkg2", "version": "2.1.0" },
23+
{ "name": "dependency/pkg2", "version": "2.0.0" },
24+
{ "name": "dependency/pkg2", "version": "1.1.0" },
25+
{ "name": "dependency/pkg2", "version": "1.0.0" }
26+
]
27+
}
28+
],
29+
"require": {
30+
"root/dep": "2.*",
31+
"root/dep2": "1.*"
32+
}
33+
}
34+
--INSTALLED--
35+
[
36+
{ "name": "root/dep", "version": "1.0.0", "require": { "dependency/pkg": "1.*", "dependency/pkg2": "1.*" } },
37+
{ "name": "dependency/pkg", "version": "1.0.0" },
38+
{ "name": "dependency/pkg2", "version": "1.0.0" },
39+
{ "name": "root/dep2", "version": "1.0.0" }
40+
]
41+
--LOCK--
42+
{
43+
"packages": [
44+
{ "name": "root/dep", "version": "1.0.0", "require": { "dependency/pkg": "1.*", "dependency/pkg2": "1.*" } },
45+
{ "name": "dependency/pkg", "version": "1.0.0" },
46+
{ "name": "dependency/pkg2", "version": "1.0.0" },
47+
{ "name": "root/dep2", "version": "1.0.0" }
48+
],
49+
"packages-dev": [],
50+
"aliases": [],
51+
"minimum-stability": "dev",
52+
"stability-flags": {},
53+
"prefer-stable": false,
54+
"prefer-lowest": false,
55+
"platform": {},
56+
"platform-dev": {}
57+
}
58+
--RUN--
59+
update --minimal-changes
60+
--EXPECT--
61+
Upgrading dependency/pkg (1.0.0 => 2.1.0)
62+
Upgrading root/dep (1.0.0 => 2.0.0)

0 commit comments

Comments
 (0)