diff --git a/Library/Homebrew/formula_auditor.rb b/Library/Homebrew/formula_auditor.rb index 835f6beeff..9a1eb5def5 100644 --- a/Library/Homebrew/formula_auditor.rb +++ b/Library/Homebrew/formula_auditor.rb @@ -523,9 +523,15 @@ module Homebrew spec_name = name.downcase.to_sym next unless (spec = formula.send(spec_name)) + except = @except.to_a + if spec_name == :head && + tap_audit_exception(:head_non_default_branch_allowlist, formula.name, spec.specs[:branch]) + except << "head_branch" + end + ra = ResourceAuditor.new( spec, spec_name, - online: @online, strict: @strict, only: @only, except: @except + online: @online, strict: @strict, only: @only, except: except ).audit ra.problems.each do |message| problem "#{name}: #{message}" diff --git a/Library/Homebrew/resource_auditor.rb b/Library/Homebrew/resource_auditor.rb index a8b54ee80c..39c348a7ea 100644 --- a/Library/Homebrew/resource_auditor.rb +++ b/Library/Homebrew/resource_auditor.rb @@ -124,6 +124,20 @@ module Homebrew end end + def audit_head_branch + return unless @online + return unless @strict + return if spec_name != :head + return unless Utils::Git.remote_exists?(url) + + branch = Utils.popen_read("git", "ls-remote", "--symref", url, "HEAD") + .match(%r{ref: refs/heads/(.*?)\s+HEAD})[1] + + return if branch == specs[:branch] + + problem "Use `branch: \"#{branch}\"` to specify the default branch" + end + def problem(text) @problems << text end