Comments (4)
I personally don't think needing to add a !
to the glob justifies a new API for this.
With that said, I am hoping to do a refresh of the ignore
crate soonish. Probably within the next year or so. My guess is that the API will be completely redesigned. There is little to like about the current one IMO.
from ripgrep.
Here's my actual problem:
In order to exclude the .git
directory itself when hidden files are shown, and gitignore is active, we add "!.git" to the overrides.
I still think this is a reasonable default to have (and maybe it would make sense for the ignore crate itself to do this?), but there are a few users who do want to include the .git
directory in the output. I was hoping that I could get something like --exclude !.git
or --include .git
to work where it would negate the !.git
in the overrides. However, due to the way overrides are implemented, !.git
has higher priority than .git
in the overrides. I could check for the specific string ".git" in the list of options passed to --include
, before adding !.git
, but that feels kind of hacky, and wouldn't work if the user used something like .git*
.
What I really want is a way to add additional rules at the same level as the .gitignore file, at lower priority than the override rules. Or, having native support for .git would be cool too. :)
I'm looking forward to seeing your redesign.
from ripgrep.
After a bit of experimentation, implementing an --include
option that is able to re-include things that have been excluded by other rules, also doesn't work as I hoped. It appears that if I add a non-negated rule, then the results will only include directories, and files that match the included patterns.
from ripgrep.
However, due to the way overrides are implemented,
!.git
has higher priority than.git
in the overrides.
That's not quite what's happening. The issue is one of whitelist/blacklist semantics. Namely, if all you have are blacklist rules, then a path passes the filter so long as it doesn't match anything in the blacklist. But if you have any whitelist rules, then a path passes the filter only when it both matches a rule and the last rule it matches is a whitelist rule. That applies when you have 0 or more blacklist rules.
This is easier with examples (using this repo):
$ rg burntsushi -l --hidden
GUIDE.md
CHANGELOG.md
README.md
tests/regression.rs
FAQ.md
.git/rr-cache/347ea8452dc5a9833914ef7fa86e08d8c618a57a/postimage
.git/rr-cache/347ea8452dc5a9833914ef7fa86e08d8c618a57a/preimage
$ rg burntsushi -l --hidden -g '!/.git/'
README.md
FAQ.md
CHANGELOG.md
tests/regression.rs
GUIDE.md
$ rg burntsushi -l --hidden -g '!/.git/' -g '/.git/'
rg: No files were searched, which means ripgrep probably applied a filter you didn't expect.
Running with --debug will show why files are being skipped.
$ rg burntsushi -l --hidden -g '!/.git/' -g '/.git/' -g '/.git/**'
.git/rr-cache/347ea8452dc5a9833914ef7fa86e08d8c618a57a/postimage
.git/rr-cache/347ea8452dc5a9833914ef7fa86e08d8c618a57a/preimage
The second to last example is the interesting one. The issue is that there is one whitelist pattern, so the only thing ripgrep will search are things matching /.git/
. But the only thing that /.git/
matches is a directory. But not anything inside that directory. So you need the extra /.git/**
rule.
Perhaps this will help with your use case.
I still think this is a reasonable default to have (and maybe it would make sense for the ignore crate itself to do this?)
I don't think so. I find this to be surprising behavior personally. If I ask to see hidden files, I want to see all of them, unless I've explicitly configured it to do otherwise.
For example, another approach here is echo /.git/ >> .ignore
(or echo /.git/ >> .fdignore
). That rule will suppress /.git/
when searching hidden folders. And users can opt into it.
from ripgrep.
Related Issues (20)
- Feature Request: Early Bail Out for Time-Consuming Regex Matches in pcre2 HOT 4
- [perf] rg does not use globs to prune recursion when it can HOT 4
- cursor disappearing HOT 1
- failing test: f2361_sort_nested_files
- The same `LineTerminator` is being used for searching and printing
- `--pre` doesn't work on Windows (CMD, MSYS2 bash, Powershell) HOT 16
- ARMv8 release binary for RPI 5 HOT 2
- ripgrep 14.1.0 exit silently when stdin is not connected (GNU parallel without --tty) HOT 8
- Feature Request: search for binary data by supplying a hex string HOT 9
- Is it possible to add a search for just a set of directories as a type? HOT 1
- Allow following symlinks to files HOT 2
- WalkDir ignores files that are in .gitignore outside of current git repository HOT 2
- Multiple quirks in ignore behavior HOT 1
- BUG: exit code on windows not stable (wrong on first run, then stable), seems to leak HOT 9
- pcre2 reset match \K drops submatches HOT 1
- ripgrep is slower than LTREP matching `[A-Z][A-Z]+` HOT 3
- --files is listing files that won't be searched into HOT 4
- ripgrep ignore files inside `.github` folder HOT 5
- Potentially incorrect or undocumented .gitignore files handling
- `--text` flag only works if it's late in the command HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ripgrep.