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()); }