From d0e438c5fafc3e8d11e94f1912d77ef91fa7257a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lach?= Date: Sun, 3 Nov 2024 13:29:47 +0100 Subject: [PATCH 1/2] Downcase internal commands Since APFS is case-insensitive by default, Ruby will load the command file if user passes it mixed-case, but invoking it later will fail. --- Library/Homebrew/brew.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index dbe7acc2105c8..8a68f37df6d34 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -83,7 +83,10 @@ end if internal_cmd || Commands.external_ruby_v2_cmd_path(cmd) - cmd = T.must(cmd) + # All internal commands are downcased + # Since APFS is case-insensitive by default, Ruby will load the command file + # if user passes it mixed-case, but here invoking it will fail. + cmd = T.must(cmd).downcase cmd_class = Homebrew::AbstractCommand.command(cmd) Homebrew.running_command = cmd if cmd_class From 9fd678cc588f701350777a1395d82cadb590f98f Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Mon, 4 Nov 2024 08:51:05 +0000 Subject: [PATCH 2/2] brew.rb: improve error message for miscased commands. --- Library/Homebrew/brew.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 8a68f37df6d34..679abea0d245d 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -83,10 +83,7 @@ end if internal_cmd || Commands.external_ruby_v2_cmd_path(cmd) - # All internal commands are downcased - # Since APFS is case-insensitive by default, Ruby will load the command file - # if user passes it mixed-case, but here invoking it will fail. - cmd = T.must(cmd).downcase + cmd = T.must(cmd) cmd_class = Homebrew::AbstractCommand.command(cmd) Homebrew.running_command = cmd if cmd_class @@ -96,7 +93,14 @@ Utils::Analytics.report_command_run(command_instance) command_instance.run else - Homebrew.public_send Commands.method_name(cmd) + begin + Homebrew.public_send Commands.method_name(cmd) + rescue NoMethodError => e + case_error = "undefined method `#{cmd.downcase}' for module Homebrew" + odie "Unknown command: brew #{cmd}" if e.message == case_error + + raise + end end elsif (path = Commands.external_ruby_cmd_path(cmd)) Homebrew.running_command = cmd