-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
brew edit --print-path --formula src
prints src
not the full path
#16015
Comments
Can't reproduce with or without homebrew/core tapped. Do you have a |
Oh wow, yes that's totally it, I have a |
It's an unintentional consequence of sharing code with |
This has come up before (#14895) and personally I think this behavior is confusing and unexpected. @MikeMcQuaid mentions in that issue that this is an intentional part of some users workflows though it seems like there are better options for opening files in the current directory. I think this is particularly confusing when the Other than deprecating this behavior entirely, we could always just print expanded paths whenever |
This seems like a good idea 👍🏻 |
The behaviour was added to
I agree with this - the logic should probably at least be skipped if |
Perhaps also this could default to a formula if one exists, so preferring |
To add |
When current directory contains dir with the same name as formula, `brew edit <formula>` now opens the formula instead of the dir. Fixes Homebrew#16015.
When current directory contains dir with the same name as formula, `brew edit <formula>` now opens the formula instead of the dir. Fixes Homebrew#16015.
I think we should deprecate the behavior of reading relative files/directories in This would mean adding a deprecation warning for users if local files exist that shadow formula/tap names. It would also mean modifying This might break some users' workflows. I believe that that is not a big deal though because there are other options when it comes to opening relative files and the |
@MikeMcQuaid You've mentioned multiple times that we should keep the current behavior because users will complain otherwise. Can you give use some examples of the users this change will negatively affect and why other approaches wouldn't work for them? |
I disagree. People use this and it's easier to resolve this confusion with messaging (i.e. always output a full, resolved path when editing or with errors) and then it allows them to continue to use these workflows. An example workflow I've seen a few people do:
This neither seems harmful or undesirable, other than confusion like in this issue.
I think it's also desirable that |
I still don't think
If this is intentional: can it be documented? It currently is not documented as supported for |
I agree that that should fail. Whether |
It's harmful because this undocumented behavior has precedence over all of the documented and therefore expected behaviors of The only argument for keeping the current behavior as I see it is momentum. It shouldn't be a big deal to remove support for undocumented behavior with clear alternatives; we do that regularly already. |
After making https://github.com/Homebrew/brew/pull/16030/files I think there is also a structural problem - Maybe the
|
For a package manager with millions of users and thousands of users: the "momentum" argument is non-trivial.
If we were talking about removing it from
I don't think the internals are the problem here. |
There is actually a wider question to be had here. This is how the following currently behave: $ cd ~
$ brew formula hello
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/h/hello.rb
$ brew formula Library
Library
$ brew formula /etc
/etc
$ brew log hello
(git log output)
$ brew log Library
[if not in git directory]
fatal: not a git repository (or any of the parent directories): .git
[if in git directory - and one that's not even a shallow clone like the warning suggests]
Warning: . is a shallow clone so only partial output will be shown.
To get a full clone, run:
git -C "" fetch --unshallow
(git log output)
$ brew audit --installed Library
(runs `brew style Library`, not installed formulae, and then audits over the installed formulae, not Library) The follow up question is how should each of the the previous behave? |
The easiest way to deal with it is: diff --git a/Library/Homebrew/cli/named_args.rb b/Library/Homebrew/cli/named_args.rb
index 98ab981c1..f0bf6ab74 100644
--- a/Library/Homebrew/cli/named_args.rb
+++ b/Library/Homebrew/cli/named_args.rb
@@ -230,7 +230,7 @@ module Homebrew
@to_paths[only] ||= Homebrew.with_no_api_env_if_needed(@without_api) do
downcased_unique_named.flat_map do |name|
path = Pathname(name)
- if File.exist?(name)
+ if only.nil? && File.exist?(name)
path
elsif name.count("/") == 1 && !name.start_with?("./", "/")
tap = Tap.fetch(name) This in turn fixes There's perhaps also an priority argument to be had too. If you run |
Great question. Here's what I think the ideal behaviour/output would be: $ cd ~
$ brew formula hello
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/h/hello.rb
$ brew formula Library
/Users/mike/Library
$ brew formula /etc
/etc
# alternatively:
$ brew formula Library
Error: /Users/mike/Library is not a formula!
$ brew formula /etc
Error: /etc is not a formula!
$ brew log hello
Git log for /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/h/hello.rb:
(git log output)
$ brew log Library
[if not in git directory]
Error: no /Users/mike/Library/.git directory found!
$ brew log Library
[if in git directory - and one that's not even a shallow clone like the warning suggests]
Git log for /Users/mike/Library:
Warning: . is a shallow clone so only partial output will be shown.
To get a full clone, run:
git -C "" fetch --unshallow
(git log output)
$ brew audit --installed Library
Error: no formulae or casks found in /Users/mike/Library!
This makes sense to me 👍🏻
I think the |
It looks like we're already in agreement about the expanding paths in The current eval order:
I still think it's more intuitive to make local files/directories lower priority for this specific command but we should update the docs to mention it either way. The
In comparison, this is what we have for
Edit: By keeping local files/directories as the highest precedence option we're essentially signaling that this is the most common expected use case of this command. |
I'd like to discuss other commands too if possible but maybe that'd be worth making another issue for since it's not directly related to this one. Just to make it easier to follow. Edit: I'm certainly surprised that the |
I don't agree with this take. It's almost certainly too much work but I think As I keep saying, though: I think the main issue here is just communicating through the command output what is being edited.
Yeh, happy to discuss that in another issue 👍🏻. I think ideally there'd be as much consistency between commands as possible. |
The ambiguous ones are It should be easy enough to add handling for the other cases though. Anything that starts or ends with a slash or includes a period should be treated as a file path by default. Strings with periods and strings that start with slashes are already unambiguous. Interesting that as currently written diff --git a/Library/Homebrew/cli/named_args.rb b/Library/Homebrew/cli/named_args.rb
index bfa013001..0fd56ae5d 100644
--- a/Library/Homebrew/cli/named_args.rb
+++ b/Library/Homebrew/cli/named_args.rb
@@ -230,9 +230,7 @@ module Homebrew
@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)
- path
- elsif name.count("/") == 1 && !name.start_with?("./", "/")
+ if name.match?(%r{^[^./]+/[^./]+$})
tap = Tap.fetch(name)
if recurse_tap Something like this would work I think. |
Yup, that seems like a good idea. |
brew doctor
outputVerification
brew doctor
output" above saysYour system is ready to brew.
and am still able to reproduce my issue.brew update
twice and am still able to reproduce my issue.brew install wget
. If they do, open an issue at https://github.com/Homebrew/homebrew-core/issues/new/choose instead.brew config
outputWhat were you trying to do (and why)?
Get the path to the src core formula
What happened (include all command output)?
What did you expect to happen?
Same as if you fully specify the formula:
Step-by-step reproduction instructions (by running
brew
commands)The text was updated successfully, but these errors were encountered: