1
0
Fork 0

Try ssh before http auth, and make sure ssh fails fast if no login is possible

pull/851/head
Jordi Boggiano 2012-06-27 18:00:52 +02:00
parent 9333579ef1
commit 4ee1ff46a8
3 changed files with 11 additions and 5 deletions

View File

@ -25,7 +25,7 @@ class GitDownloader extends VcsDownloader
public function doDownload(PackageInterface $package, $path)
{
$ref = $package->getSourceReference();
$command = 'git clone %s %s && cd %2$s && git remote add composer %1$s && git fetch composer';
$command = 'git clone -c core.askpass=echo %s %s && cd %2$s && git remote add composer %1$s && git fetch composer';
$this->io->write(" Cloning ".$ref);
$commandCallable = function($url) use ($ref, $path, $command) {
@ -140,7 +140,7 @@ class GitDownloader extends VcsDownloader
{
$handler = array($this, 'outputHandler');
// github, autoswitch protocols
// public github, autoswitch protocols
if (preg_match('{^(?:https?|git)(://github.com/.*)}', $url, $match)) {
$protocols = array('git', 'https', 'http');
$messages = array();
@ -162,7 +162,7 @@ class GitDownloader extends VcsDownloader
$command = call_user_func($commandCallable, $url);
if (0 !== $this->process->execute($command, $handler)) {
if (preg_match('{^git@github.com:(.+?)\.git$}i', $url, $match) && $this->io->isInteractive()) {
// private repository without git access, try https with auth
// private github repository without git access, try https with auth
$retries = 3;
$retrying = false;
do {

View File

@ -48,7 +48,7 @@ class GitDriver extends VcsDriver
$fs = new Filesystem();
$fs->removeDirectory($this->repoDir);
$command = sprintf('git clone --mirror %s %s', escapeshellarg($this->url), escapeshellarg($this->repoDir));
$command = sprintf('git clone -c core.askpass=echo --mirror %s %s', escapeshellarg($this->url), escapeshellarg($this->repoDir));
if (0 !== $this->process->execute($command, $output)) {
$output = $this->process->getErrorOutput();

View File

@ -259,7 +259,8 @@ class GitHubDriver extends VcsDriver
case 401:
case 404:
$this->isPrivate = true;
if (!$this->io->isInteractive()) {
try {
// If this repository may be private (hard to say for sure,
// GitHub returns 404 for private repositories) and we
// cannot ask for authentication credentials (because we
@ -274,6 +275,11 @@ class GitHubDriver extends VcsDriver
$this->gitDriver->initialize();
return;
} catch (\RuntimeException $e) {
if (!$this->io->isInteractive()) {
$this->io->write('<error>Failed to clone the '.$this->generateSshUrl().' repository, try running in interactive mode so that you can enter your username and password</error>');
throw $e;
}
}
$this->io->write('Authentication required (<info>'.$this->url.'</info>):');
$username = $this->io->ask('Username: ');