{"record":{"id":"cdaebf6f311f1de2","repo":"composer/composer","slug":"could-not-remove-s","errorCode":null,"errorMessage":"Could not remove %s","messagePattern":"Could not remove (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"warning","filePath":"src/Composer/Command/CreateProjectCommand.php","lineNumber":320,"sourceCode":"            && $installedFromVcs\n            && (\n                $input->getOption('remove-vcs')\n                || !$io->isInteractive()\n                || $io->askConfirmation('<info>Do you want to remove the existing VCS (.git, .svn..) history?</info> [<comment>y,n</comment>]? ')\n            )\n        ) {\n            $finder = new Finder();\n            $finder->depth(0)->directories()->in(Platform::getCwd())->ignoreVCS(false)->ignoreDotFiles(false);\n            foreach (['.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg', '.fslckout', '_FOSSIL_'] as $vcsName) {\n                $finder->name($vcsName);\n            }\n\n            try {\n                $dirs = iterator_to_array($finder);\n                unset($finder);\n                foreach ($dirs as $dir) {\n                    if (!$fs->removeDirectory((string) $dir)) {\n                        throw new \\RuntimeException('Could not remove '.$dir);\n                    }\n                }\n            } catch (\\Exception $e) {\n                $io->writeError('<error>An error occurred while removing the VCS metadata: '.$e->getMessage().'</error>');\n            }\n\n            $hasVcs = false;\n        }\n\n        // rewriting self.version dependencies with explicit version numbers if the package's vcs metadata is gone\n        if (!$hasVcs) {\n            $package = $composer->getPackage();\n            $configSource = new JsonConfigSource(new JsonFile('composer.json'));\n            foreach (BasePackage::$supportedLinkTypes as $type => $meta) {\n                foreach ($package->{'get'.$meta['method']}() as $link) {\n                    if ($link->getPrettyConstraint() === 'self.version') {\n                        $configSource->addLink($type, $link->getTarget(), $package->getPrettyVersion());\n                    }","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/composer/composer/blob/c435d285c9120efdca35696769c72ea9fdcc0466/src/Composer/Command/CreateProjectCommand.php#L302-L338","documentation":"Thrown during CreateProjectCommand cleanup when Filesystem::removeDirectory() returns false for a VCS metadata directory (.git/.svn/.hg/etc.) after the user agreed (or --remove-vcs/non-interactive) to strip VCS history. The exception is actually caught immediately and printed as an error line, so it does not abort the command—it degrades the VCS-removal step.","triggerScenarios":"Creating a project from a VCS source and consenting to remove VCS history, while the .git/.svn directory has restrictive permissions, is locked by another process, or sits on a filesystem where recursive removal fails.","commonSituations":"Windows file locks (editor/IDE holding .git files), read-only permissions, network-mounted filesystems, or antivirus locking files during deletion.","solutions":["Close editors/IDEs and any process holding the project directory, then `rm -rf <dir>/.git` manually.","Check and fix directory permissions: `chmod -R u+w <project>` then retry removal.","Re-run create-project; the failure is non-fatal so the project is otherwise usable.","On Windows, ensure no antivirus/explorer window is locking the folder."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Before create-project cleanup, check VCS dir writability:\n$vcsDir = $projectDir . '/.git';\nif (is_dir($vcsDir) && !is_writable($vcsDir)) {\n    chmod($vcsDir, 0700); // attempt fix\n}","typeGuard":null,"tryCatchPattern":"try {\n    $process = new Symfony\\Component\\Process\\Process(['rm','-rf',$dir.'/'.\"$vcsName\"]);\n    $process->run();\n} catch (\\Throwable $e) {\n    // non-fatal: VCS removal failed, project still usable\n    error_log('VCS cleanup failed: '.$e->getMessage());\n}","preventionTips":["Close editors/IDEs before create-project to avoid file locks on .git.","On Windows, disable antivirus real-time scan for the project folder.","Use --keep-vcs if you do not need history stripped."],"tags":["create-project","filesystem","vcs","permissions"],"backgroundTag":null,"analyzedSha":"c435d285c9120efdca35696769c72ea9fdcc0466","analyzedAt":"2026-08-07T18:58:23.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}