From 334d0cce6b056e7555daf4c68c48cbe40ee4d51a Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 2 Jul 2016 18:34:02 +0100 Subject: [PATCH] Make sure we do not clone from local mirror if mirroring failed --- src/Composer/Downloader/GitDownloader.php | 8 ++++++-- tests/Composer/Test/Downloader/GitDownloaderTest.php | 8 +++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index 5f41d6842..daf509d81 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -51,8 +51,12 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface $gitVersion = $this->gitUtil->getVersion(); if ($gitVersion && version_compare($gitVersion, '2.3.0-rc0', '>=')) { $this->io->writeError(sprintf(' Cloning to cache at %s', ProcessExecutor::escape($cachePath)), true, IOInterface::DEBUG); - $this->gitUtil->syncMirror($url, $cachePath); - $cacheOptions = sprintf('--dissociate --reference %s ', ProcessExecutor::escape($cachePath)); + try { + $this->gitUtil->syncMirror($url, $cachePath); + if (is_dir($cachePath)) { + $cacheOptions = sprintf('--dissociate --reference %s ', ProcessExecutor::escape($cachePath)); + } + } catch (\RuntimeException $e) {} } $command = 'git clone --no-checkout %s %s '.$cacheOptions.'&& cd '.$flag.'%2$s && git remote add composer %1$s && git fetch composer'; $this->io->writeError(" Cloning ".$ref); diff --git a/tests/Composer/Test/Downloader/GitDownloaderTest.php b/tests/Composer/Test/Downloader/GitDownloaderTest.php index 297362a44..3c32bcb29 100644 --- a/tests/Composer/Test/Downloader/GitDownloaderTest.php +++ b/tests/Composer/Test/Downloader/GitDownloaderTest.php @@ -156,11 +156,16 @@ class GitDownloaderTest extends TestCase $config = new Config; $this->setupConfig($config); $cachePath = $config->get('cache-vcs-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', 'https://example.com/composer/composer').'/'; + $expectedGitCommand = $this->winCompat(sprintf("git clone --mirror 'https://example.com/composer/composer' '%s'", $cachePath)); $processExecutor->expects($this->at(1)) ->method('execute') ->with($this->equalTo($expectedGitCommand)) - ->will($this->returnValue(0)); + ->will($this->returnCallback(function () use ($cachePath) { + @mkdir($cachePath, 0777, true); + + return 0; + })); $expectedGitCommand = $this->winCompat(sprintf("git clone --no-checkout 'https://example.com/composer/composer' 'composerPath' --dissociate --reference '%s' && cd 'composerPath' && git remote add composer 'https://example.com/composer/composer' && git fetch composer", $cachePath)); $processExecutor->expects($this->at(2)) @@ -185,6 +190,7 @@ class GitDownloaderTest extends TestCase $downloader = $this->getDownloaderMock(null, $config, $processExecutor); $downloader->download($packageMock, 'composerPath'); + @rmdir($cachePath); } public function testDownloadUsesVariousProtocolsAndSetsPushUrlForGithub()