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

Ignore gitignore rules when explicitly searching inside an ignored dir #1108

Open
nyurik opened this issue Sep 10, 2022 · 8 comments
Open

Ignore gitignore rules when explicitly searching inside an ignored dir #1108

nyurik opened this issue Sep 10, 2022 · 8 comments

Comments

@nyurik
Copy link

nyurik commented Sep 10, 2022

To improve usability, I think it would be good to ignore the rules in .gitignore when the user tries to search inside a dir that is already ignored. This will result in far fewer "gotcha" moments. For example, assume I am searching inside a Rust project:

fd rmeta
# no results because all *.rmeta files are in the target/ dir, which is in .gitignore
fd rmeta target/
# No results because .gitignore has a `*.rmeta` rule too. Instead, I think it
# should show lots of results because I am searching explicitly inside an ignored dir

Note that .gitignore may have multiple rules, e.g. target/ and *.rmeta, but I believe the logic for ignoring should be: "if the dir is excluded, but gets included because fd is ran inside of the ignored dir or is explicitly listed as a param, automatically enable the -I param`

@tavianator
Copy link
Collaborator

I believe the logic for ignoring should be: "if the dir is excluded, but gets included because fd is ran inside of the ignored dir or is explicitly listed as a param, automatically enable the -I param

I think that's a little too aggressive: what if there is another git directory within the search path? I think its .gitignore should still be respected. The right behaviour might be to enable --no-ignore-parent instead, if the search path itself is ignored.

@nyurik
Copy link
Author

nyurik commented Sep 21, 2022

@tavianator not certain I understood what you mean. In case of a nested git repo, fd should respect the "closest" .gitignore up the tree.

@tavianator
Copy link
Collaborator

Right, but if you turn on -I, fd won't respect any .gitignores at all

@tavianator
Copy link
Collaborator

Oh but actually, I think I misinterpreted your question a bit. fd pattern ignored-dir already kind of does what I was suggesting. I thought it would give no results at all since the search path was ignored, but it indeed does give some results. Your point is that it still respects other .gitignore rules from the parent, which might not be helpful if we're already inside an ignored directory.

@tavianator
Copy link
Collaborator

However, I still think --no-ignore-parent is what you want, not -I. You can try fd rmeta target/ --no-ignore-parent yourself and see that it does the right thing. The difference is apparent if you clone another git repo inside target/.

@nyurik
Copy link
Author

nyurik commented Sep 21, 2022

@tavianator correct, that's the issue i was running into, and was very confused, esp after I already used the -H, and didn't realize it was due to the missing -I. You are right that the --no-ignore-parent would have worked, but we are talking about usability -- I was not even aware of that flag until you mentioned it -- I think the tool should work in the most non-surprising way possible by default, to minimize the confusion of the new users. Do you think the --no-ignore-parent should be enabled by default?

@tavianator
Copy link
Collaborator

Do you think the --no-ignore-parent should be enabled by default?

No, I just think that

if the dir is excluded, but gets included because fd is ran inside of the ignored dir or is explicitly listed as a param, automatically enable the -I param

is not the right fix, but

if the dir is excluded, but gets included because fd is ran inside of the ignored dir or is explicitly listed as a param, automatically enable the --no-ignore-parent param

is the right fix.

@nyurik
Copy link
Author

nyurik commented Sep 21, 2022

ah, sure, that could also work, thanks! You basically propose a new --ignore-parent=auto mode, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants