From 7e91e9fd8063c620a27b88b788622568d2d21ec4 Mon Sep 17 00:00:00 2001 From: Marco Villegas Date: Sun, 29 May 2016 12:25:59 -0500 Subject: [PATCH] Use git cache path to mirror the repository before download to vendor target. --- src/Composer/Downloader/GitDownloader.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index 37128d772..272d496e2 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -43,10 +43,21 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface GitUtil::cleanEnv(); $path = $this->normalizePath($path); $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(); $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'; $this->io->writeError(" Cloning ".$ref);