From 173b96de2deaf543e1d69ac5fc46865f8265f462 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 28 Jan 2020 15:13:35 +0100 Subject: [PATCH] Make sure the first require does not fail due to a missing lock file --- src/Composer/Command/RequireCommand.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Composer/Command/RequireCommand.php b/src/Composer/Command/RequireCommand.php index 48851c28d..10506170f 100644 --- a/src/Composer/Command/RequireCommand.php +++ b/src/Composer/Command/RequireCommand.php @@ -35,6 +35,7 @@ use Composer\Util\Silencer; class RequireCommand extends InitCommand { private $newlyCreated; + private $firstRequire; private $json; private $file; private $composerBackup; @@ -186,6 +187,14 @@ EOT $sortPackages = $input->getOption('sort-packages') || $composer->getConfig()->get('sort-packages'); + $this->firstRequire = $this->newlyCreated; + if (!$this->firstRequire) { + $composerDefinition = $this->json->read(); + if (empty($composerDefinition['require']) && empty($composerDefinition['require-dev'])) { + $this->firstRequire = true; + } + } + if (!$this->updateFileCleanly($this->json, $requirements, $requireKey, $removeKey, $sortPackages)) { $composerDefinition = $this->json->read(); foreach ($requirements as $package => $version) { @@ -245,7 +254,7 @@ EOT // if no lock is present, or the file is brand new, we do not do a // partial update as this is not supported by the Installer - if (!$this->newlyCreated && $composer->getConfig()->get('lock')) { + if (!$this->firstRequire && $composer->getConfig()->get('lock')) { $install->setUpdateWhitelist(array_keys($requirements)); }