Skip to content

Commit

Permalink
Only treat symlinks in taps as alias paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Feb 22, 2024
1 parent e0743a1 commit 964f005
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions Library/Homebrew/formulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -599,28 +599,42 @@ def self.try_new(ref, from: T.unsafe(nil), warn: false)

return unless path.expand_path.exist?

options = if path.symlink?
alias_path = path
path = alias_path.resolved_path
{ alias_path: alias_path }
options = if (tap = Tap.from_path(path))
# Only treat symlinks in taps as aliases.
if path.symlink?
alias_path = path
path = alias_path.resolved_path

{
alias_path: alias_path,
tap: tap,
}
else
{
tap: tap,
}
end
elsif (tap = Homebrew::API.tap_from_source_download(path))
# Don't treat cache symlinks as aliases.
{
tap: tap,
}
else
{}
end
end

return if path.extname != ".rb"

new(path, **options)
end
end

sig { params(path: T.any(Pathname, String), alias_path: Pathname).void }
def initialize(path, alias_path: T.unsafe(nil))
sig { params(path: T.any(Pathname, String), alias_path: Pathname, tap: Tap).void }
def initialize(path, alias_path: T.unsafe(nil), tap: T.unsafe(nil))
path = Pathname(path).expand_path
name = path.basename(".rb").to_s
alias_path = alias_path&.expand_path
alias_dir = alias_path&.dirname

tap = Tap.from_path(path) || Homebrew::API.tap_from_source_download(path)

options = {
alias_path: (alias_path if alias_dir == tap&.alias_dir),
tap: tap,
Expand Down

0 comments on commit 964f005

Please sign in to comment.