dev-cmd/edit: suggest tapping core repositories if untapped#15740
dev-cmd/edit: suggest tapping core repositories if untapped#15740MikeMcQuaid merged 1 commit intoHomebrew:masterfrom
Conversation
6521a59 to
56a6562
Compare
8cd4b31 to
2e77267
Compare
78172b6 to
1306ac4
Compare
| 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.
Fixes an issue where args in the form "user/repo/name" wouldn't be handled properly.
| 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.
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.
File::FNM_DOTMATCH allows relative path arguments to be handled correctly.
There was a problem hiding this comment.
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.
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.
**/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
Library/Homebrew/formulary.rb
Outdated
|
|
||
| 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.
Fixes an issue where ".rb" would be unnecessarily added to a path argument that had it already.
There was a problem hiding this comment.
| filename = "#{name}#{".rb" unless name.end_with?(".rb")}" | |
| filename = name | |
| filename << ".rb" unless filename.end_with?(".rb") |
There was a problem hiding this comment.
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.
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.
Identifying the tap from a path seems like something we can extract to a method somewhere.
There was a problem hiding this comment.
Any location in particular?
1306ac4 to
b3ecd91
Compare
MikeMcQuaid
left a comment
There was a problem hiding this comment.
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 stylewith your changes locally?brew typecheckwith your changes locally?brew testswith 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.