-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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]: Support absolute paths in global ignore files (via add_ignore
).
#2366
Comments
Could you please say why you can't use a
Also, ripgrep will ignore
It is not backwards compatible. Starting a glob pattern in a gitignore file with Overall, I don't see a compelling use case here. And even if there were a good use case, it would have to be very compelling because this is a rather complex feature to implement in an already complex part of ripgrep. Namely, if you have an absolute glob pattern, then you also need to turn every file path you're searching into an absolute path. That has a non-trivial cost, which means ripgrep would want to avoid turning everything into an absolute path if it didn't have to. Which means it would have to scan gitignore files for absolute patterns before starting the search. Which is just not great. |
I can think of a few reasons:
But these are just hypotheses. See below.
Sorry, that was a typo. I meant to say that it is backwards incompatible.
First of all, "/" in gitignore usually anchors to the location of the .gitignore file. But for global gitignores it anchors to the the root of the current git repository. The current working directory doesn't matter beyond dtermining the current git repo. Anchoring to the current directory doesn't actually seem very useful to me. If I have a rule to ignore "/foo/bar", in my global ignore file, and there is a file at "/a/b/foo/bar/c/d", then the current behavior is if I run Also, of the two, I would prefer having a distinct syntax for absolute patterns (maybe some sigil at the beginning that indicates the remander should be matched against the absolute path, I suggested "//" becuase that seems unlikely to appear at the beginning of an existing pattern). I included the option of a backwards incompatible change to how pattersn starting wtih "/" are matched mainly for completeness.
That's a legitimate concern. And I don't really see a way out of increasing the complexity, and if it would significantly add to the complexity maybe it isn't worth it. But I would like to point out a few things:
Finally, I haven't personally run into a need for this. However, this has come up a few times for That last one actually points out something interesting. If the starting path passed in to |
It is consistent with how greps behave. Notice, for example, that if you use an absolute file path as an input, then ripgrep will emit absolute file paths in the search result output. Indeed, the way paths are dealt with is almost purely symbolically. This is also simultaneously the reason why absolute glob patterns don't work when one provides a relative file path. Bottom line here is that I've been saying that the |
Describe your feature request
It is sometimes desirable to add a global ignore rule using an absolute path. Say for example I always wanted to ignore everything in /home/myuser/.cache.
.gitignore doesn't have a mechanism to do this, because git doesn't really care about anything outside of the git repository (at least for the context of .gitignore). However, for more general tools such as ripgrep (and
fd
) it does make sense to want to ignore something based on an absolute path, at least for global ignore files (such as ~/.config/fd/ignore).I see a couple ways of addressing this:
See sharkdp/fd#1150 (comment)
The text was updated successfully, but these errors were encountered: