From 4ee1ff46a8c268b35626cb8ef46717a92fc4cd13 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 27 Jun 2012 18:00:52 +0200 Subject: [PATCH] Try ssh before http auth, and make sure ssh fails fast if no login is possible --- src/Composer/Downloader/GitDownloader.php | 6 +++--- src/Composer/Repository/Vcs/GitDriver.php | 2 +- src/Composer/Repository/Vcs/GitHubDriver.php | 8 +++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index 756218da5..8978a86ab 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -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 { diff --git a/src/Composer/Repository/Vcs/GitDriver.php b/src/Composer/Repository/Vcs/GitDriver.php index 271e645c7..1db4fc45e 100644 --- a/src/Composer/Repository/Vcs/GitDriver.php +++ b/src/Composer/Repository/Vcs/GitDriver.php @@ -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(); diff --git a/src/Composer/Repository/Vcs/GitHubDriver.php b/src/Composer/Repository/Vcs/GitHubDriver.php index 07c89cd03..c72290190 100644 --- a/src/Composer/Repository/Vcs/GitHubDriver.php +++ b/src/Composer/Repository/Vcs/GitHubDriver.php @@ -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('Failed to clone the '.$this->generateSshUrl().' repository, try running in interactive mode so that you can enter your username and password'); + throw $e; + } } $this->io->write('Authentication required ('.$this->url.'):'); $username = $this->io->ask('Username: ');