1
0
Fork 0

fetch tag,commit form local but not ref

pull/6684/head
Robert Lu 2017-09-13 22:59:47 +08:00
parent 0ad985122d
commit e768e297cd
2 changed files with 24 additions and 8 deletions

View File

@ -55,12 +55,14 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
$this->io->writeError('', true, IOInterface::DEBUG); $this->io->writeError('', true, IOInterface::DEBUG);
$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);
try { try {
$this->gitUtil->lazySyncMirror($url, $cachePath, $ref); $cached = $this->gitUtil->fetchRef($url, $cachePath, $ref);
if (is_dir($cachePath)) { if (is_dir($cachePath)) {
$command = $command =
'git clone --no-checkout %cachePath% %path% --dissociate --reference %cachePath% ' 'git clone --no-checkout %cachePath% %path% --dissociate --reference %cachePath% '
. '&& cd '.$flag.'%path% ' . '&& cd '.$flag.'%path% '
. '&& git remote set-url origin %url% && git remote add composer %url%'; . '&& git remote set-url origin %url% && git remote add composer %url%';
if (!$cached)
$command .= ' && git fetch composer';
$msg = "Cloning ".$this->getShortHash($ref).' from cache'; $msg = "Cloning ".$this->getShortHash($ref).' from cache';
} }
} catch (\RuntimeException $e) { } catch (\RuntimeException $e) {

View File

@ -228,20 +228,34 @@ class Git
return true; return true;
} }
public function lazySyncMirror($url, $dir, $ref) public function fetchRef($url, $dir, $ref)
{ {
if (is_dir($dir) && 0 === $this->process->execute('git rev-parse --git-dir', $output, $dir) && trim($output) === '.') { if (is_dir($dir) && 0 === $this->process->execute('git rev-parse --git-dir', $output, $dir) && trim($output) === '.') {
try { try {
$commandCallable = function ($ref) { $isTag = $isRef = $actualCommit = false;
return sprintf('git cat-file -t %s', ProcessExecutor::escape($ref)); $escapedRef = ProcessExecutor::escape($ref);
}; $exitCode = $this->process->execute(sprintf('git show-ref --tags %s', $escapedRef), $output, $dir);
$this->runCommand($commandCallable, $ref, $dir); if (!$exitCode)
return true; $isTag = true;
$exitCode = $this->process->execute(sprintf('git show-ref %s', $escapedRef), $output, $dir);
if (!$exitCode)
$isRef = true;
$exitCode = $this->process->execute(sprintf('git cat-file -t %s', $escapedRef), $output, $dir);
if (!$exitCode && trim($output) == "commit")
$actualCommit = true;
if ($isTag){
return true;
}
if (!$isRef && $actualCommit) {
return true;
}
} catch (\Exception $e) { } catch (\Exception $e) {
} }
} }
return $this->syncMirror($url, $dir); $this->syncMirror($url, $dir);
return false;
} }
private function isAuthenticationFailure($url, &$match) private function isAuthenticationFailure($url, &$match)