1
0
Fork 0

Fix up create-project command

pull/1223/merge
Jordi Boggiano 2012-10-17 11:29:26 +02:00
parent 2a0e783c42
commit 110044c3ea
2 changed files with 16 additions and 10 deletions

View File

@ -26,9 +26,9 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Finder;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Composer\Util\Filesystem;
use Composer\Util\RemoteFilesystem; use Composer\Util\RemoteFilesystem;
use Composer\Package\Version\VersionParser; use Composer\Package\Version\VersionParser;
@ -190,20 +190,24 @@ EOT
if (!$keepVcs && ( if (!$keepVcs && (
!$io->isInteractive() || !$io->isInteractive() ||
$io->askConfirmation('<info>Do you want remove all previous VCS history ?</info> [<comment>yes</comment>]: ', true) $io->askConfirmation('<info>Do you want to remove the exisitng VCS (.git, .svn..) history?</info> [<comment>Y,n</comment>]? ', true)
) )
) { ) {
$finder = new Finder(); $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) { foreach (array('.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg') as $vcsName) {
$finder->name($vcsName); $finder->name($vcsName);
} }
$fs = new Filesystem();
try { try {
$fs->remove($finder); $fs = new Filesystem();
} catch (IOException $e) { foreach (iterator_to_array($finder) as $dir) {
$io->write("<error>An error occured while removing the .git directory</error>"); if (!$fs->removeDirectory($dir)) {
throw new \RuntimeException('Could not remove '.$dir);
}
}
} catch (\Exception $e) {
$io->write('<error>An error occured while removing the VCS metadata: '.$e->getMessage().'</error>');
} }
} }
} }

View File

@ -160,6 +160,7 @@ class GitDownloader extends VcsDownloader
protected function updateToCommit($path, $reference, $branch, $date) protected function updateToCommit($path, $reference, $branch, $date)
{ {
$template = 'git checkout %s && git reset --hard %1$s'; $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 // check whether non-commitish are branches or tags, and fetch branches with the remote name
$gitRef = $reference; $gitRef = $reference;
@ -167,10 +168,11 @@ class GitDownloader extends VcsDownloader
&& 0 === $this->process->execute('git branch -r', $output, $path) && 0 === $this->process->execute('git branch -r', $output, $path)
&& preg_match('{^\s+composer/'.preg_quote($reference).'$}m', $output) && 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 // checkout branch by name if the current reference matches the tip of the branch
if (preg_match('{^[a-f0-9]{40}$}', $reference) if (preg_match('{^[a-f0-9]{40}$}', $reference)