Skip to content

Commit

Permalink
split update --prefer-lowest and --prefer-stable
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Dec 2, 2014
1 parent fb01be2 commit a896606
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
6 changes: 4 additions & 2 deletions src/Composer/Command/UpdateCommand.php
Expand Up @@ -47,7 +47,8 @@ protected function configure()
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('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore platform requirements (php & ext- packages).'),
new InputOption('prefer-lowest-stable', null, InputOption::VALUE_NONE, 'Forces all packages to their lowest stable version.'),
new InputOption('prefer-stable', null, InputOption::VALUE_NONE, 'Prefer stable versions of dependencies.'),
new InputOption('prefer-lowest', null, InputOption::VALUE_NONE, 'Prefer lowest versions of dependencies.'),
))
->setHelp(<<<EOT
The <info>update</info> command reads the composer.json file from the
Expand Down Expand Up @@ -122,7 +123,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
->setUpdateWhitelist($input->getOption('lock') ? array('lock') : $input->getArgument('packages'))
->setWhitelistDependencies($input->getOption('with-dependencies'))
->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs'))
->setPreferLowestStable($input->getOption('prefer-lowest-stable'))
->setPreferStable($input->getOption('prefer-stable'))
->setPreferLowest($input->getOption('prefer-lowest'))
;

if ($input->getOption('no-plugins')) {
Expand Down
31 changes: 21 additions & 10 deletions src/Composer/Installer.php
Expand Up @@ -107,7 +107,8 @@ class Installer
protected $update = false;
protected $runScripts = true;
protected $ignorePlatformReqs = false;
protected $preferLowestStable = false;
protected $preferStable = false;
protected $preferLowest = false;
/**
* Array of package names/globs flagged for update
*
Expand Down Expand Up @@ -699,11 +700,8 @@ private function createPolicy()
// old lock file without prefer stable will return null
// so in this case we use the composer.json info
if (null === $preferStable) {
if ($this->preferLowestStable) {
$preferStable = $preferLowest = true;
} else {
$preferStable = $this->package->getPreferStable();
}
$preferStable = $this->preferStable || $this->package->getPreferStable();
$preferLowest = $this->preferLowest;
}

return new DefaultPolicy($preferStable, $preferLowest);
Expand Down Expand Up @@ -1248,14 +1246,27 @@ public function setWhitelistDependencies($updateDependencies = true)
}

/**
* Should packages be forced to their lowest stable version when updating?
* Should packages be prefered in a stable version when updating?
*
* @param boolean $preferStable
* @return Installer
*/
public function setPreferStable($preferStable = true)
{
$this->preferStable = (boolean) $preferStable;

return $this;
}

/**
* Should packages be prefered in a lowest version when updating?
*
* @param boolean $preferLowestStable
* @param boolean $preferLowest
* @return Installer
*/
public function setPreferLowestStable($preferLowestStable = true)
public function setPreferLowest($preferLowest = true)
{
$this->preferLowestStable = (boolean) $preferLowestStable;
$this->preferLowest = (boolean) $preferLowest;

return $this;
}
Expand Down
Expand Up @@ -34,7 +34,7 @@ Updates packages to their lowest stable version
{ "name": "a/b", "version": "1.0.1" }
]
--RUN--
update --prefer-lowest-stable
update --prefer-lowest --prefer-stable
--EXPECT--
Updating a/a (1.0.0-rc1) to a/a (1.0.1)
Updating a/b (1.0.1) to a/b (1.0.0)
3 changes: 2 additions & 1 deletion tests/Composer/Test/InstallerTest.php
Expand Up @@ -217,7 +217,8 @@ public function testIntegration($file, $message, $condition, $composerConfig, $l
->setDryRun($input->getOption('dry-run'))
->setUpdateWhitelist($input->getArgument('packages'))
->setWhitelistDependencies($input->getOption('with-dependencies'))
->setPreferLowestStable($input->getOption('prefer-lowest-stable'))
->setPreferStable($input->getOption('prefer-stable'))
->setPreferLowest($input->getOption('prefer-lowest'))
->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs'));

return $installer->run();
Expand Down

0 comments on commit a896606

Please sign in to comment.