Skip to content

Commit cc65316

Browse files
committed
Merge branch '2.6'
2 parents 899dced + 3d6a6c2 commit cc65316

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

src/Composer/Command/BaseDependencyCommand.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,23 @@ protected function doExecute(InputInterface $input, OutputInterface $output, boo
152152
}
153153

154154
if ($inverted && $input->hasArgument(self::ARGUMENT_CONSTRAINT)) {
155-
$this->getIO()->writeError('Not finding what you were looking for? Try calling `composer update "'.$input->getArgument(self::ARGUMENT_PACKAGE).':'.$input->getArgument(self::ARGUMENT_CONSTRAINT).'" --dry-run` to get another view on the problem.');
155+
$composerCommand = 'update';
156+
157+
foreach ($composer->getPackage()->getRequires() as $rootRequirement) {
158+
if ($rootRequirement->getTarget() === $needle) {
159+
$composerCommand = 'require';
160+
break;
161+
}
162+
}
163+
164+
foreach ($composer->getPackage()->getDevRequires() as $rootRequirement) {
165+
if ($rootRequirement->getTarget() === $needle) {
166+
$composerCommand = 'require --dev';
167+
break;
168+
}
169+
}
170+
171+
$this->getIO()->writeError('Not finding what you were looking for? Try calling `composer '.$composerCommand.' "'.$needle.':'.$textConstraint.'" --dry-run` to get another view on the problem.');
156172
}
157173

158174
return 0;

src/Composer/Command/UpdateCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
161161
$parsedConstraint = $parser->parseConstraints($constraint);
162162
$temporaryConstraints[$package] = $parsedConstraint;
163163
if (isset($rootRequirements[$package]) && !Intervals::haveIntersections($parsedConstraint, $rootRequirements[$package]->getConstraint())) {
164-
throw new \InvalidArgumentException('The temporary constraint "'.$constraint.'" for "'.$package.'" must be a subset of the constraint in your composer.json ('.$rootRequirements[$package]->getPrettyConstraint().')');
164+
$io->writeError('<error>The temporary constraint "'.$constraint.'" for "'.$package.'" must be a subset of the constraint in your composer.json ('.$rootRequirements[$package]->getPrettyConstraint().')</error>');
165+
$io->write('<info>Run `composer require '.$package.'` or `composer require '.$package.':'.$constraint.'` instead to replace the constraint</info>');
166+
return self::FAILURE;
165167
}
166168
}
167169

src/Composer/Repository/VcsRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function __construct(array $repoConfig, IOInterface $io, Config $config,
9191
'svn' => 'Composer\Repository\Vcs\SvnDriver',
9292
];
9393

94-
$this->url = Platform::expandPath($repoConfig['url']);
94+
$this->url = $repoConfig['url'] = Platform::expandPath($repoConfig['url']);
9595
$this->io = $io;
9696
$this->type = $repoConfig['type'] ?? 'vcs';
9797
$this->isVerbose = $io->isVerbose();

tests/Composer/Test/Command/BaseDependencyCommandTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,11 @@ public function testWhyNotCommandOutputs(array $parameters, string $expectedOutp
396396
$secondDevNestedRequiredPackage = self::getPackage('vendor2/package3', '1.4.0');
397397

398398
$this->createComposerLock(
399-
[$someRequiredPackage],
399+
[$someRequiredPackage],
400400
[$firstDevRequiredPackage, $secondDevRequiredPackage]
401401
);
402402
$this->createInstalledJson(
403-
[$someRequiredPackage],
403+
[$someRequiredPackage],
404404
[$firstDevRequiredPackage, $secondDevRequiredPackage, $secondDevNestedRequiredPackage]
405405
);
406406

@@ -425,7 +425,7 @@ public function caseWhyNotProvider(): Generator
425425
<<<OUTPUT
426426
Package "vendor1/package1" could not be found with constraint "3.*", results below will most likely be incomplete.
427427
__root__ - requires vendor1/package1 (1.*)
428-
Not finding what you were looking for? Try calling `composer update "vendor1/package1:3.*" --dry-run` to get another view on the problem.
428+
Not finding what you were looking for? Try calling `composer require "vendor1/package1:3.*" --dry-run` to get another view on the problem.
429429
OUTPUT
430430
];
431431

@@ -434,15 +434,15 @@ public function caseWhyNotProvider(): Generator
434434
<<<OUTPUT
435435
Package "vendor1/package1" could not be found with constraint "^1.4", results below will most likely be incomplete.
436436
There is no installed package depending on "vendor1/package1" in versions not matching ^1.4
437-
Not finding what you were looking for? Try calling `composer update "vendor1/package1:^1.4" --dry-run` to get another view on the problem.
437+
Not finding what you were looking for? Try calling `composer require "vendor1/package1:^1.4" --dry-run` to get another view on the problem.
438438
OUTPUT
439439
];
440440

441441
yield 'there is no installed package depending on the package in versions not matching a specific version' => [
442442
['package' => 'vendor1/package1', 'version' => '^1.3'],
443443
<<<OUTPUT
444444
There is no installed package depending on "vendor1/package1" in versions not matching ^1.3
445-
Not finding what you were looking for? Try calling `composer update "vendor1/package1:^1.3" --dry-run` to get another view on the problem.
445+
Not finding what you were looking for? Try calling `composer require "vendor1/package1:^1.3" --dry-run` to get another view on the problem.
446446
OUTPUT
447447
];
448448

tests/Composer/Test/Command/UpdateCommandTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ public static function provideUpdates(): \Generator
8989
Problem 1
9090
- Root composer.json requires root/req 1.* -> satisfiable by root/req[1.0.0].
9191
- root/req 1.0.0 requires dep/pkg ^1 -> found dep/pkg[1.0.0, 1.0.1, 1.0.2] but it conflicts with your temporary update constraint (dep/pkg:^2).
92+
OUTPUT
93+
];
94+
95+
yield 'update with temporary constraint failing resolution on root package' => [
96+
$rootDepAndTransitiveDep,
97+
['--with' => ['root/req:^2']],
98+
<<<OUTPUT
99+
The temporary constraint "^2" for "root/req" must be a subset of the constraint in your composer.json (1.*)
100+
Run `composer require root/req` or `composer require root/req:^2` instead to replace the constraint
92101
OUTPUT
93102
];
94103
}

0 commit comments

Comments
 (0)