function GitDriver::initialize
@inheritDoc
Overrides VcsDriverInterface::initialize
File
-
vendor/
composer/ composer/ src/ Composer/ Repository/ Vcs/ GitDriver.php, line 41
Class
- GitDriver
- @author Jordi Boggiano <j.boggiano@seld.be>
Namespace
Composer\Repository\VcsCode
public function initialize() : void {
if (Filesystem::isLocalPath($this->url)) {
$this->url = Preg::replace('{[\\/]\\.git/?$}', '', $this->url);
if (!is_dir($this->url)) {
throw new \RuntimeException('Failed to read package information from ' . $this->url . ' as the path does not exist');
}
$this->repoDir = $this->url;
$cacheUrl = realpath($this->url);
}
else {
if (!Cache::isUsable($this->config
->get('cache-vcs-dir'))) {
throw new \RuntimeException('GitDriver requires a usable cache directory, and it looks like you set it to be disabled');
}
$this->repoDir = $this->config
->get('cache-vcs-dir') . '/' . Preg::replace('{[^a-z0-9.]}i', '-', Url::sanitize($this->url)) . '/';
GitUtil::cleanEnv();
$fs = new Filesystem();
$fs->ensureDirectoryExists(dirname($this->repoDir));
if (!is_writable(dirname($this->repoDir))) {
throw new \RuntimeException('Can not clone ' . $this->url . ' to access package information. The "' . dirname($this->repoDir) . '" directory is not writable by the current user.');
}
if (Preg::isMatch('{^ssh://[^@]+@[^:]+:[^0-9]+}', $this->url)) {
throw new \InvalidArgumentException('The source URL ' . $this->url . ' is invalid, ssh URLs should have a port number after ":".' . "\n" . 'Use ssh://git@example.com:22/path or just git@example.com:path if you do not want to provide a password or custom port.');
}
$gitUtil = new GitUtil($this->io, $this->config, $this->process, $fs);
if (!$gitUtil->syncMirror($this->url, $this->repoDir)) {
if (!is_dir($this->repoDir)) {
throw new \RuntimeException('Failed to clone ' . $this->url . ' to read package information from it');
}
$this->io
->writeError('<error>Failed to update ' . $this->url . ', package information from this repository may be outdated</error>');
}
$cacheUrl = $this->url;
}
$this->getTags();
$this->getBranches();
$this->cache = new Cache($this->io, $this->config
->get('cache-repo-dir') . '/' . Preg::replace('{[^a-z0-9.]}i', '-', Url::sanitize($cacheUrl)));
$this->cache
->setReadOnly($this->config
->get('cache-read-only'));
}