From 0c775e997e0747a561cacf67716e0948511877fa Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 25 Feb 2015 18:47:31 +0000 Subject: [PATCH] Fallback to https directly if ssh proto is disabled on github private repos, fixes #2786 --- src/Composer/Util/Git.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Composer/Util/Git.php b/src/Composer/Util/Git.php index f5c87487a..00c909b9d 100644 --- a/src/Composer/Util/Git.php +++ b/src/Composer/Util/Git.php @@ -52,9 +52,10 @@ class Git } } + $protocols = $this->config->get('github-protocols'); + // public github, autoswitch protocols if (preg_match('{^(?:https?|git)://'.self::getGitHubDomainsRegex($this->config).'/(.*)}', $url, $match)) { - $protocols = $this->config->get('github-protocols'); if (!is_array($protocols)) { throw new \RuntimeException('Config value "github-protocols" must be an array, got '.gettype($protocols)); } @@ -79,8 +80,11 @@ class Git $this->throwException('Failed to clone ' . self::sanitizeUrl($url) .' via '.implode(', ', $protocols).' protocols, aborting.' . "\n\n" . implode("\n", $messages), $url); } + // if we have a private github url and the ssh protocol is disabled then we skip it and directly fallback to https + $bypassSshForGitHub = preg_match('{^git@'.self::getGitHubDomainsRegex($this->config).':(.+?)\.git$}i', $url) && !in_array('ssh', $protocols, true); + $command = call_user_func($commandCallable, $url); - if (0 !== $this->process->execute($command, $ignoredOutput, $cwd)) { + if ($bypassSshForGitHub || 0 !== $this->process->execute($command, $ignoredOutput, $cwd)) { // private github repository without git access, try https with auth if (preg_match('{^git@'.self::getGitHubDomainsRegex($this->config).':(.+?)\.git$}i', $url, $match)) { if (!$this->io->hasAuthentication($match[1])) {