diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index ea8a21162e..7c08865607 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -1078,17 +1078,17 @@ class GitHubGitDownloadStrategy < GitDownloadStrategy sig { returns(String) } def default_refspec - default_branch.yield_self do |branch| - if branch - "+refs/heads/#{branch}:refs/remotes/origin/#{branch}" - else - super - end + if default_branch + "+refs/heads/#{default_branch}:refs/remotes/origin/#{default_branch}" + else + super end end sig { returns(String) } def default_branch + return @default_branch if defined?(@default_branch) + command! "git", args: ["remote", "set-head", "origin", "--auto"], chdir: cached_location @@ -1097,7 +1097,7 @@ class GitHubGitDownloadStrategy < GitDownloadStrategy args: ["symbolic-ref", "refs/remotes/origin/HEAD"], chdir: cached_location - result.stdout[%r{^refs/remotes/origin/(.*)$}, 1] + @default_branch = result.stdout[%r{^refs/remotes/origin/(.*)$}, 1] end end