function HgDriver::initialize
@inheritDoc
Overrides VcsDriverInterface::initialize
File
-
vendor/
composer/ composer/ src/ Composer/ Repository/ Vcs/ HgDriver.php, line 41
Class
- HgDriver
- @author Per Bernhardt <plb@webfactory.de>
Namespace
Composer\Repository\VcsCode
public function initialize() : void {
if (Filesystem::isLocalPath($this->url)) {
$this->repoDir = $this->url;
}
else {
if (!Cache::isUsable($this->config
->get('cache-vcs-dir'))) {
throw new \RuntimeException('HgDriver requires a usable cache directory, and it looks like you set it to be disabled');
}
$cacheDir = $this->config
->get('cache-vcs-dir');
$this->repoDir = $cacheDir . '/' . Preg::replace('{[^a-z0-9]}i', '-', Url::sanitize($this->url)) . '/';
$fs = new Filesystem();
$fs->ensureDirectoryExists($cacheDir);
if (!is_writable(dirname($this->repoDir))) {
throw new \RuntimeException('Can not clone ' . $this->url . ' to access package information. The "' . $cacheDir . '" directory is not writable by the current user.');
}
// Ensure we are allowed to use this URL by config
$this->config
->prohibitUrlByConfig($this->url, $this->io);
$hgUtils = new HgUtils($this->io, $this->config, $this->process);
// update the repo if it is a valid hg repository
if (is_dir($this->repoDir) && 0 === $this->process
->execute([
'hg',
'summary',
], $output, $this->repoDir)) {
if (0 !== $this->process
->execute([
'hg',
'pull',
], $output, $this->repoDir)) {
$this->io
->writeError('<error>Failed to update ' . $this->url . ', package information from this repository may be outdated (' . $this->process
->getErrorOutput() . ')</error>');
}
}
else {
// clean up directory and do a fresh clone into it
$fs->removeDirectory($this->repoDir);
$repoDir = $this->repoDir;
$command = static function ($url) use ($repoDir) : array {
return [
'hg',
'clone',
'--noupdate',
'--',
$url,
$repoDir,
];
};
$hgUtils->runCommand($command, $this->url, null);
}
}
$this->getTags();
$this->getBranches();
}