Merge pull request #20475 from Homebrew/better_formulary_debugging

formulary: provide ref and realpath when rejecting path.
This commit is contained in:
Mike McQuaid 2025-08-15 18:08:28 +00:00 committed by GitHub
commit 523d743705
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 4 deletions

View File

@ -619,12 +619,13 @@ module Formulary
if Homebrew::EnvConfig.forbid_packages_from_paths?
path_realpath = path.realpath.to_s
path_string = path.to_s
if !path_realpath.start_with?("#{HOMEBREW_CELLAR}/", "#{HOMEBREW_LIBRARY}/Taps/", "#{HOMEBREW_CACHE}/") &&
if (path_realpath.end_with?(".rb") || path_string.end_with?(".rb")) &&
!path_realpath.start_with?("#{HOMEBREW_CELLAR}/", "#{HOMEBREW_LIBRARY}/Taps/", "#{HOMEBREW_CACHE}/") &&
!path_string.start_with?("#{HOMEBREW_CELLAR}/", "#{HOMEBREW_LIBRARY}/Taps/", "#{HOMEBREW_CACHE}/")
if path_string.include?("./") || path_string.end_with?(".rb") || path_string.count("/") != 2
raise <<~WARNING
Rejecting formula at #{path_string} because it's not in a tap.
Homebrew requires formulae to be in a tap.
Homebrew requires formulae to be in a tap, rejecting:
#{path_string} (#{path_realpath})
To create a tap, run e.g.
brew tap-new <user|org>/<repository>

View File

@ -126,7 +126,7 @@ RSpec.describe Formulary do
described_class.factory(temp_formula_path)
ensure
temp_formula_path.unlink
end.to raise_error(RuntimeError, /Rejecting formula at/)
end.to raise_error(RuntimeError, /requires formulae to be in a tap, rejecting/)
end
it "returns a Formula when given a URL", :needs_utils_curl do