resource_auditor: add audit for HEAD default branch

This commit is contained in:
Nanda H Krishna 2021-07-14 23:23:08 +05:30
parent cd900ef71e
commit d75320069f
No known key found for this signature in database
GPG Key ID: 067E5FCD58ADF3AA

View File

@ -124,6 +124,21 @@ module Homebrew
end
end
def audit_head_branch
return if !@online || !@strict || spec_name != :head || !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]
if branch == "master"
problem "Remove `branch: \"#{specs[:branch]}\"`"
else
problem "Use `branch: \"#{branch}\"` to specify the correct default branch"
end
end
def problem(text)
@problems << text
end