From 110044c3ea9979387ca391fb17b379a8c38b5f6d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 17 Oct 2012 11:29:26 +0200 Subject: [PATCH] Fix up create-project command --- src/Composer/Command/CreateProjectCommand.php | 18 +++++++++++------- src/Composer/Downloader/GitDownloader.php | 8 +++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 7989c60d2..33cd46f0e 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -26,9 +26,9 @@ 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\Filesystem; use Composer\Util\RemoteFilesystem; use Composer\Package\Version\VersionParser; @@ -190,20 +190,24 @@ EOT if (!$keepVcs && ( !$io->isInteractive() || - $io->askConfirmation('Do you want remove all previous VCS history ? [yes]: ', true) + $io->askConfirmation('Do you want to remove the exisitng VCS (.git, .svn..) history? [Y,n]? ', true) ) ) { $finder = new Finder(); - $finder->in($directory)->ignoreVCS(false)->ignoreDotFiles(false); + $finder->directories()->in(getcwd())->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"); + $fs = new Filesystem(); + foreach (iterator_to_array($finder) as $dir) { + if (!$fs->removeDirectory($dir)) { + throw new \RuntimeException('Could not remove '.$dir); + } + } + } catch (\Exception $e) { + $io->write('An error occured while removing the VCS metadata: '.$e->getMessage().''); } } } diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index 750ff73bf..728e0ba5d 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -160,6 +160,7 @@ class GitDownloader extends VcsDownloader protected function updateToCommit($path, $reference, $branch, $date) { $template = 'git checkout %s && git reset --hard %1$s'; + $branch = preg_replace('{(?:^dev-|(?:\.x)?-dev$)}i', '', $branch); // check whether non-commitish are branches or tags, and fetch branches with the remote name $gitRef = $reference; @@ -167,11 +168,12 @@ class GitDownloader extends VcsDownloader && 0 === $this->process->execute('git branch -r', $output, $path) && preg_match('{^\s+composer/'.preg_quote($reference).'$}m', $output) ) { - $gitRef = 'composer/'.$reference; + $command = sprintf('git checkout -B %s %s && git reset --hard %2$s', escapeshellarg($branch), escapeshellarg('composer/'.$reference)); + if (0 === $this->process->execute($command, $output, $path)) { + return; + } } - $branch = preg_replace('{(?:^dev-|(?:\.x)?-dev$)}i', '', $branch); - // checkout branch by name if the current reference matches the tip of the branch if (preg_match('{^[a-f0-9]{40}$}', $reference) && 0 === $this->process->execute('git log '.escapeshellarg($branch).' -1 --format=format:%H', $output, $path)