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

main
Jordi Boggiano 12 years ago
parent 9333579ef1
commit 4ee1ff46a8

@ -25,7 +25,7 @@ class GitDownloader extends VcsDownloader
public function doDownload(PackageInterface $package, $path) public function doDownload(PackageInterface $package, $path)
{ {
$ref = $package->getSourceReference(); $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); $this->io->write(" Cloning ".$ref);
$commandCallable = function($url) use ($ref, $path, $command) { $commandCallable = function($url) use ($ref, $path, $command) {
@ -140,7 +140,7 @@ class GitDownloader extends VcsDownloader
{ {
$handler = array($this, 'outputHandler'); $handler = array($this, 'outputHandler');
// github, autoswitch protocols // public github, autoswitch protocols
if (preg_match('{^(?:https?|git)(://github.com/.*)}', $url, $match)) { if (preg_match('{^(?:https?|git)(://github.com/.*)}', $url, $match)) {
$protocols = array('git', 'https', 'http'); $protocols = array('git', 'https', 'http');
$messages = array(); $messages = array();
@ -162,7 +162,7 @@ class GitDownloader extends VcsDownloader
$command = call_user_func($commandCallable, $url); $command = call_user_func($commandCallable, $url);
if (0 !== $this->process->execute($command, $handler)) { if (0 !== $this->process->execute($command, $handler)) {
if (preg_match('{^git@github.com:(.+?)\.git$}i', $url, $match) && $this->io->isInteractive()) { 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; $retries = 3;
$retrying = false; $retrying = false;
do { do {

@ -48,7 +48,7 @@ class GitDriver extends VcsDriver
$fs = new Filesystem(); $fs = new Filesystem();
$fs->removeDirectory($this->repoDir); $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)) { if (0 !== $this->process->execute($command, $output)) {
$output = $this->process->getErrorOutput(); $output = $this->process->getErrorOutput();

@ -259,7 +259,8 @@ class GitHubDriver extends VcsDriver
case 401: case 401:
case 404: case 404:
$this->isPrivate = true; $this->isPrivate = true;
if (!$this->io->isInteractive()) {
try {
// If this repository may be private (hard to say for sure, // If this repository may be private (hard to say for sure,
// GitHub returns 404 for private repositories) and we // GitHub returns 404 for private repositories) and we
// cannot ask for authentication credentials (because we // cannot ask for authentication credentials (because we
@ -274,6 +275,11 @@ class GitHubDriver extends VcsDriver
$this->gitDriver->initialize(); $this->gitDriver->initialize();
return; 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>):'); $this->io->write('Authentication required (<info>'.$this->url.'</info>):');
$username = $this->io->ask('Username: '); $username = $this->io->ask('Username: ');

Loading…
Cancel
Save