From 9b7a8d4543d1b8d9df818f996dc8316963224ded Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 3 May 2021 14:41:48 +0200 Subject: [PATCH] Hint at a branch rename if we detect dev-master can not be found but dev-main or dev-default exists, fixes #9850 --- src/Composer/DependencyResolver/Problem.php | 12 +++- .../Fixtures/installer/hint-main-rename.test | 64 +++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 tests/Composer/Test/Fixtures/installer/hint-main-rename.test diff --git a/src/Composer/DependencyResolver/Problem.php b/src/Composer/DependencyResolver/Problem.php index c090a34d8..996cd5005 100644 --- a/src/Composer/DependencyResolver/Problem.php +++ b/src/Composer/DependencyResolver/Problem.php @@ -291,7 +291,17 @@ class Problem return self::computeCheckForLowerPrioRepo($isVerbose, $packageName, $constraint, $packages, $allReposPackages, 'constraint'); } - return array("- Root composer.json requires $packageName".self::constraintToText($constraint) . ', ', 'found '.self::getPackageList($packages, $isVerbose).' but '.(self::hasMultipleNames($packages) ? 'these do' : 'it does').' not match the constraint.'); + $suffix = ''; + if ($constraint instanceof Constraint && $constraint->getVersion() === 'dev-master') { + foreach ($packages as $candidate) { + if (in_array($candidate->getVersion(), array('dev-default', 'dev-main'), true)) { + $suffix = ' Perhaps dev-master was renamed to '.$candidate->getPrettyVersion().'?'; + break; + } + } + } + + return array("- Root composer.json requires $packageName".self::constraintToText($constraint) . ', ', 'found '.self::getPackageList($packages, $isVerbose).' but '.(self::hasMultipleNames($packages) ? 'these do' : 'it does').' not match the constraint.' . $suffix); } if (!preg_match('{^[A-Za-z0-9_./-]+$}', $packageName)) { diff --git a/tests/Composer/Test/Fixtures/installer/hint-main-rename.test b/tests/Composer/Test/Fixtures/installer/hint-main-rename.test new file mode 100644 index 000000000..bd28a278a --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/hint-main-rename.test @@ -0,0 +1,64 @@ +--TEST-- +Test that master branches renamed to main is hinted to the user. This also covers minification of dev-x branches in output. +--COMPOSER-- +{ + "repositories": [ + { + "type": "package", + "package": [ + { "name": "package/a", "version": "2.0.0" }, + { "name": "package/a", "version": "2.0.1" }, + { "name": "package/a", "version": "2.0.2" }, + { "name": "package/a", "version": "2.0.3" }, + { "name": "package/a", "version": "2.1.0" }, + { "name": "package/a", "version": "2.2.0" }, + { "name": "package/a", "version": "2.3.1" }, + { "name": "package/a", "version": "2.3.2" }, + { "name": "package/a", "version": "2.3.3" }, + { "name": "package/a", "version": "2.3.4" }, + { "name": "package/a", "version": "2.3.5" }, + { "name": "package/a", "version": "2.4.0" }, + { "name": "package/a", "version": "2.5.0" }, + { "name": "package/a", "version": "2.6.0" }, + { "name": "package/a", "version": "dev-main" }, + { "name": "package/a", "version": "dev-foo-1" }, + { "name": "package/a", "version": "dev-foo-2" }, + { "name": "package/a", "version": "dev-foo-3" }, + { "name": "package/a", "version": "dev-foo-4" }, + { "name": "package/a", "version": "dev-foo-5" }, + { "name": "package/a", "version": "dev-foo-6" }, + { "name": "package/a", "version": "dev-foo-7" }, + { "name": "package/a", "version": "dev-foo-8" }, + { "name": "package/a", "version": "dev-foo-9" }, + { "name": "package/a", "version": "dev-foo-10" }, + { "name": "package/a", "version": "dev-foo-11" }, + { "name": "package/a", "version": "dev-foo-12" }, + { "name": "package/a", "version": "dev-foo-13" }, + { "name": "package/a", "version": "dev-foo-14" }, + { "name": "package/a", "version": "dev-foo-15" }, + { "name": "package/a", "version": "dev-foo-16" }, + { "name": "package/a", "version": "dev-foo-17" }, + { "name": "package/a", "version": "dev-foo-18" } + ] + } + ], + "require": { + "package/a": "dev-master" + } +} + +--RUN-- +update + +--EXPECT-EXIT-CODE-- +2 + +--EXPECT-OUTPUT-- +Loading composer repositories with package information +Updating dependencies +Your requirements could not be resolved to an installable set of packages. + + Problem 1 + - Root composer.json requires package/a dev-master, found package/a[dev-main, ..., dev-foo-18, 2.0.0, ..., 2.6.0] but it does not match the constraint. Perhaps dev-master was renamed to dev-main? + +--EXPECT--