From 942f419a48426d14a1b49d35f343cbe00a583e71 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Mon, 17 Oct 2022 13:06:52 -0400 Subject: [PATCH] ResourceAuditor: Fix #audit_head_branch error The existing logic in `#audit_head_branch` for identifying the `HEAD` branch in a Git repository will give an ```undefined method `[]' for nil:NilClass``` error when a repository doesn't provide this reference. Expected output is as follows: ``` ref: refs/heads/master HEAD 1a8f9ac700873d1a08de31a17a2fd654245d5085 HEAD ``` However, I encountered this error for a repository with the following output (i.e., where no symref is provided for HEAD): ``` f86be659718c0cd0a67f88b42f07044c23d0d028 HEAD ``` This commit resolves the error by modifying the related logic to account for a `nil` value. --- Library/Homebrew/resource_auditor.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/resource_auditor.rb b/Library/Homebrew/resource_auditor.rb index 624f2b8e07..ac51bb0cd9 100644 --- a/Library/Homebrew/resource_auditor.rb +++ b/Library/Homebrew/resource_auditor.rb @@ -146,9 +146,8 @@ module Homebrew return if specs[:tag].present? branch = Utils.popen_read("git", "ls-remote", "--symref", url, "HEAD") - .match(%r{ref: refs/heads/(.*?)\s+HEAD})[1] - - return if branch == specs[:branch] + .match(%r{ref: refs/heads/(.*?)\s+HEAD})&.to_a&.second + return if branch.blank? || branch == specs[:branch] problem "Use `branch: \"#{branch}\"` to specify the default branch" end