From d75320069f37d757030c8e55d219fadd2107f8ba Mon Sep 17 00:00:00 2001 From: Nanda H Krishna Date: Wed, 14 Jul 2021 23:23:08 +0530 Subject: [PATCH] resource_auditor: add audit for HEAD default branch --- Library/Homebrew/resource_auditor.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Library/Homebrew/resource_auditor.rb b/Library/Homebrew/resource_auditor.rb index a8b54ee80c..f40af7ce9b 100644 --- a/Library/Homebrew/resource_auditor.rb +++ b/Library/Homebrew/resource_auditor.rb @@ -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