Skip to content
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

cli/named_args: better handle name conflicts in #to_paths #16069

Conversation

apainintheneck
Copy link
Contributor

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Closes #16015

Before we used to evaluate all named arguments as local paths first. This means that the following could be a name conflict.

brew edit src

If there was a local file or directory named src, it would default to that. Otherwise it would search for a formula/cask with the same name and return that.

Now it will only default to the local path if the named argument starts or ends with a slash (/) or includes a period (.). This means that in the event of a name clash with a normal package name it will default to the package instead of the local file.

It also fixes an edge case where the following would be interpreted as a tap name if no local directory existed with the same name.

brew edit src/

Example:

$ pwd
/Users/kevinrobell/test
$ ls
jrnl     jrnl.rb  src/
$ brew edit --print-path jrnl
Warning: `brew install` ignores locally edited casks and formulae if
HOMEBREW_NO_INSTALL_FROM_API is not set.
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/j/jrnl.rb
$ brew edit --print-path jrnl.rb
/Users/kevinrobell/test/jrnl.rb
$ brew edit --print-path ./jrnl
/Users/kevinrobell/test/jrnl
$ brew edit --print-path src
Warning: `brew install` ignores locally edited casks and formulae if
HOMEBREW_NO_INSTALL_FROM_API is not set.
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/s/src.rb
$ brew edit --print-path src/
/Users/kevinrobell/test/src

Note: CLI::NamedArgs#to_paths is used in the following commands.

  • brew audit
  • brew bump-unversioned-casks
  • brew cat
  • brew edit
  • brew log
  • brew style

As an aside, the following used to work before but now doesn't work for formulae after tap sharding.

brew(main):001:0> Formulary.path "jrnl"
=> #<Pathname:/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/j/jrnl.rb>
brew(main):002:0> Formulary.path "jrnl.rb"
=> #<Pathname:/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/jrnl.rb>

It does work for casks though.

brew(main):003:0> Cask::CaskLoader.path "virtualbox"
=> #<Pathname:/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks/v/virtualbox.rb>
brew(main):004:0> Cask::CaskLoader.path "virtualbox.rb"
=> #<Pathname:/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks/v/virtualbox.rb>

Before we used to evaluate all named arguments as local paths
first. This means that the following could be a name conflict.

$ brew edit src

If there was a local file or directory named src, it would default
to that. Otherwise it would search for a formula/cask with the
same name and return that.

Now it will only default to the local path if the named argument
starts or ends with a slash ('/') or includes a period ('.').
This means that in the event of a name clash with a normal package
name it will default to the package instead of the local file.

It also fixes an edge case where the following would be interpreted
as a tap name.

$ brew edit /src
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me, nice work as usual @apainintheneck!

@MikeMcQuaid MikeMcQuaid merged commit d2f07f8 into Homebrew:master Oct 2, 2023
27 checks passed
@buildpulse
Copy link

buildpulse bot commented Oct 2, 2023

Known disruptive tests have failed for this pull request.

Commit SHA: d2f07f8
Build URL: https://github.com/Homebrew/brew/actions/runs/6379642693/attempts/1

Suite Name Test Name Details
rspec SystemCommand with both STDOUT and STDERR output from upstream with default options its result stderr is expected to eq "2\n4\n6\n"

@github-actions github-actions bot added the outdated PR was locked due to age label Nov 2, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

brew edit --print-path --formula src prints src not the full path
2 participants