1
0
Fork 0

Avoid blocking when guessing default branch name, fixes #9001

pull/9008/head
Jordi Boggiano 2020-06-22 10:48:15 +02:00
parent 09d7acee3c
commit e76fc2dc39
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 13 additions and 4 deletions

View File

@ -20,6 +20,7 @@ use Composer\Util\Git as GitUtil;
use Composer\Util\HttpDownloader; use Composer\Util\HttpDownloader;
use Composer\Util\ProcessExecutor; use Composer\Util\ProcessExecutor;
use Composer\Util\Svn as SvnUtil; use Composer\Util\Svn as SvnUtil;
use Composer\Util\Platform;
use Composer\Package\Version\VersionParser; use Composer\Package\Version\VersionParser;
@ -117,9 +118,17 @@ class VersionGuesser
*/ */
public function getDefaultBranchName($path) public function getDefaultBranchName($path)
{ {
if (version_compare(GitUtil::getVersion($this->process), '2.3.0-rc0', '>=')) {
GitUtil::cleanEnv(); GitUtil::cleanEnv();
if (0 === $this->process->execute('git remote show origin', $output, $path) || 0 === $this->process->execute('git remote show upstream', $output, $path)) { $oldVal = getenv('GIT_SSH_COMMAND');
if (preg_match('{^ HEAD branch: (.+)$}m', $output, $match)) { putenv("GIT_SSH_COMMAND=ssh".(Platform::isWindows() ? '.exe' : '')." -o StrictHostKeyChecking=yes");
$hasGitRemote = 0 === $this->process->execute('git remote show origin', $output, $path);
if ($oldVal) {
putenv("GIT_SSH_COMMAND=$oldVal");
} else {
putenv("GIT_SSH_COMMAND");
}
if ($hasGitRemote && preg_match('{^ HEAD branch: (.+)$}m', $output, $match)) {
return trim($match[1]); return trim($match[1]);
} }
} }
@ -287,7 +296,7 @@ class VersionGuesser
foreach ($branches as $candidate) { foreach ($branches as $candidate) {
// do not compare against itself or other feature branches // do not compare against itself or other feature branches
if ($candidate === $branch || !preg_match('{^(' . $nonFeatureBranches . ($defaultBranch ? '|'.preg_quote($defaultBranch) : '').'|master|trunk|default|develop|\d+\..+)$}', $candidate, $match)) { if ($candidate === $branch || !preg_match('{^(' . $nonFeatureBranches . ($defaultBranch ? '|'.preg_quote($defaultBranch) : '').'|master|main|latest|next|current|support|tip|trunk|default|develop|\d+\..+)$}', $candidate, $match)) {
continue; continue;
} }