From cc33db92577f365c86b0c088b93323805f2ad964 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 16 Aug 2022 16:53:57 +0300 Subject: [PATCH] Only fetch remote default branch for mirrored git repos, not local ones, refs #10949 (#10996) --- src/Composer/Repository/Vcs/GitDriver.php | 10 ++++++---- tests/Composer/Test/Repository/Vcs/GitDriverTest.php | 5 +---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Composer/Repository/Vcs/GitDriver.php b/src/Composer/Repository/Vcs/GitDriver.php index 66650ce7b..731c5bde0 100644 --- a/src/Composer/Repository/Vcs/GitDriver.php +++ b/src/Composer/Repository/Vcs/GitDriver.php @@ -95,12 +95,14 @@ class GitDriver extends VcsDriver $this->rootIdentifier = 'master'; $gitUtil = new GitUtil($this->io, $this->config, $this->process, new Filesystem()); - $defaultBranch = $gitUtil->getMirrorDefaultBranch($this->url, $this->repoDir, Filesystem::isLocalPath($this->url)); - if ($defaultBranch !== null) { - return $this->rootIdentifier = $defaultBranch; + 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 if master is not available + // 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)) { diff --git a/tests/Composer/Test/Repository/Vcs/GitDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitDriverTest.php index d40366158..229ef130d 100644 --- a/tests/Composer/Test/Repository/Vcs/GitDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitDriverTest.php @@ -63,12 +63,9 @@ GIT; $process ->expects([[ - 'cmd' => 'git remote show origin', - 'stdout' => $stdoutFailure, - ], [ 'cmd' => 'git branch --no-color', 'stdout' => $stdout, - ]]); + ]], true); $this->assertSame('main', $driver->getRootIdentifier()); }