diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index a0e2a9adf..bdebaf4cf 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -52,6 +52,10 @@ class GitDownloader extends VcsDownloader }; $this->gitUtil->runCommand($commandCallable, $url, $path, true); + if ($url !== $package->getSourceUrl()) { + $url = $package->getSourceUrl(); + $this->process->execute(sprintf('git remote set-url origin %s', ProcessExecutor::escape($url)), $output, $path); + } $this->setPushUrl($path, $url); if ($newRef = $this->updateToCommit($path, $ref, $package->getPrettyVersion(), $package->getReleaseDate())) { @@ -60,10 +64,6 @@ class GitDownloader extends VcsDownloader } $package->setSourceReference($newRef); } - - if ($url !== $package->getSourceUrl()) { - $this->process->execute(sprintf('git remote set-url origin %s', $package->getSourceUrl()), $output, $path); - } } /** diff --git a/tests/Composer/Test/Downloader/GitDownloaderTest.php b/tests/Composer/Test/Downloader/GitDownloaderTest.php index 194fc96c9..05cc8f30e 100644 --- a/tests/Composer/Test/Downloader/GitDownloaderTest.php +++ b/tests/Composer/Test/Downloader/GitDownloaderTest.php @@ -53,6 +53,9 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase $packageMock->expects($this->any()) ->method('getSourceUrls') ->will($this->returnValue(array('https://example.com/composer/composer'))); + $packageMock->expects($this->any()) + ->method('getSourceUrl') + ->will($this->returnValue('https://example.com/composer/composer')); $packageMock->expects($this->any()) ->method('getPrettyVersion') ->will($this->returnValue('dev-master')); @@ -91,36 +94,45 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue('ref')); $packageMock->expects($this->any()) ->method('getSourceUrls') - ->will($this->returnValue(array('https://github.com/composer/composer'))); + ->will($this->returnValue(array('https://github.com/mirrors/composer', 'https://github.com/composer/composer'))); + $packageMock->expects($this->any()) + ->method('getSourceUrl') + ->will($this->returnValue('https://github.com/composer/composer')); $packageMock->expects($this->any()) ->method('getPrettyVersion') ->will($this->returnValue('1.0.0')); $processExecutor = $this->getMock('Composer\Util\ProcessExecutor'); - $expectedGitCommand = $this->winCompat("git clone --no-checkout 'git://github.com/composer/composer' 'composerPath' && cd 'composerPath' && git remote add composer 'git://github.com/composer/composer' && git fetch composer"); + $expectedGitCommand = $this->winCompat("git clone --no-checkout 'git://github.com/mirrors/composer' 'composerPath' && cd 'composerPath' && git remote add composer 'git://github.com/mirrors/composer' && git fetch composer"); $processExecutor->expects($this->at(0)) ->method('execute') ->with($this->equalTo($expectedGitCommand)) ->will($this->returnValue(1)); - $expectedGitCommand = $this->winCompat("git clone --no-checkout 'https://github.com/composer/composer' 'composerPath' && cd 'composerPath' && git remote add composer 'https://github.com/composer/composer' && git fetch composer"); + $expectedGitCommand = $this->winCompat("git clone --no-checkout 'https://github.com/mirrors/composer' 'composerPath' && cd 'composerPath' && git remote add composer 'https://github.com/mirrors/composer' && git fetch composer"); $processExecutor->expects($this->at(2)) ->method('execute') ->with($this->equalTo($expectedGitCommand)) ->will($this->returnValue(0)); - $expectedGitCommand = $this->winCompat("git remote set-url --push origin 'git@github.com:composer/composer.git'"); + $expectedGitCommand = $this->winCompat("git remote set-url origin 'https://github.com/composer/composer'"); $processExecutor->expects($this->at(3)) ->method('execute') ->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 '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'))) + ->will($this->returnValue(0)); + + $processExecutor->expects($this->at(5)) ->method('execute') ->with($this->equalTo('git branch -r')) ->will($this->returnValue(0)); - $processExecutor->expects($this->at(5)) + $processExecutor->expects($this->at(6)) ->method('execute') ->with($this->equalTo($this->winCompat("git checkout 'ref' && git reset --hard 'ref'")), $this->equalTo(null), $this->equalTo($this->winCompat('composerPath'))) ->will($this->returnValue(0)); @@ -149,6 +161,9 @@ class GitDownloaderTest extends \PHPUnit_Framework_TestCase $packageMock->expects($this->any()) ->method('getSourceUrls') ->will($this->returnValue(array('https://github.com/composer/composer'))); + $packageMock->expects($this->any()) + ->method('getSourceUrl') + ->will($this->returnValue('https://github.com/composer/composer')); $packageMock->expects($this->any()) ->method('getPrettyVersion') ->will($this->returnValue('1.0.0'));