From ac78eaa02794a43f748485c283f1490b7f7b130e Mon Sep 17 00:00:00 2001 From: Gennady Feldman Date: Fri, 7 Feb 2014 11:11:36 -0500 Subject: [PATCH] Adding ssh protocol support to github-protocols. --- src/Composer/Command/ConfigCommand.php | 4 ++-- src/Composer/Config.php | 4 ++-- src/Composer/Downloader/GitDownloader.php | 9 +++++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index bcd3beeab..48647512f 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -294,8 +294,8 @@ EOT } foreach ($vals as $val) { - if (!in_array($val, array('git', 'https'))) { - return 'valid protocols include: git, https'; + if (!in_array($val, array('git', 'https', 'ssh'))) { + return 'valid protocols include: git, https, ssh'; } } diff --git a/src/Composer/Config.php b/src/Composer/Config.php index 087949ef8..df006fd2e 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -24,7 +24,7 @@ class Config 'use-include-path' => false, 'preferred-install' => 'auto', 'notify-on-install' => true, - 'github-protocols' => array('git', 'https'), + 'github-protocols' => array('git', 'https', 'ssh'), 'vendor-dir' => 'vendor', 'bin-dir' => '{$vendor-dir}/bin', 'cache-dir' => '{$home}/cache', @@ -206,7 +206,7 @@ class Config case 'github-protocols': if (reset($this->config['github-protocols']) === 'http') { - throw new \RuntimeException('The http protocol for github is not available anymore, update your config\'s github-protocols to use "https" or "git"'); + throw new \RuntimeException('The http protocol for github is not available anymore, update your config\'s github-protocols to use "https" or "git" or "ssh"'); } return $this->config[$key]; diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index a6056eec8..ce02523ec 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -312,14 +312,19 @@ class GitDownloader extends VcsDownloader } // public github, autoswitch protocols - if (preg_match('{^(?:https?|git)(://'.$this->getGitHubDomainsRegex().'/.*)}', $url, $match)) { + if (preg_match('{^(?:https?|git)://'.$this->getGitHubDomainsRegex().'/(.*)}', $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)); } $messages = array(); foreach ($protocols as $protocol) { - $url = $protocol . $match[1]; + if ('ssh' === $protocol) { + $url = "git@" . $match[1] . ":" . $match[2]; + } else { + $url = $protocol ."://" . $match[1] . "/" . $match[2]; + } + if (0 === $this->process->execute(call_user_func($commandCallable, $url), $ignoredOutput, $cwd)) { return; }