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\UtilCode
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;
}