Warn/throw when we detect git safe.directory errors (#12178)
Fixes #12158 Fixes #12160pull/12180/head^2
parent
1f0d012845
commit
e0ed22bbd0
|
@ -92,7 +92,7 @@ EOT
|
|||
$vcsVersionChanges = [];
|
||||
|
||||
$parser = new VersionParser;
|
||||
$guesser = new VersionGuesser($composer->getConfig(), $composer->getLoop()->getProcessExecutor() ?? new ProcessExecutor($io), $parser);
|
||||
$guesser = new VersionGuesser($composer->getConfig(), $composer->getLoop()->getProcessExecutor() ?? new ProcessExecutor($io), $parser, $io);
|
||||
$dumper = new ArrayDumper;
|
||||
|
||||
// list packages
|
||||
|
|
|
@ -224,7 +224,7 @@ class PathDownloader extends FileDownloader implements VcsCapableDownloaderInter
|
|||
{
|
||||
$path = Filesystem::trimTrailingSlash($path);
|
||||
$parser = new VersionParser;
|
||||
$guesser = new VersionGuesser($this->config, $this->process, $parser);
|
||||
$guesser = new VersionGuesser($this->config, $this->process, $parser, $this->io);
|
||||
$dumper = new ArrayDumper;
|
||||
|
||||
$packageConfig = $dumper->dump($package);
|
||||
|
|
|
@ -241,7 +241,7 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
|
|||
public function getVcsReference(PackageInterface $package, string $path): ?string
|
||||
{
|
||||
$parser = new VersionParser;
|
||||
$guesser = new VersionGuesser($this->config, $this->process, $parser);
|
||||
$guesser = new VersionGuesser($this->config, $this->process, $parser, $this->io);
|
||||
$dumper = new ArrayDumper;
|
||||
|
||||
$packageConfig = $dumper->dump($package);
|
||||
|
|
|
@ -384,7 +384,7 @@ class Factory
|
|||
|
||||
// load package
|
||||
$parser = new VersionParser;
|
||||
$guesser = new VersionGuesser($config, $process, $parser);
|
||||
$guesser = new VersionGuesser($config, $process, $parser, $io);
|
||||
$loader = $this->loadRootPackage($rm, $config, $parser, $guesser, $io);
|
||||
$package = $loader->load($localConfig, 'Composer\Package\RootPackage', $cwd);
|
||||
$composer->setPackage($package);
|
||||
|
|
|
@ -60,7 +60,7 @@ class RootPackageLoader extends ArrayLoader
|
|||
|
||||
$this->manager = $manager;
|
||||
$this->config = $config;
|
||||
$this->versionGuesser = $versionGuesser ?: new VersionGuesser($config, new ProcessExecutor($io), $this->versionParser);
|
||||
$this->versionGuesser = $versionGuesser ?: new VersionGuesser($config, new ProcessExecutor($io), $this->versionParser, $io);
|
||||
$this->io = $io;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
namespace Composer\Package\Version;
|
||||
|
||||
use Composer\Config;
|
||||
use Composer\IO\IOInterface;
|
||||
use Composer\Pcre\Preg;
|
||||
use Composer\Repository\Vcs\HgDriver;
|
||||
use Composer\IO\NullIO;
|
||||
|
@ -50,11 +51,17 @@ class VersionGuesser
|
|||
*/
|
||||
private $versionParser;
|
||||
|
||||
public function __construct(Config $config, ProcessExecutor $process, SemverVersionParser $versionParser)
|
||||
/**
|
||||
* @var IOInterface|null
|
||||
*/
|
||||
private $io;
|
||||
|
||||
public function __construct(Config $config, ProcessExecutor $process, SemverVersionParser $versionParser, ?IOInterface $io = null)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->process = $process;
|
||||
$this->versionParser = $versionParser;
|
||||
$this->io = $io;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -178,6 +185,7 @@ class VersionGuesser
|
|||
$prettyVersion = $result['pretty_version'];
|
||||
}
|
||||
}
|
||||
GitUtil::checkForRepoOwnershipError($this->process->getErrorOutput(), $path, $this->io);
|
||||
|
||||
if (!$version || $isDetached) {
|
||||
$result = $this->versionFromGitTags($path);
|
||||
|
|
|
@ -116,7 +116,7 @@ class PathRepository extends ArrayRepository implements ConfigurableRepositoryIn
|
|||
$this->loader = new ArrayLoader(null, true);
|
||||
$this->url = Platform::expandPath($repoConfig['url']);
|
||||
$this->process = $process ?? new ProcessExecutor($io);
|
||||
$this->versionGuesser = new VersionGuesser($config, $this->process, new VersionParser());
|
||||
$this->versionGuesser = new VersionGuesser($config, $this->process, new VersionParser(), $io);
|
||||
$this->repoConfig = $repoConfig;
|
||||
$this->options = $repoConfig['options'] ?? [];
|
||||
if (!isset($this->options['relative'])) {
|
||||
|
|
|
@ -236,6 +236,7 @@ class GitDriver extends VcsDriver
|
|||
if ($process->execute('git tag', $output, $url) === 0) {
|
||||
return true;
|
||||
}
|
||||
GitUtil::checkForRepoOwnershipError($process->getErrorOutput(), $url);
|
||||
}
|
||||
|
||||
if (!$deep) {
|
||||
|
|
|
@ -43,6 +43,20 @@ class Git
|
|||
$this->filesystem = $fs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param IOInterface|null $io If present, a warning is output there instead of throwing, so pass this in only for cases where this is a soft failure
|
||||
*/
|
||||
public static function checkForRepoOwnershipError(string $output, string $path, ?IOInterface $io = null): void
|
||||
{
|
||||
if (str_contains($output, 'fatal: detected dubious ownership')) {
|
||||
$msg = 'The repository at "' . $path . '" does not have the correct ownership and git refuses to use it:' . PHP_EOL . PHP_EOL . $output;
|
||||
if ($io === null) {
|
||||
throw new \RuntimeException($msg);
|
||||
}
|
||||
$io->writeError('<warning>'.$msg.'</warning>');
|
||||
}
|
||||
}
|
||||
|
||||
public function setHttpDownloader(HttpDownloader $httpDownloader): void
|
||||
{
|
||||
$this->httpDownloader = $httpDownloader;
|
||||
|
@ -317,6 +331,7 @@ class Git
|
|||
|
||||
return true;
|
||||
}
|
||||
self::checkForRepoOwnershipError($this->process->getErrorOutput(), $dir);
|
||||
|
||||
// clean up directory and do a fresh clone into it
|
||||
$this->filesystem->removeDirectory($dir);
|
||||
|
@ -384,6 +399,7 @@ class Git
|
|||
return true;
|
||||
}
|
||||
}
|
||||
self::checkForRepoOwnershipError($this->process->getErrorOutput(), $dir);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue