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

specifying --ignore-file .gitignore works, but the normal gitignore logic does not #1574

Closed
Kagami opened this issue May 8, 2020 · 7 comments
Labels
bug A bug. gitignore Bugs related to gitignore problems.

Comments

@Kagami
Copy link

Kagami commented May 8, 2020

Sorry if it was already asked.

Explanation of feature request with the code:

# Init structure
$ git init t
$ cd t
$ echo a > 1
$ echo a > 2
$ mkdir sub
$ echo a > sub/1
$ echo a > sub/2
$ echo sub/1 > .gitignore

# Search for a
$ rg -l a
1
2
sub/2

# Want a only in sub
$ rg -l a sub
sub/1 # < don't want this
sub/2

# Forcing ignore file
$ rg -l --ignore-file .gitignore a sub
sub/2 # < ok

# Works ok too
$ cd sub
$ rg -l a
2

# Don't know how to find gitignore (possible, but needs additional code)
$ cd sub
$ rg -l --ignore-file .gitignore a
.gitignore: No such file or directory (os error 2)

# Would be nice to have
$ alias rgi='rg --force-ignore'
$ rgi -l a sub
sub/2 # < ok
$ cd sub
$ rgi -l a
2 # < ok
@BurntSushi BurntSushi changed the title Add option to respect ignore files with positional arguments specifying --ignore-file .gitignore works, but the normal gitignore logic does not May 8, 2020
@BurntSushi BurntSushi added bug A bug. gitignore Bugs related to gitignore problems. labels May 8, 2020
@BurntSushi
Copy link
Owner

I think there are two separate issues here. One is your request for ignore files to apply to explicitly given file paths. That won't ever happen, but it should still work when the explicitly given arguments are directories, which is the case here.

I think the bug here is that --ignore-file .gitignore works where as the normal gitignore logic does not. That's quite strange to me and I don't know off-hand why they would be inconsistent with one another.

This issue looks very similar to #278, #829 and #1050.

@Kagami
Copy link
Author

Kagami commented May 8, 2020

Ah yes, it's the same as #829, thanks.

I thought it's working as designed due to #1531.

Closing.

@Kagami Kagami closed this as completed May 8, 2020
BurntSushi added a commit that referenced this issue May 8, 2020
This attempts to fix some mild confusion that came up as part of #1574.
Specifically:
#1574 (comment)
BurntSushi added a commit that referenced this issue May 9, 2020
This attempts to fix some mild confusion that came up as part of #1574.
Specifically:
#1574 (comment)
@rolfb
Copy link

rolfb commented May 20, 2020

How are you supposed to do rg --files **/index.js and always apply ignores (.gitignore) to the result?

@BurntSushi
Copy link
Owner

@rolfb You can't, by design.

@rolfb
Copy link

rolfb commented May 20, 2020

@BurntSushi does that mean it's not possible to search for all index.js files recursively that respects the ignores?

@BurntSushi
Copy link
Owner

No it does not mean that. Why not open a new discussion question with the actual problem you're trying to solve instead of commenting on a closed issue?

@rolfb
Copy link

rolfb commented May 20, 2020

@BurntSushi my apologies for this, created a discussion at #1589 and linking it here in case people land here the same way I did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug. gitignore Bugs related to gitignore problems.
Projects
None yet
Development

No branches or pull requests

3 participants