Skip to content

Commit

Permalink
Clarify temporary constraint usages and throw if an unresolvable cons…
Browse files Browse the repository at this point in the history
…traint is provided
  • Loading branch information
Seldaek committed Oct 11, 2022
1 parent aeaf125 commit 436a112
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
5 changes: 3 additions & 2 deletions doc/03-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ you can skip `--with` and instead use constraints with the partial update syntax
php composer.phar update vendor/package:2.0.1 vendor/package2:3.0.*
```

The custom constraint has to be a subset of the existing constraint you have,
and this feature is only available for your root package dependencies.
> **Note:** For packages also required in your composer.json the custom constraint
> must be a subset of the existing constraint. The composer.json constraints still
> apply and the composer.json is not modified by these temporary update constraints.

### Options
Expand Down
17 changes: 12 additions & 5 deletions src/Composer/Command/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents;
use Composer\Package\Version\VersionParser;
use Composer\Semver\Intervals;
use Composer\Util\HttpDownloader;
use Composer\Advisory\Auditor;
use Symfony\Component\Console\Helper\Table;
Expand Down Expand Up @@ -147,16 +148,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

$rootPackage = $composer->getPackage();
$rootPackage->setReferences(RootPackageLoader::extractReferences($reqs, $rootPackage->getReferences()));
$rootPackage->setStabilityFlags(RootPackageLoader::extractStabilityFlags($reqs, $rootPackage->getMinimumStability(), $rootPackage->getStabilityFlags()));

$parser = new VersionParser;
$temporaryConstraints = [];
$rootRequirements = array_merge($rootPackage->getRequires(), $rootPackage->getDevRequires());
foreach ($reqs as $package => $constraint) {
$temporaryConstraints[strtolower($package)] = $parser->parseConstraints($constraint);
$package = strtolower($package);
$parsedConstraint = $parser->parseConstraints($constraint);
$temporaryConstraints[$package] = $parsedConstraint;
if (isset($rootRequirements[$package]) && !Intervals::haveIntersections($parsedConstraint, $rootRequirements[$package]->getConstraint())) {
throw new \InvalidArgumentException('The temporary constraint "'.$constraint.'" for "'.$package.'" must be a subset of the constraint in your composer.json ('.$rootRequirements[$package]->getPrettyConstraint().')');
}
}

$rootPackage = $composer->getPackage();
$rootPackage->setReferences(RootPackageLoader::extractReferences($reqs, $rootPackage->getReferences()));
$rootPackage->setStabilityFlags(RootPackageLoader::extractStabilityFlags($reqs, $rootPackage->getMinimumStability(), $rootPackage->getStabilityFlags()));

if ($input->getOption('interactive')) {
$packages = $this->getPackagesInteractively($io, $input, $output, $composer, $packages);
}
Expand Down

0 comments on commit 436a112

Please sign in to comment.