1
0
Fork 0

Use git cache path to mirror the repository before download to vendor target.

pull/5384/head
Marco Villegas 2016-05-29 12:25:59 -05:00
parent 5bb0433a51
commit 7e91e9fd80
1 changed files with 13 additions and 2 deletions

View File

@ -43,10 +43,21 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
GitUtil::cleanEnv(); GitUtil::cleanEnv();
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
$cachePath = $this->config->get('cache-vcs-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $url).'/'; $cachePath = $this->config->get('cache-vcs-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $url).'/';
$cacheOptions = file_exists($cachePath) ? '--dissociate --reference '.ProcessExecutor::escape($cachePath).' ' : '';
$ref = $package->getSourceReference(); $ref = $package->getSourceReference();
$flag = Platform::isWindows() ? '/D ' : ''; $flag = Platform::isWindows() ? '/D ' : '';
// --dissociate option is only available since git 2.3.0-rc0
if (version_compare($this->gitUtil->getVersion(), '2.3.0-rc0', '>=')) {
if (!file_exists($cachePath)) {
$this->io->writeError(sprintf(' Cloning to cache at %s', ProcessExecutor::escape($cachePath)));
$mirrorCommand = 'git clone --mirror %s %s';
$mirrorCommandCallable = function ($url) use ($cachePath, $mirrorCommand) {
return sprintf($mirrorCommand, ProcessExecutor::escape($url), ProcessExecutor::escape($cachePath));
};
$this->gitUtil->runCommand($mirrorCommandCallable, $url, $path, true);
}
}
$cacheOptions = file_exists($cachePath) ? '--dissociate --reference '.ProcessExecutor::escape($cachePath).' ' : '';
$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);