-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dev-cmd/edit: suggest tapping core repositories if untapped #15740
Conversation
6521a59
to
56a6562
Compare
8cd4b31
to
2e77267
Compare
78172b6
to
1306ac4
Compare
@@ -244,7 +244,7 @@ def self.can_load?(ref) | |||
|
|||
def initialize(token, from_json: nil) | |||
@token = token.sub(%r{^homebrew/(?:homebrew-)?cask/}i, "") | |||
@path = CaskLoader.default_path(token) | |||
@path = CaskLoader.default_path(@token) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes an issue where args in the form "user/repo/name" wouldn't be handled properly.
@@ -24,7 +24,7 @@ def edit_args | |||
|
|||
conflicts "--formula", "--cask" | |||
|
|||
named_args [:formula, :cask], without_api: true | |||
named_args [:formula, :cask, :tap], without_api: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This command hasn't advertised that it handles tap arguments too, until now.
Library/Homebrew/dev-cmd/edit.rb
Outdated
args.named.to_paths.select do |path| | ||
next path if path.exist? | ||
core_formula_path = path.fnmatch?("**/homebrew-core/Formula/*.rb", File::FNM_DOTMATCH) | ||
core_cask_path = path.fnmatch?("**/homebrew-cask/Casks/*.rb", File::FNM_DOTMATCH) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File::FNM_DOTMATCH
allows relative path arguments to be handled correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should modify this so it can handle sharded Formula/Cask directories.
Also, I wonder if it would be simpler/more robust to use #realpath
/#ascend
and/or GitRepository
to find the repository root instead of with #fnmatch?
, as this seems a bit fragile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should modify this so it can handle sharded Formula/Cask directories.
Agreed. Formula/**/*.rb
should cover it. Ideally some of this logic would be in the Tap
class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**/homebrew-core/Formula/**.rb
is what you want.
brew(main):020:0> Pathname("/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks/firefox.rb").fnmatch?("**/homebrew-cask/Casks/**.rb", File::FNM_DOTMATCH)
=> true
brew(main):021:0> Pathname("/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks/f/firefox.rb").fnmatch?("**/homebrew-cask/Casks/**.rb", File::FNM_DOTMATCH)
=> true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, thanks.
Library/Homebrew/formulary.rb
Outdated
@@ -1004,7 +1004,7 @@ def self.tap_paths(name, taps = Tap) | |||
end | |||
|
|||
def self.find_formula_in_tap(name, tap) | |||
filename = "#{name}.rb" | |||
filename = "#{name}#{".rb" unless name.end_with?(".rb")}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes an issue where ".rb" would be unnecessarily added to a path argument that had it already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filename = "#{name}#{".rb" unless name.end_with?(".rb")}" | |
filename = name | |
filename << ".rb" unless filename.end_with?(".rb") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to use name.dup
otherwise tests like brew audit --skip-style --except=version openssl@3
would fail.
Library/Homebrew/dev-cmd/edit.rb
Outdated
args.named.to_paths.select do |path| | ||
next path if path.exist? | ||
core_formula_path = path.fnmatch?("**/homebrew-core/Formula/*.rb", File::FNM_DOTMATCH) | ||
core_cask_path = path.fnmatch?("**/homebrew-cask/Casks/*.rb", File::FNM_DOTMATCH) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should modify this so it can handle sharded Formula/Cask directories.
Also, I wonder if it would be simpler/more robust to use #realpath
/#ascend
and/or GitRepository
to find the repository root instead of with #fnmatch?
, as this seems a bit fragile.
EOS | ||
name = path.basename(".rb").to_s | ||
|
||
if (tap_match = Regexp.new(HOMEBREW_TAP_DIR_REGEX.source + /$/.source).match(path.to_s)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identifying the tap from a path seems like something we can extract to a method somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any location in particular?
1306ac4
to
b3ecd91
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @EricFromCanada! Has been a lot of back and forth and this looks much better so would suggest any remaining/following comments get addressed in a follow-up PR.
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?Addresses the issue brought up in #15664 by suggesting homebrew/core or homebrew/cask be tapped when attempting to edit a formula or cask and either repo is untapped. Also expands
edit
's handling of tap arguments and fixes a few other related bugs.