Fixes #6661: Allow a given package and its dependencies (including siblings) to be updated.

main
Matthew Grasmick 7 years ago
parent 4853661934
commit f29e98cdf9

@ -131,7 +131,7 @@ EOT
->setApcuAutoloader($apcu) ->setApcuAutoloader($apcu)
->setUpdate(true) ->setUpdate(true)
->setUpdateWhitelist($packages) ->setUpdateWhitelist($packages)
->setWhitelistDependencies(!$input->getOption('no-update-with-dependencies')) ->setIndirectWhitelistDependencies(!$input->getOption('no-update-with-dependencies'))
->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs')) ->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs'))
->setRunScripts(!$input->getOption('no-scripts')) ->setRunScripts(!$input->getOption('no-scripts'))
; ;

@ -169,7 +169,8 @@ EOT
->setApcuAutoloader($apcu) ->setApcuAutoloader($apcu)
->setUpdate(true) ->setUpdate(true)
->setUpdateWhitelist(array_keys($requirements)) ->setUpdateWhitelist(array_keys($requirements))
->setWhitelistDependencies($input->getOption('update-with-dependencies')) ->setIndirectWhitelistDependencies($input->getOption('update-with-dependencies'))
->setAllWhitelistDependencies($input->getOption('update-with-all-dependencies'))
->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs')) ->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs'))
->setPreferStable($input->getOption('prefer-stable')) ->setPreferStable($input->getOption('prefer-stable'))
->setPreferLowest($input->getOption('prefer-lowest')) ->setPreferLowest($input->getOption('prefer-lowest'))

@ -48,7 +48,8 @@ class UpdateCommand extends BaseCommand
new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Skips the execution of all scripts defined in composer.json file.'), new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Skips the execution of all scripts defined in composer.json file.'),
new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'), new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'),
new InputOption('no-suggest', null, InputOption::VALUE_NONE, 'Do not show package suggestions.'), new InputOption('no-suggest', null, InputOption::VALUE_NONE, 'Do not show package suggestions.'),
new InputOption('with-dependencies', null, InputOption::VALUE_NONE, 'Add also all dependencies of whitelisted packages to the whitelist.'), new InputOption('with-dependencies', null, InputOption::VALUE_NONE, 'Add also dependencies of whitelisted packages to the whitelist, if those dependencies are not defined in root package.'),
new InputOption('with-all-dependencies', null, InputOption::VALUE_NONE, 'Add also all dependencies of whitelisted packages to the whitelist.'),
new InputOption('verbose', 'v|vv|vvv', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'), new InputOption('verbose', 'v|vv|vvv', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'),
new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump.'), new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump.'),
new InputOption('classmap-authoritative', 'a', InputOption::VALUE_NONE, 'Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.'), new InputOption('classmap-authoritative', 'a', InputOption::VALUE_NONE, 'Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.'),
@ -145,7 +146,8 @@ EOT
->setApcuAutoloader($apcu) ->setApcuAutoloader($apcu)
->setUpdate(true) ->setUpdate(true)
->setUpdateWhitelist($input->getOption('lock') ? array('lock') : $packages) ->setUpdateWhitelist($input->getOption('lock') ? array('lock') : $packages)
->setWhitelistDependencies($input->getOption('with-dependencies')) ->setIndirectWhitelistDependencies($input->getOption('with-dependencies'))
->setAllWhitelistDependencies($input->getOption('with-all-dependencies'))
->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs')) ->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs'))
->setPreferStable($input->getOption('prefer-stable')) ->setPreferStable($input->getOption('prefer-stable'))
->setPreferLowest($input->getOption('prefer-lowest')) ->setPreferLowest($input->getOption('prefer-lowest'))

