if (preg_match('{^(?:https?|git)(://github.com/.*)}', $package->getSourceUrl(), $match)) {
$protocols = array('git', 'https', 'http');
foreach ($protocols as $protocol) {
$url = escapeshellarg($protocol . $match[1]);
if (0 === $this->process->execute(sprintf($command, $url, escapeshellarg($path), $ref), $ignoredOutput)) {
return;
}
$this->filesystem->removeDirectory($path);
}
throw new \RuntimeException('Failed to checkout ' . $url .' via git, https and http protocols, aborting.' . "\n\n" . $this->process->getErrorOutput());
@ -77,4 +67,36 @@ class GitDownloader extends VcsDownloader
throw new \RuntimeException('Source directory ' . $path . ' has uncommitted changes');
}
}
/**
* Runs a command doing attempts for each protocol supported by github.
*
* @param callable $commandCallable A callable building the command for the given url
* @param string $url
* @param string $path The directory to remove for each attempt (null if not needed)
* @throws \RuntimeException
*/
protected function runCommand($commandCallable, $url, $path = null)
{
// github, autoswitch protocols
if (preg_match('{^(?:https?|git)(://github.com/.*)}', $url, $match)) {
$protocols = array('git', 'https', 'http');
foreach ($protocols as $protocol) {
$url = escapeshellarg($protocol . $match[1]);
if (0 === $this->process->execute(call_user_func($commandCallable, $url), $ignoredOutput)) {
return;
}
if (null !== $path) {
$this->filesystem->removeDirectory($path);
}
}
throw new \RuntimeException('Failed to checkout ' . $url .' via git, https and http protocols, aborting.' . "\n\n" . $this->process->getErrorOutput());