Merge pull request #20583 from Homebrew/encourage-adding-to-head-branch-allowlist

Encourage using a default branch for HEAD core formulae
This commit is contained in:
Issy Long 2025-08-26 13:02:02 +00:00 committed by GitHub
commit fee0e1543f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 7 deletions

View File

@ -763,7 +763,7 @@ module Homebrew
ra = ResourceAuditor.new( ra = ResourceAuditor.new(
spec, spec_name, spec, spec_name,
online: @online, strict: @strict, only: @only, except:, online: @online, strict: @strict, only: @only, core_tap: @core_tap, except:,
use_homebrew_curl: spec.using == :homebrew_curl use_homebrew_curl: spec.using == :homebrew_curl
).audit ).audit
ra.problems.each do |message| ra.problems.each do |message|

View File

@ -24,6 +24,7 @@ module Homebrew
@strict = options[:strict] @strict = options[:strict]
@only = options[:only] @only = options[:only]
@except = options[:except] @except = options[:except]
@core_tap = options[:core_tap]
@use_homebrew_curl = options[:use_homebrew_curl] @use_homebrew_curl = options[:use_homebrew_curl]
@problems = [] @problems = []
end end
@ -190,10 +191,15 @@ module Homebrew
detected_branch = Utils.popen_read("git", "ls-remote", "--symref", url, "HEAD") detected_branch = Utils.popen_read("git", "ls-remote", "--symref", url, "HEAD")
.match(%r{ref: refs/heads/(.*?)\s+HEAD})&.to_a&.second .match(%r{ref: refs/heads/(.*?)\s+HEAD})&.to_a&.second
message = "Git `head` URL must specify a branch name" if specs[:branch].blank?
message += " - try `branch: \"#{detected_branch}\"`" if detected_branch.present? problem "Git `head` URL must specify a branch name"
return
end
problem message if specs[:branch].blank? || detected_branch != specs[:branch] return unless @core_tap
return if specs[:branch] == detected_branch
problem "To use a non-default HEAD branch, add the formula to `head_non_default_branch_allowlist.json`."
end end
def problem(text) def problem(text)

View File

@ -729,7 +729,7 @@ RSpec.describe Homebrew::FormulaAuditor do
end end
it "suggests a detected default branch for Git head URLs" do it "suggests a detected default branch for Git head URLs" do
fa = formula_auditor "foo", <<~RUBY, online: true fa = formula_auditor "foo", <<~RUBY, online: true, core_tap: true
class Foo < Formula class Foo < Formula
url "https://brew.sh/foo-1.0.tgz" url "https://brew.sh/foo-1.0.tgz"
sha256 "31cccfc6630528db1c8e3a06f6decf2a370060b982841cfab2b8677400a5092e" sha256 "31cccfc6630528db1c8e3a06f6decf2a370060b982841cfab2b8677400a5092e"
@ -737,13 +737,13 @@ RSpec.describe Homebrew::FormulaAuditor do
end end
RUBY RUBY
message = "Git `head` URL must specify a branch name - try `branch: \"main\"`" message = "To use a non-default HEAD branch, add the formula to `head_non_default_branch_allowlist.json`."
fa.audit_specs fa.audit_specs
# This is `.last` because the first problem is the unreachable stable URL. # This is `.last` because the first problem is the unreachable stable URL.
expect(fa.problems.last[:message]).to match(message) expect(fa.problems.last[:message]).to match(message)
end end
it "ignores a pre-existing correct HEAD branch name" do it "can specify a default branch without an allowlist if not in a core tap" do
fa = formula_auditor "foo", <<~RUBY, online: true fa = formula_auditor "foo", <<~RUBY, online: true
class Foo < Formula class Foo < Formula
url "https://brew.sh/foo-1.0.tgz" url "https://brew.sh/foo-1.0.tgz"