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

Breadcrumb

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

function Git::getMirrorDefaultBranch

File

vendor/composer/composer/src/Composer/Util/Git.php, line 501

Class

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

Namespace

Composer\Util

Code

public function getMirrorDefaultBranch(string $url, string $dir, bool $isLocalPathRepository) : ?string {
    if ((bool) Platform::getEnv('COMPOSER_DISABLE_NETWORK')) {
        return null;
    }
    try {
        if ($isLocalPathRepository) {
            $this->process
                ->execute([
                'git',
                'remote',
                'show',
                'origin',
            ], $output, $dir);
        }
        else {
            $commands = [
                [
                    'git',
                    'remote',
                    'set-url',
                    'origin',
                    '--',
                    '%url%',
                ],
                [
                    'git',
                    'remote',
                    'show',
                    'origin',
                ],
                [
                    'git',
                    'remote',
                    'set-url',
                    'origin',
                    '--',
                    '%sanitizedUrl%',
                ],
            ];
            $this->runCommands($commands, $url, $dir, false, $output);
        }
        $lines = $this->process
            ->splitLines($output);
        foreach ($lines as $line) {
            if (Preg::isMatch('{^\\s*HEAD branch:\\s(.+)\\s*$}m', $line, $matches)) {
                return $matches[1];
            }
        }
    } catch (\Exception $e) {
        $this->io
            ->writeError('<error>Failed to fetch root identifier from remote: ' . $e->getMessage() . '</error>', true, IOInterface::DEBUG);
    }
    return null;
}

API Navigation

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