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

Breadcrumb

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

function GitDriver::getRootIdentifier

@inheritDoc

Overrides VcsDriverInterface::getRootIdentifier

File

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

Class

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

Namespace

Composer\Repository\Vcs

Code

public function getRootIdentifier() : string {
    if (null === $this->rootIdentifier) {
        $this->rootIdentifier = 'master';
        $gitUtil = new GitUtil($this->io, $this->config, $this->process, new Filesystem());
        if (!Filesystem::isLocalPath($this->url)) {
            $defaultBranch = $gitUtil->getMirrorDefaultBranch($this->url, $this->repoDir, false);
            if ($defaultBranch !== null) {
                return $this->rootIdentifier = $defaultBranch;
            }
        }
        // select currently checked out branch as default branch
        $this->process
            ->execute([
            'git',
            'branch',
            '--no-color',
        ], $output, $this->repoDir);
        $branches = $this->process
            ->splitLines($output);
        if (!in_array('* master', $branches)) {
            foreach ($branches as $branch) {
                if ($branch && Preg::isMatchStrictGroups('{^\\* +(\\S+)}', $branch, $match)) {
                    $this->rootIdentifier = $match[1];
                    break;
                }
            }
        }
    }
    return $this->rootIdentifier;
}
RSS feed
Powered by Drupal