1
0
Fork 0

Clarify the fetch/push URL selection for github repos and various protocols, fix regression

pull/4982/head
Jordi Boggiano 2016-03-01 13:43:59 +00:00
parent b080a73840
commit fea99bcb1b
2 changed files with 10 additions and 6 deletions

View File

@ -344,7 +344,7 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
if (preg_match('{^(?:https?|git)://'.GitUtil::getGitHubDomainsRegex($this->config).'/([^/]+)/([^/]+?)(?:\.git)?$}', $url, $match)) {
$protocols = $this->config->get('github-protocols');
$pushUrl = 'git@'.$match[1].':'.$match[2].'/'.$match[3].'.git';
if ($protocols[0] !== 'git') {
if (!in_array('ssh', $protocols, true)) {
$pushUrl = 'https://' . $match[1] . '/'.$match[2].'/'.$match[3].'.git';
}
$cmd = sprintf('git remote set-url --push origin %s', ProcessExecutor::escape($pushUrl));

View File

@ -146,7 +146,7 @@ class GitDownloaderTest extends TestCase
->with($this->equalTo($expectedGitCommand), $this->equalTo(null), $this->equalTo($this->winCompat('composerPath')))
->will($this->returnValue(0));
$expectedGitCommand = $this->winCompat("git remote set-url --push origin 'https://github.com/composer/composer.git'");
$expectedGitCommand = $this->winCompat("git remote set-url --push origin 'git@github.com:composer/composer.git'");
$processExecutor->expects($this->at(4))
->method('execute')
->with($this->equalTo($expectedGitCommand), $this->equalTo(null), $this->equalTo($this->winCompat('composerPath')))
@ -169,15 +169,19 @@ class GitDownloaderTest extends TestCase
public function pushUrlProvider()
{
return array(
array('ssh', 'git@github.com:composer/composer', 'https://github.com/composer/composer.git'),
array('https', 'https://github.com/composer/composer', 'https://github.com/composer/composer.git'),
// ssh proto should use git@ all along
array(array('ssh'), 'git@github.com:composer/composer', 'git@github.com:composer/composer.git'),
// auto-proto uses git@ by default for push url, but not fetch
array(array('https', 'ssh', 'git'), 'https://github.com/composer/composer', 'git@github.com:composer/composer.git'),
// if restricted to https then push url is not overwritten to git@
array(array('https'), 'https://github.com/composer/composer', 'https://github.com/composer/composer.git'),
);
}
/**
* @dataProvider pushUrlProvider
*/
public function testDownloadAndSetPushUrlUseCustomVariousProtocolsForGithub($protocol, $url, $pushUrl)
public function testDownloadAndSetPushUrlUseCustomVariousProtocolsForGithub($protocols, $url, $pushUrl)
{
$packageMock = $this->getMock('Composer\Package\PackageInterface');
$packageMock->expects($this->any())
@ -211,7 +215,7 @@ class GitDownloaderTest extends TestCase
->will($this->returnValue(0));
$config = new Config();
$config->merge(array('config' => array('github-protocols' => array($protocol))));
$config->merge(array('config' => array('github-protocols' => $protocols)));
$downloader = $this->getDownloaderMock(null, $config, $processExecutor);
$downloader->download($packageMock, 'composerPath');