Skip to content

Commit

Permalink
Add allowlist, make branch: mandatory
Browse files Browse the repository at this point in the history
  • Loading branch information
nandahkrishna committed Aug 12, 2021
1 parent d753200 commit f69f9be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
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
13 changes: 6 additions & 7 deletions Library/Homebrew/resource_auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,17 @@ def audit_urls
end

def audit_head_branch
return if !@online || !@strict || spec_name != :head || !Utils::Git.remote_exists?(url)
return unless @online
return unless @strict
return unless 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 == "master" && specs[:branch].blank? || branch == specs[:branch]
return if branch == specs[:branch]

if branch == "master"
problem "Remove `branch: \"#{specs[:branch]}\"`"
else
problem "Use `branch: \"#{branch}\"` to specify the correct default branch"
end
problem "Use `branch: \"#{branch}\"` to specify the default branch"
end

def problem(text)
Expand Down

0 comments on commit f69f9be

Please sign in to comment.