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

Breadcrumb

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

function GitDriver::supports

@inheritDoc

Overrides VcsDriverInterface::supports

File

vendor/composer/composer/src/Composer/Repository/Vcs/GitDriver.php, line 217

Class

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

Namespace

Composer\Repository\Vcs

Code

public static function supports(IOInterface $io, Config $config, string $url, bool $deep = false) : bool {
    if (Preg::isMatch('#(^git://|\\.git/?$|git(?:olite)?@|//git\\.|//github.com/)#i', $url)) {
        return true;
    }
    // local filesystem
    if (Filesystem::isLocalPath($url)) {
        $url = Filesystem::getPlatformPath($url);
        if (!is_dir($url)) {
            return false;
        }
        $process = new ProcessExecutor($io);
        // check whether there is a git repo in that path
        if ($process->execute([
            'git',
            'tag',
        ], $output, $url) === 0) {
            return true;
        }
        GitUtil::checkForRepoOwnershipError($process->getErrorOutput(), $url);
    }
    if (!$deep) {
        return false;
    }
    $gitUtil = new GitUtil($io, $config, new ProcessExecutor($io), new Filesystem());
    GitUtil::cleanEnv();
    try {
        $gitUtil->runCommands([
            [
                'git',
                'ls-remote',
                '--heads',
                '--',
                '%url%',
            ],
        ], $url, sys_get_temp_dir());
    } catch (\RuntimeException $e) {
        return false;
    }
    return true;
}
RSS feed
Powered by Drupal