@ -126,6 +126,7 @@ class Installer
*/ */
protected $updateWhitelist = null; protected $updateWhitelist = null;
protected $whitelistDependencies = false; protected $whitelistDependencies = false;
protected $whitelistAllDependencies = false;
/** /**
* @var SuggestedPackagesReporter * @var SuggestedPackagesReporter
@ -1351,7 +1352,7 @@ class Installer
$seen[$package->getId()] = true; $seen[$package->getId()] = true;
$this->updateWhitelist[$package->getName()] = true; $this->updateWhitelist[$package->getName()] = true;
if (!$this->whitelistDependencies) { if (!$this->whitelistDependencies && !$this->whitelistAllDependencies) {
continue; continue;
} }
@ -1361,7 +1362,7 @@ class Installer
$requirePackages = $pool->whatProvides($require->getTarget()); $requirePackages = $pool->whatProvides($require->getTarget());
foreach ($requirePackages as $requirePackage) { foreach ($requirePackages as $requirePackage) {
if (isset($this->updateWhitelist[$requirePackage->getName()])) { if (!$this->whitelistAllDependencies && isset($this->updateWhitelist[$requirePackage->getName()])) {
continue; continue;
} }
@ -1652,18 +1653,37 @@ class Installer
} }
/** /**
* Should dependencies of whitelisted packages be updated recursively? * Should indirect dependencies of whitelisted packages be updated?
*
* This will NOT whitelist any dependencies that are also directly defined
* in the root package.
* *
* @param bool $updateDependencies * @param bool $updateDependencies
* @return Installer * @return Installer
*/ */
public function setWhitelistDependencies($updateDependencies = true) public function setIndirectWhitelistDependencies($updateDependencies = true)
{ {
$this->whitelistDependencies = (bool) $updateDependencies; $this->whitelistDependencies = (bool) $updateDependencies;
return $this; return $this;
} }
/**
* Should all dependencies of whitelisted packages be updated recursively?
*
* This will NOT whitelist any dependencies that are also defined in the
* root package.
*
* @param bool $updateAllDependencies
* @return Installer
*/
public function setAllWhitelistDependencies($updateAllDependencies = true)
{
$this->whitelistAllDependencies = (bool) $updateAllDependencies;
return $this;
}
/** /**
* Should packages be preferred in a stable version when updating? * Should packages be preferred in a stable version when updating?
* *

@ -0,0 +1,44 @@
--TEST--
See Github issue #6661 ( github.com/composer/composer/issues/6661 ).
When `with-all-dependencies` is used, Composer\Installer::whitelistUpdateDependencies should update all whitelisted dependencies, even if the dependency is a root requirement.
--COMPOSER--
{
"repositories": [
{
"type": "package",
"package": [
{ "name": "a", "version": "1.0.0" },
{ "name": "a", "version": "1.1.0" },
{ "name": "b", "version": "1.0.0", "require": { "a": "~1.0" } },
{ "name": "b", "version": "1.1.0", "require": { "a": "~1.1" } }
]
}
],
"require": {
"a": "~1.0",
"b": "~1.0"
}
}
--INSTALLED--
[
{ "name": "a", "version": "1.0.0" },
{ "name": "b", "version": "1.0.0", "require": { "a": "~1.0" } }
]
--RUN--
update b --with-all-dependencies
--EXPECT-OUTPUT--
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 2 updates, 0 removals
Writing lock file
Generating autoload files
--EXPECT--
Updating a (1.0.0) to a (1.1.0)
Updating b (1.0.0) to b (1.1.0)

@ -224,7 +224,8 @@ class InstallerTest extends TestCase
->setUpdate(true) ->setUpdate(true)
->setDryRun($input->getOption('dry-run')) ->setDryRun($input->getOption('dry-run'))
->setUpdateWhitelist($input->getArgument('packages')) ->setUpdateWhitelist($input->getArgument('packages'))
->setWhitelistDependencies($input->getOption('with-dependencies')) ->setIndirectWhitelistDependencies($input->getOption('with-dependencies'))
->setAllWhitelistDependencies($input->getOption('with-all-dependencies'))
->setPreferStable($input->getOption('prefer-stable')) ->setPreferStable($input->getOption('prefer-stable'))
->setPreferLowest($input->getOption('prefer-lowest')) ->setPreferLowest($input->getOption('prefer-lowest'))
->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs')); ->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs'));

Loading…
Cancel
Save