1
0
Fork 0

Fail early if git/hg/svn can not be found on the system, so that download can be retried from dist, fixes #9681

pull/9702/head
Jordi Boggiano 2021-02-10 10:47:37 +01:00
parent 78d7792eb8
commit 6a869ede77
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
5 changed files with 31 additions and 5 deletions

View File

@ -71,6 +71,10 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
if ($this->gitUtil->fetchRefOrSyncMirror($url, $cachePath, $ref) && is_dir($cachePath)) { if ($this->gitUtil->fetchRefOrSyncMirror($url, $cachePath, $ref) && is_dir($cachePath)) {
$this->cachedPackages[$package->getId()][$ref] = true; $this->cachedPackages[$package->getId()][$ref] = true;
} }
} else {
if (null === GitUtil::getVersion($this->process)) {
throw new \RuntimeException('git was not found in your PATH, skipping source download');
}
} }
} }

View File

@ -26,6 +26,9 @@ class HgDownloader extends VcsDownloader
*/ */
protected function doDownload(PackageInterface $package, $path, $url, PackageInterface $prevPackage = null) protected function doDownload(PackageInterface $package, $path, $url, PackageInterface $prevPackage = null)
{ {
if (null === HgUtils::getVersion($this->process)) {
throw new \RuntimeException('hg was not found in your PATH, skipping source download');
}
} }
/** /**

View File

@ -30,6 +30,11 @@ class SvnDownloader extends VcsDownloader
*/ */
protected function doDownload(PackageInterface $package, $path, $url, PackageInterface $prevPackage = null) protected function doDownload(PackageInterface $package, $path, $url, PackageInterface $prevPackage = null)
{ {
SvnUtil::cleanEnv();
$util = new SvnUtil($url, $this->io, $this->config, $this->process);
if (null === $util->binaryVersion()) {
throw new \RuntimeException('svn was not found in your PATH, skipping source download');
}
} }
/** /**

View File

@ -403,15 +403,12 @@ class Git
/** /**
* Retrieves the current git version. * Retrieves the current git version.
* *
* @return string|null The git version number. * @return string|null The git version number, if present.
*/ */
public static function getVersion(ProcessExecutor $process) public static function getVersion(ProcessExecutor $process)
{ {
if (false === self::$version) { if (false === self::$version) {
self::$version = null; self::$version = null;
if (!$process) {
$process = new ProcessExecutor;
}
if (0 === $process->execute('git --version', $output) && preg_match('/^git version (\d+(?:\.\d+)+)/m', $output, $matches)) { if (0 === $process->execute('git --version', $output) && preg_match('/^git version (\d+(?:\.\d+)+)/m', $output, $matches)) {
self::$version = $matches[1]; self::$version = $matches[1];
} }

View File

@ -74,10 +74,27 @@ class Hg
private function throwException($message, $url) private function throwException($message, $url)
{ {
if (0 !== $this->process->execute('hg --version', $ignoredOutput)) { if (null === self::getVersion($this->process)) {
throw new \RuntimeException(Url::sanitize('Failed to clone ' . $url . ', hg was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput())); throw new \RuntimeException(Url::sanitize('Failed to clone ' . $url . ', hg was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput()));
} }
throw new \RuntimeException(Url::sanitize($message)); throw new \RuntimeException(Url::sanitize($message));
} }
/**
* Retrieves the current hg version.
*
* @return string|null The hg version number, if present.
*/
public static function getVersion(ProcessExecutor $process)
{
if (false === self::$version) {
self::$version = null;
if (0 === $this->process->execute('hg --version', $output) && preg_match('/version (\d+(?:\.\d+)+)/m', $output, $matches)) {
self::$version = $matches[1];
}
}
return self::$version;
}
} }