diff --git a/src/Composer/Command/SelfUpdateCommand.php b/src/Composer/Command/SelfUpdateCommand.php index 0f45f8717..c9418b0a6 100644 --- a/src/Composer/Command/SelfUpdateCommand.php +++ b/src/Composer/Command/SelfUpdateCommand.php @@ -103,7 +103,7 @@ EOT foreach (Versions::CHANNELS as $channel) { if ($input->getOption($channel)) { $requestedChannel = $channel; - $versionsUtil->setChannel($channel); + $versionsUtil->setChannel($channel, $io); break; } } diff --git a/src/Composer/SelfUpdate/Versions.php b/src/Composer/SelfUpdate/Versions.php index 6a9c90120..22f57af90 100644 --- a/src/Composer/SelfUpdate/Versions.php +++ b/src/Composer/SelfUpdate/Versions.php @@ -12,6 +12,7 @@ namespace Composer\SelfUpdate; +use Composer\IO\IOInterface; use Composer\Pcre\Preg; use Composer\Util\HttpDownloader; use Composer\Config; @@ -69,7 +70,7 @@ class Versions * * @return void */ - public function setChannel(string $channel): void + public function setChannel(string $channel, IOInterface $io = null): void { if (!in_array($channel, self::$channels, true)) { throw new \InvalidArgumentException('Invalid channel '.$channel.', must be one of: ' . implode(', ', self::$channels)); @@ -77,8 +78,15 @@ class Versions $channelFile = $this->config->get('home').'/update-channel'; $this->channel = $channel; + + $storedChannel = Preg::isMatch('{^\d+$}D', $channel) ? 'stable' : $channel; + $previouslyStored = file_exists($channelFile) ? trim((string) file_get_contents($channelFile)) : null; // rewrite '2' and '1' channels to stable for future self-updates, but LTS ones like '2.2' remain pinned - file_put_contents($channelFile, (Preg::isMatch('{^\d+$}D', $channel) ? 'stable' : $channel).PHP_EOL); + file_put_contents($channelFile, $storedChannel.PHP_EOL); + + if ($io !== null && $previouslyStored !== $storedChannel) { + $io->writeError('Storing "'.$storedChannel.'" as default update channel for the next self-update run.'); + } } /**