Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource_auditor: add audit for HEAD default branch #11720

Merged
merged 3 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion Library/Homebrew/formula_auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,15 @@ def audit_specs
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}"
Expand Down
14 changes: 14 additions & 0 deletions Library/Homebrew/resource_auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ def audit_urls
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
Expand Down