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

Breadcrumb

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

function GitDownloader::doInstall

@inheritDoc

Overrides VcsDownloader::doInstall

File

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

Class

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

Namespace

Composer\Downloader

Code

protected function doInstall(PackageInterface $package, string $path, string $url) : PromiseInterface {
    GitUtil::cleanEnv();
    $path = $this->normalizePath($path);
    $cachePath = $this->config
        ->get('cache-vcs-dir') . '/' . Preg::replace('{[^a-z0-9.]}i', '-', Url::sanitize($url)) . '/';
    $ref = $package->getSourceReference();
    if (!empty($this->cachedPackages[$package->getId()][$ref])) {
        $msg = "Cloning " . $this->getShortHash($ref) . ' from cache';
        $cloneFlags = [
            '--dissociate',
            '--reference',
            $cachePath,
        ];
        $transportOptions = $package->getTransportOptions();
        if (isset($transportOptions['git']['single_use_clone']) && $transportOptions['git']['single_use_clone']) {
            $cloneFlags = [];
        }
        $commands = [
            array_merge([
                'git',
                'clone',
                '--no-checkout',
                $cachePath,
                $path,
            ], $cloneFlags),
            [
                'git',
                'remote',
                'set-url',
                'origin',
                '--',
                '%sanitizedUrl%',
            ],
            [
                'git',
                'remote',
                'add',
                'composer',
                '--',
                '%sanitizedUrl%',
            ],
        ];
    }
    else {
        $msg = "Cloning " . $this->getShortHash($ref);
        $commands = [
            array_merge([
                'git',
                'clone',
                '--no-checkout',
                '--',
                '%url%',
                $path,
            ]),
            [
                'git',
                'remote',
                'add',
                'composer',
                '--',
                '%url%',
            ],
            [
                'git',
                'fetch',
                'composer',
            ],
            [
                'git',
                'remote',
                'set-url',
                'origin',
                '--',
                '%sanitizedUrl%',
            ],
            [
                'git',
                'remote',
                'set-url',
                'composer',
                '--',
                '%sanitizedUrl%',
            ],
        ];
        if (Platform::getEnv('COMPOSER_DISABLE_NETWORK')) {
            throw new \RuntimeException('The required git reference for ' . $package->getName() . ' is not in cache and network is disabled, aborting');
        }
    }
    $this->io
        ->writeError($msg);
    $this->gitUtil
        ->runCommands($commands, $url, $path, true);
    $sourceUrl = $package->getSourceUrl();
    if ($url !== $sourceUrl && $sourceUrl !== null) {
        $this->updateOriginUrl($path, $sourceUrl);
    }
    else {
        $this->setPushUrl($path, $url);
    }
    if ($newRef = $this->updateToCommit($package, $path, (string) $ref, $package->getPrettyVersion())) {
        if ($package->getDistReference() === $package->getSourceReference()) {
            $package->setDistReference($newRef);
        }
        $package->setSourceReference($newRef);
    }
    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