1
0
Fork 0

Set push url correctly for github clones

pull/439/head
Jordi Boggiano 2012-03-11 21:01:41 +01:00
parent 09083089ff
commit e763af7412
2 changed files with 17 additions and 3 deletions

View File

@ -34,6 +34,13 @@ class GitDownloader extends VcsDownloader
};
$this->runCommand($commandCallable, $package->getSourceUrl(), $path);
// set push url for github projects
if (preg_match('{^(?:https?|git)://github.com/([^/]+)/([^/]+?)(?:\.git)?$}', $package->getSourceUrl(), $match)) {
$pushUrl = 'git@github.com:'.$match[1].'/'.$match[2].'.git';
$cmd = sprintf('cd %s && git remote set-url --push origin %s', escapeshellarg($path), escapeshellarg($pushUrl));
$this->process->execute($cmd, $ignoredOutput);
}
}
/**

View File

@ -41,7 +41,6 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
public function testDownload()
{
$expectedGitCommand = $this->getCmd("git clone 'https://example.com/composer/composer' 'composerPath' && cd 'composerPath' && git checkout 'ref' && git reset --hard 'ref'");
$packageMock = $this->getMock('Composer\Package\PackageInterface');
$packageMock->expects($this->any())
->method('getSourceReference')
@ -50,6 +49,8 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
->method('getSourceUrl')
->will($this->returnValue('https://example.com/composer/composer'));
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
$expectedGitCommand = $this->getCmd("git clone 'https://example.com/composer/composer' 'composerPath' && cd 'composerPath' && git checkout 'ref' && git reset --hard 'ref'");
$processExecutor->expects($this->once())
->method('execute')
->with($this->equalTo($expectedGitCommand))
@ -59,13 +60,13 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
$downloader->download($packageMock, 'composerPath');
}
public function testDownloadUsesVariousProtocolsForGithub()
public function testDownloadUsesVariousProtocolsAndSetsPushUrlForGithub()
{
$packageMock = $this->getMock('Composer\Package\PackageInterface');
$packageMock->expects($this->any())
->method('getSourceReference')
->will($this->returnValue('ref'));
$packageMock->expects($this->once())
$packageMock->expects($this->any())
->method('getSourceUrl')
->will($this->returnValue('https://github.com/composer/composer'));
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
@ -88,6 +89,12 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase
->with($this->equalTo($expectedGitCommand))
->will($this->returnValue(0));
$expectedGitCommand = $this->getCmd("cd 'composerPath' && git remote set-url --push origin 'git@github.com:composer/composer.git'");
$processExecutor->expects($this->at(3))
->method('execute')
->with($this->equalTo($expectedGitCommand))
->will($this->returnValue(0));
$downloader = $this->getDownloaderMock(null, $processExecutor);
$downloader->download($packageMock, 'composerPath');
}