Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. GitDownloader.php

function GitDownloader::doUpdate

@inheritDoc

Overrides VcsDownloader::doUpdate

File

vendor/composer/composer/src/Composer/Downloader/GitDownloader.php, line 150

Class

GitDownloader
@author Jordi Boggiano <j.boggiano@seld.be>

Namespace

Composer\Downloader

Code

protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url) : PromiseInterface {
    GitUtil::cleanEnv();
    $path = $this->normalizePath($path);
    if (!$this->hasMetadataRepository($path)) {
        throw new \RuntimeException('The .git directory is missing from ' . $path . ', see https://getcomposer.org/commit-deps for more information');
    }
    $cachePath = $this->config
        ->get('cache-vcs-dir') . '/' . Preg::replace('{[^a-z0-9.]}i', '-', Url::sanitize($url)) . '/';
    $ref = $target->getSourceReference();
    if (!empty($this->cachedPackages[$target->getId()][$ref])) {
        $msg = "Checking out " . $this->getShortHash($ref) . ' from cache';
        $remoteUrl = $cachePath;
    }
    else {
        $msg = "Checking out " . $this->getShortHash($ref);
        $remoteUrl = '%url%';
        if (Platform::getEnv('COMPOSER_DISABLE_NETWORK')) {
            throw new \RuntimeException('The required git reference for ' . $target->getName() . ' is not in cache and network is disabled, aborting');
        }
    }
    $this->io
        ->writeError($msg);
    if (0 !== $this->process
        ->execute([
        'git',
        'rev-parse',
        '--quiet',
        '--verify',
        $ref . '^{commit}',
    ], $output, $path)) {
        $commands = [
            [
                'git',
                'remote',
                'set-url',
                'composer',
                '--',
                $remoteUrl,
            ],
            [
                'git',
                'fetch',
                'composer',
            ],
            [
                'git',
                'fetch',
                '--tags',
                'composer',
            ],
        ];
        $this->gitUtil
            ->runCommands($commands, $url, $path);
    }
    $command = [
        'git',
        'remote',
        'set-url',
        'composer',
        '--',
        '%sanitizedUrl%',
    ];
    $this->gitUtil
        ->runCommands([
        $command,
    ], $url, $path);
    if ($newRef = $this->updateToCommit($target, $path, (string) $ref, $target->getPrettyVersion())) {
        if ($target->getDistReference() === $target->getSourceReference()) {
            $target->setDistReference($newRef);
        }
        $target->setSourceReference($newRef);
    }
    $updateOriginUrl = false;
    if (0 === $this->process
        ->execute([
        'git',
        'remote',
        '-v',
    ], $output, $path) && Preg::isMatch('{^origin\\s+(?P<url>\\S+)}m', $output, $originMatch) && Preg::isMatch('{^composer\\s+(?P<url>\\S+)}m', $output, $composerMatch)) {
        if ($originMatch['url'] === $composerMatch['url'] && $composerMatch['url'] !== $target->getSourceUrl()) {
            $updateOriginUrl = true;
        }
    }
    if ($updateOriginUrl && $target->getSourceUrl() !== null) {
        $this->updateOriginUrl($path, $target->getSourceUrl());
    }
    return \React\Promise\resolve(null);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal