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.
This commit is contained in:
Sam Ford 2022-10-17 13:06:52 -04:00
parent 1a8f9ac700
commit 942f419a48
No known key found for this signature in database
GPG Key ID: 7AF5CBEE1DD6F76D

View File

@ -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