Clarify the fetch/push URL selection for github repos and various protocols, fix regression
parent
b080a73840
commit
fea99bcb1b
|
@ -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));
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue