diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 6d7835e46..7989c60d2 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -26,6 +26,8 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Finder\Finder; use Composer\Json\JsonFile; use Composer\Util\RemoteFilesystem; use Composer\Package\Version\VersionParser; @@ -50,7 +52,8 @@ class CreateProjectCommand extends Command new InputOption('repository-url', null, InputOption::VALUE_REQUIRED, 'Pick a different repository url to look for the package.'), new InputOption('dev', null, InputOption::VALUE_NONE, 'Whether to install dependencies for development.'), new InputOption('no-custom-installers', null, InputOption::VALUE_NONE, 'Whether to disable custom installers.'), - new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Whether to prevent execution of all defined scripts in the root package.') + new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Whether to prevent execution of all defined scripts in the root package.'), + new InputOption('keep-vcs', null, InputOption::VALUE_NONE, 'Whether to prevent deletion vcs folder.'), )) ->setHelp(<<create-project command creates a new project from a given @@ -84,11 +87,12 @@ EOT $input->getOption('dev'), $input->getOption('repository-url'), $input->getOption('no-custom-installers'), - $input->getOption('no-scripts') + $input->getOption('no-scripts'), + $input->getOption('keep-vcs') ); } - public function installProject(IOInterface $io, $packageName, $directory = null, $packageVersion = null, $preferSource = false, $installDevPackages = false, $repositoryUrl = null, $disableCustomInstallers = false, $noScripts = false) + public function installProject(IOInterface $io, $packageName, $directory = null, $packageVersion = null, $preferSource = false, $installDevPackages = false, $repositoryUrl = null, $disableCustomInstallers = false, $noScripts = false, $keepVcs = false) { $config = Factory::createConfig(); @@ -146,7 +150,7 @@ EOT } unset($candidates); - $io->write('Installing ' . $package->getName() . ' (' . VersionParser::formatVersion($package, false) . ')', true); + $io->write('Installing ' . $package->getName() . ' (' . VersionParser::formatVersion($package, false) . ')'); if ($disableCustomInstallers) { $io->write('Custom installers have been disabled.'); @@ -162,7 +166,7 @@ EOT $package->getRepository()->notifyInstall($package); } - $io->write('Created project in ' . $directory . '', true); + $io->write('Created project in ' . $directory . ''); chdir($directory); putenv('COMPOSER_ROOT_VERSION='.$package->getPrettyVersion()); @@ -183,6 +187,25 @@ EOT } $installer->run(); + + if (!$keepVcs && ( + !$io->isInteractive() || + $io->askConfirmation('Do you want remove all previous VCS history ? [yes]: ', true) + ) + ) { + $finder = new Finder(); + $finder->in($directory)->ignoreVCS(false)->ignoreDotFiles(false); + foreach (array('.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg') as $vcsName) { + $finder->name($vcsName); + } + + $fs = new Filesystem(); + try { + $fs->remove($finder); + } catch (IOException $e) { + $io->write("An error occured while removing the .git directory"); + } + } } protected function createDownloadManager(IOInterface $io, Config $config)