Make sure we do not clone from local mirror if mirroring failed

main
Jordi Boggiano 8 years ago
parent 866820f334
commit 334d0cce6b

@ -51,8 +51,12 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
$gitVersion = $this->gitUtil->getVersion(); $gitVersion = $this->gitUtil->getVersion();
if ($gitVersion && version_compare($gitVersion, '2.3.0-rc0', '>=')) { 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->io->writeError(sprintf(' Cloning to cache at %s', ProcessExecutor::escape($cachePath)), true, IOInterface::DEBUG);
$this->gitUtil->syncMirror($url, $cachePath); try {
$cacheOptions = sprintf('--dissociate --reference %s ', ProcessExecutor::escape($cachePath)); $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'; $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); $this->io->writeError(" Cloning ".$ref);

@ -156,11 +156,16 @@ class GitDownloaderTest extends TestCase
$config = new Config; $config = new Config;
$this->setupConfig($config); $this->setupConfig($config);
$cachePath = $config->get('cache-vcs-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', 'https://example.com/composer/composer').'/'; $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)); $expectedGitCommand = $this->winCompat(sprintf("git clone --mirror 'https://example.com/composer/composer' '%s'", $cachePath));
$processExecutor->expects($this->at(1)) $processExecutor->expects($this->at(1))
->method('execute') ->method('execute')
->with($this->equalTo($expectedGitCommand)) ->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)); $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)) $processExecutor->expects($this->at(2))
@ -185,6 +190,7 @@ class GitDownloaderTest extends TestCase
$downloader = $this->getDownloaderMock(null, $config, $processExecutor); $downloader = $this->getDownloaderMock(null, $config, $processExecutor);
$downloader->download($packageMock, 'composerPath'); $downloader->download($packageMock, 'composerPath');
@rmdir($cachePath);
} }
public function testDownloadUsesVariousProtocolsAndSetsPushUrlForGithub() public function testDownloadUsesVariousProtocolsAndSetsPushUrlForGithub()

Loading…
Cancel
Save