From cfa73266209977d0e3658659994d60bd17790b44 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 Aug 2025 17:10:44 +0100 Subject: [PATCH] Improve error message for local formula file installation attempts Co-authored-by: MikeMcQuaid <125011+MikeMcQuaid@users.noreply.github.com> --- Library/Homebrew/formulary.rb | 20 +++++++++++++++++--- Library/Homebrew/test/formulary_spec.rb | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index e73fb9e89f..cce0a28d51 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -616,9 +616,23 @@ module Formulary return unless path.expand_path.exist? - return if Homebrew::EnvConfig.forbid_packages_from_paths? && - !path.realpath.to_s.start_with?("#{HOMEBREW_CELLAR}/", "#{HOMEBREW_LIBRARY}/Taps/", - "#{HOMEBREW_CACHE}/") + if Homebrew::EnvConfig.forbid_packages_from_paths? + path_realpath = path.realpath.to_s + unless path_realpath.start_with?("#{HOMEBREW_CELLAR}/", "#{HOMEBREW_LIBRARY}/Taps/", + "#{HOMEBREW_CACHE}/") + raise <<~WARNING if path_realpath.include?("/") || path_realpath.end_with?(".rb") + Rejecting formula at #{path_realpath} because it's not in a tap. + Homebrew requires formulae to be in a tap. + + To create a tap, run e.g. + brew tap-new / + To create a formula in a tap run e.g. + brew create --tap=/ + WARNING + + return + end + end if (tap = Tap.from_path(path)) # Only treat symlinks in taps as aliases. diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 0bf3c933ef..d2be99e619 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -126,7 +126,7 @@ RSpec.describe Formulary do described_class.factory(temp_formula_path) ensure temp_formula_path.unlink - end.to raise_error(FormulaUnavailableError) + end.to raise_error(RuntimeError, /Rejecting formula at/) end it "returns a Formula when given a URL", :needs_utils_curl do