1
0
Fork 0

Merge pull request #2327 from pl-github/with-dependencies

Change dependency processing for update with whitelisted packages
pull/2333/merge
Jordi Boggiano 2013-10-16 09:15:46 -07:00
commit 7cfeccb101
8 changed files with 110 additions and 10 deletions

View File

@ -122,7 +122,9 @@ You can also use wildcards to update a bunch of packages at once:
autoloader. This is recommended especially for production, but can take
a bit of time to run so it is currently not done by default.
* **--lock:** Only updates the lock file hash to suppress warning about the
lock file being out of date
lock file being out of date.
* **--with-dependencies** Add also all dependencies of whitelisted packages to the whitelist.
So all packages with their dependencies are updated recursively.
## require

View File

@ -43,8 +43,9 @@ class UpdateCommand extends Command
new InputOption('no-custom-installers', null, InputOption::VALUE_NONE, 'DEPRECATED: Use no-plugins instead.'),
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('with-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('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump')
new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump.')
))
->setHelp(<<<EOT
The <info>update</info> command reads the composer.json file from the
@ -107,6 +108,7 @@ EOT
->setOptimizeAutoloader($input->getOption('optimize-autoloader'))
->setUpdate(true)
->setUpdateWhitelist($input->getOption('lock') ? array('lock') : $input->getArgument('packages'))
->setWhitelistDependencies($input->getOption('with-dependencies'))
;
if ($input->getOption('no-plugins')) {

View File

@ -106,6 +106,7 @@ class Installer
protected $update = false;
protected $runScripts = true;
protected $updateWhitelist = null;
protected $whitelistDependencies = false;
/**
* @var array
@ -851,6 +852,10 @@ class Installer
$seen[$package->getId()] = true;
$this->updateWhitelist[$package->getName()] = true;
if (!$this->whitelistDependencies) {
continue;
}
$requires = $package->getRequires();
foreach ($requires as $require) {
@ -1051,6 +1056,19 @@ class Installer
return $this;
}
/**
* Should dependencies of whitelisted packages be updated recursively?
*
* @param boolean $updateDependencies
* @return Installer
*/
public function setWhitelistDependencies($updateDependencies = true)
{
$this->whitelistDependencies = (boolean) $updateDependencies;
return $this;
}
/**
* Disables plugins.
*

View File

@ -1,5 +1,5 @@
--TEST--
Update with a package whitelist only updates those packages and their dependencies if they are not present in composer.json
Update with a package whitelist only updates those packages if they are not present in composer.json
--COMPOSER--
{
"repositories": [
@ -30,7 +30,7 @@ Update with a package whitelist only updates those packages and their dependenci
{ "name": "fixed-sub-dependency", "version": "1.0.0" }
]
--RUN--
update whitelisted
update whitelisted dependency
--EXPECT--
Updating dependency (1.0.0) to dependency (1.1.0)
Updating whitelisted (1.0.0) to whitelisted (1.1.0)

View File

@ -0,0 +1,40 @@
--TEST--
Update with a package whitelist only updates those packages and their dependencies listed as command arguments
--COMPOSER--
{
"repositories": [
{
"type": "package",
"package": [
{ "name": "fixed", "version": "1.1.0" },
{ "name": "fixed", "version": "1.0.0" },
{ "name": "whitelisted", "version": "1.1.0", "require": { "dependency": "1.1.0" } },
{ "name": "whitelisted", "version": "1.0.0", "require": { "dependency": "1.0.0" } },
{ "name": "dependency", "version": "1.1.0" },
{ "name": "dependency", "version": "1.0.0" },
{ "name": "unrelated", "version": "1.1.0", "require": { "unrelated-dependency": "1.*" } },
{ "name": "unrelated", "version": "1.0.0", "require": { "unrelated-dependency": "1.*" } },
{ "name": "unrelated-dependency", "version": "1.1.0" },
{ "name": "unrelated-dependency", "version": "1.0.0" }
]
}
],
"require": {
"fixed": "1.*",
"whitelisted": "1.*",
"unrelated": "1.*"
}
}
--INSTALLED--
[
{ "name": "fixed", "version": "1.0.0" },
{ "name": "whitelisted", "version": "1.0.0", "require": { "dependency": "1.0.0" } },
{ "name": "dependency", "version": "1.0.0" },
{ "name": "unrelated", "version": "1.0.0", "require": { "unrelated-dependency": "1.*" } },
{ "name": "unrelated-dependency", "version": "1.0.0" }
]
--RUN--
update whitelisted --with-dependencies
--EXPECT--
Updating dependency (1.0.0) to dependency (1.1.0)
Updating whitelisted (1.0.0) to whitelisted (1.1.0)

View File

@ -0,0 +1,38 @@
--TEST--
Update with a package whitelist only updates whitelisted packages if no dependency conflicts
--COMPOSER--
{
"repositories": [
{
"type": "package",
"package": [
{ "name": "fixed", "version": "1.1.0" },
{ "name": "fixed", "version": "1.0.0" },
{ "name": "whitelisted", "version": "1.1.0", "require": { "dependency": "1.1.0" } },
{ "name": "whitelisted", "version": "1.0.0", "require": { "dependency": "1.0.0" } },
{ "name": "dependency", "version": "1.1.0" },
{ "name": "dependency", "version": "1.0.0" },
{ "name": "unrelated", "version": "1.1.0", "require": { "unrelated-dependency": "1.*" } },
{ "name": "unrelated", "version": "1.0.0", "require": { "unrelated-dependency": "1.*" } },
{ "name": "unrelated-dependency", "version": "1.1.0" },
{ "name": "unrelated-dependency", "version": "1.0.0" }
]
}
],
"require": {
"fixed": "1.*",
"whitelisted": "1.*",
"unrelated": "1.*"
}
}
--INSTALLED--
[
{ "name": "fixed", "version": "1.0.0" },
{ "name": "whitelisted", "version": "1.0.0", "require": { "dependency": "1.0.0" } },
{ "name": "dependency", "version": "1.0.0" },
{ "name": "unrelated", "version": "1.0.0", "require": { "unrelated-dependency": "1.*" } },
{ "name": "unrelated-dependency", "version": "1.0.0" }
]
--RUN--
update whitelisted
--EXPECT--

View File

@ -1,5 +1,5 @@
--TEST--
Update with a package whitelist only updates those packages and their dependencies listed as command arguments
Update with a package whitelist only updates those packages listed as command arguments
--COMPOSER--
{
"repositories": [
@ -8,8 +8,8 @@ Update with a package whitelist only updates those packages and their dependenci
"package": [
{ "name": "fixed", "version": "1.1.0" },
{ "name": "fixed", "version": "1.0.0" },
{ "name": "whitelisted", "version": "1.1.0", "require": { "dependency": "1.1.0" } },
{ "name": "whitelisted", "version": "1.0.0", "require": { "dependency": "1.0.0" } },
{ "name": "whitelisted", "version": "1.1.0", "require": { "dependency": "1.*" } },
{ "name": "whitelisted", "version": "1.0.0", "require": { "dependency": "1.*" } },
{ "name": "dependency", "version": "1.1.0" },
{ "name": "dependency", "version": "1.0.0" },
{ "name": "unrelated", "version": "1.1.0", "require": { "unrelated-dependency": "1.*" } },
@ -28,7 +28,7 @@ Update with a package whitelist only updates those packages and their dependenci
--INSTALLED--
[
{ "name": "fixed", "version": "1.0.0" },
{ "name": "whitelisted", "version": "1.0.0", "require": { "dependency": "1.0.0" } },
{ "name": "whitelisted", "version": "1.0.0", "require": { "dependency": "1.*" } },
{ "name": "dependency", "version": "1.0.0" },
{ "name": "unrelated", "version": "1.0.0", "require": { "unrelated-dependency": "1.*" } },
{ "name": "unrelated-dependency", "version": "1.0.0" }
@ -36,5 +36,4 @@ Update with a package whitelist only updates those packages and their dependenci
--RUN--
update whitelisted
--EXPECT--
Updating dependency (1.0.0) to dependency (1.1.0)
Updating whitelisted (1.0.0) to whitelisted (1.1.0)

View File

@ -214,7 +214,8 @@ class InstallerTest extends TestCase
->setDevMode($input->getOption('dev'))
->setUpdate(true)
->setDryRun($input->getOption('dry-run'))
->setUpdateWhitelist($input->getArgument('packages'));
->setUpdateWhitelist($input->getArgument('packages'))
->setWhitelistDependencies($input->getOption('with-dependencies'));
return $installer->run() ? 0 : 1;
});