Skip to content

Commit

Permalink
Merge pull request #16069 from apainintheneck/handle-name-conflicts-i…
Browse files Browse the repository at this point in the history
…n-to_paths

cli/named_args: better handle name conflicts in #to_paths
  • Loading branch information
MikeMcQuaid authored Oct 2, 2023
2 parents affc4c0 + 23b277b commit d2f07f8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Library/Homebrew/cli/named_args.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ def to_resolved_formulae_to_casks(only: parent&.only_formula_or_cask)
to_formulae_to_casks(only: only, method: :resolve)
end

LOCAL_PATH_REGEX = %r{^/|[.]|/$}.freeze
TAP_NAME_REGEX = %r{^[^./]+/[^./]+$}.freeze
private_constant :LOCAL_PATH_REGEX, :TAP_NAME_REGEX

# Keep existing paths and try to convert others to tap, formula or cask paths.
# If a cask and formula with the same name exist, includes both their paths
# unless `only` is specified.
Expand All @@ -230,9 +234,9 @@ def to_paths(only: parent&.only_formula_or_cask, recurse_tap: false)
@to_paths[only] ||= Homebrew.with_no_api_env_if_needed(@without_api) do
downcased_unique_named.flat_map do |name|
path = Pathname(name).expand_path
if only.nil? && File.exist?(name)
if only.nil? && name.match?(LOCAL_PATH_REGEX) && path.exist?
path
elsif name.count("/") == 1 && !name.start_with?("./", "/")
elsif name.match?(TAP_NAME_REGEX)
tap = Tap.fetch(name)

if recurse_tap
Expand Down

0 comments on commit d2f07f8

Please sign in to comment.