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\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('<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->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("<error>An error occured while removing the .git directory</error>");
$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('<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)
{
$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)