1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 16:42:57 +00:00

Only fetch remote default branch for mirrored git repos, not local ones, refs #10949 (#10996)

This commit is contained in:
Jordi Boggiano 2022-08-16 16:53:57 +03:00 committed by GitHub
parent 82e3059c6e
commit cc33db9257
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 8 deletions

View file

@ -95,12 +95,14 @@ class GitDriver extends VcsDriver
$this->rootIdentifier = 'master'; $this->rootIdentifier = 'master';
$gitUtil = new GitUtil($this->io, $this->config, $this->process, new Filesystem()); $gitUtil = new GitUtil($this->io, $this->config, $this->process, new Filesystem());
$defaultBranch = $gitUtil->getMirrorDefaultBranch($this->url, $this->repoDir, Filesystem::isLocalPath($this->url)); if (!Filesystem::isLocalPath($this->url)) {
if ($defaultBranch !== null) { $defaultBranch = $gitUtil->getMirrorDefaultBranch($this->url, $this->repoDir, false);
return $this->rootIdentifier = $defaultBranch; if ($defaultBranch !== null) {
return $this->rootIdentifier = $defaultBranch;
}
} }
// select currently checked out branch if master is not available // select currently checked out branch as default branch
$this->process->execute('git branch --no-color', $output, $this->repoDir); $this->process->execute('git branch --no-color', $output, $this->repoDir);
$branches = $this->process->splitLines($output); $branches = $this->process->splitLines($output);
if (!in_array('* master', $branches)) { if (!in_array('* master', $branches)) {

View file

@ -63,12 +63,9 @@ GIT;
$process $process
->expects([[ ->expects([[
'cmd' => 'git remote show origin',
'stdout' => $stdoutFailure,
], [
'cmd' => 'git branch --no-color', 'cmd' => 'git branch --no-color',
'stdout' => $stdout, 'stdout' => $stdout,
]]); ]], true);
$this->assertSame('main', $driver->getRootIdentifier()); $this->assertSame('main', $driver->getRootIdentifier());
} }