-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Fix support of formulae aliases in taps #16637
Fix support of formulae aliases in taps #16637
Conversation
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.
In general, this fix looks correct. Thanks for taking the initiative to open a PR. However the regex should not get moved as mentioned in my comments.
38f3ea7
to
d01de75
Compare
Library/Homebrew/formulary.rb
Outdated
@@ -949,6 +950,7 @@ def self.tap_loader_for(tapped_name, warn:) | |||
end | |||
end | |||
|
|||
name = name.split("/").last if name != :nil && type == :alias |
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.
As mentioned in #16623 (comment), this is the exact same fix. Can you move the split
into the conditional above to avoid checking another condition here?
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.
Yeah, sorry, your suggestion is simpler than what I proposed earlier. Using String#split
should avoid the nil type errors entirely too.
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.
@apainintheneck I'm not sure who is targeted by @reitermarkus's wish to move the split
- shall I do it?
And if yes; I'm not sure where exactly to move it to?
So like this?
diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb
index 9a1a7cc2c..cabc1f74a 100644
--- a/Library/Homebrew/formulary.rb
+++ b/Library/Homebrew/formulary.rb
@@ -909,7 +909,7 @@ module Formulary
alias_name = tap.core_tap? ? name : "#{tap}/#{name}"
if (possible_alias = tap.alias_table[alias_name].presence)
- name = possible_alias
+ name = tap.core_tap? ? possible_alias : possible_alias.split("/").last
type = :alias
elsif (new_name = tap.formula_renames[name].presence)
old_name = name
@@ -950,7 +950,6 @@ module Formulary
end
end
- name = name.split("/").last if name != :nil && type == :alias
path = find_formula_in_tap(name, tap)
TapLoader.new(name, path, tap: tap)
end
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.
Or like this?
diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb
index 9a1a7cc2c..952ee50fd 100644
--- a/Library/Homebrew/formulary.rb
+++ b/Library/Homebrew/formulary.rb
@@ -948,9 +948,10 @@ module Formulary
elsif Homebrew::API::Formula.all_formulae.key?(name)
return FormulaAPILoader.new(name)
end
+ elsif name != :nil && type == :alias
+ name = name.split("/").last
end
- name = name.split("/").last if name != :nil && type == :alias
path = find_formula_in_tap(name, tap)
TapLoader.new(name, path, tap: tap)
end
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.
The latter seems to be error-prone … eg. when tap.core_tap? && !Homebrew::EnvConfig.no_install_from_api?
is true
and the API-lookup Homebrew::API::Formula.all_formulae.key?(name)
is false
.
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.
@apainintheneck I'm not sure who is targeted by @reitermarkus's wish to move the
split
- shall I do it? And if yes; I'm not sure where exactly to move it to?So like this?
diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 9a1a7cc2c..cabc1f74a 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -909,7 +909,7 @@ module Formulary alias_name = tap.core_tap? ? name : "#{tap}/#{name}" if (possible_alias = tap.alias_table[alias_name].presence) - name = possible_alias + name = tap.core_tap? ? possible_alias : possible_alias.split("/").last type = :alias elsif (new_name = tap.formula_renames[name].presence) old_name = name @@ -950,7 +950,6 @@ module Formulary end end - name = name.split("/").last if name != :nil && type == :alias path = find_formula_in_tap(name, tap) TapLoader.new(name, path, tap: tap) end
This is pretty much what I was thinking. I'll update it now and test it locally to make sure it works.
I'm also not sure why this test didn't catch this problem. brew/Library/Homebrew/test/formulary_spec.rb Lines 239 to 244 in 88b5e50
|
… I think because the spec just asks for |
That's exactly it. I added a regression test that checks for that and it fails on the master branch and works on this one. |
It seems to work now. |
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 for adding the test here, @apainintheneck! |
Thanks for this @sjorek and for the review and merge @apainintheneck and @reitermarkus! |
Resolves: #16636
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?