Bug fix Fallback to HTTPS when GIT fails for VCS #625

Closed
wants to merge 1 commit into
from
@@ -88,6 +88,18 @@ protected function runCommand($commandCallable, $url, $path = null)
$protocols = array('git', 'https', 'http');
foreach ($protocols as $protocol) {
$url = $protocol . $match[1];
+
+ // private repository without git access
+ if ($this->io->hasAuthorization($url) && preg_match('{^(?:https?)(://github.com/.*)}', $url, $match)) {
+ $auth = $this->io->getAuthorization($url);
+ $pos = strpos($url, '://') + 3;
+ $newurl = substr($url, 0, $pos);
+ $newurl .= $auth['username'] . ':' . $auth['password'] . '@';
+ $newurl .= substr($url, $pos);
+
+ $url = $newurl;
+ }
+
if (0 === $this->process->execute(call_user_func($commandCallable, $url), $handler)) {
return;
}
@@ -94,9 +94,11 @@ public function getSource($identifier)
return $this->gitDriver->getSource($identifier);
}
$label = array_search($identifier, $this->getTags()) ?: $identifier;
- if ($this->isPrivate) {
- // Private GitHub repositories should be accessed using the
- // SSH version of the URL.
+ if ($this->isPrivate && !$this->io->isInteractive()) {
+ // 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
+ // are not interactive) then we fallback to GitDriver.
$url = $this->generateSshUrl();
} else {
$url = $this->getUrl();