1
0
Fork 0

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

pull/5490/head
Jordi Boggiano 2016-07-02 18:34:02 +01:00
parent 866820f334
commit 334d0cce6b
2 changed files with 13 additions and 3 deletions

View File

@ -51,9 +51,13 @@ 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);
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);

View File

@ -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()