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

main
Jordi Boggiano 3 years ago
parent 78d7792eb8
commit 6a869ede77
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -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');
}
} }
} }

@ -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');
}
} }
/** /**

@ -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');
}
} }
/** /**

@ -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];
} }

@ -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;
}
} }

Loading…
Cancel
Save