From 9ca74576985b8f8a77d5d676255281fe872ed1ac Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 13 Oct 2020 16:18:28 +0200 Subject: [PATCH] Check whether remove command successfully removed the target packages, fixes #6998 --- src/Composer/Command/RemoveCommand.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Composer/Command/RemoveCommand.php b/src/Composer/Command/RemoveCommand.php index ab1962f6b..d761930af 100644 --- a/src/Composer/Command/RemoveCommand.php +++ b/src/Composer/Command/RemoveCommand.php @@ -209,9 +209,9 @@ EOT 'require' => $rootPackage->getRequires(), 'require-dev' => $rootPackage->getDevRequires(), ); - foreach ($toRemove as $type => $packages) { - foreach ($packages as $package) { - unset($links[$type][$package]); + foreach ($toRemove as $type => $names) { + foreach ($names as $name) { + unset($links[$type][$name]); } } $rootPackage->setRequires($links['require']); @@ -266,6 +266,15 @@ EOT file_put_contents($jsonFile->getPath(), $composerBackup); } + if (!$dryRun) { + foreach ($packages as $package) { + if ($composer->getRepositoryManager()->getLocalRepository()->findPackages($package)) { + $io->writeError('Removal failed, '.$package.' is still present, it may be required by another package. See `composer why '.$package.'`.'); + return 2; + } + } + } + return $status; } }