Fix up create-project command

main
Jordi Boggiano 12 years ago
parent 2a0e783c42
commit 110044c3ea

@ -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>');
}
}
}

@ -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)

Loading…
Cancel
Save