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

Ripgrep ignores files found in the parent directories .ignore file #2479

Closed
scottchiefbaker opened this issue Mar 27, 2023 · 6 comments
Closed
Labels
doc An issue with or an improvement to documentation. rollup A PR that has been merged with many others in a rollup.

Comments

@scottchiefbaker
Copy link

What version of ripgrep are you using?

ripgrep 13.0.0

How did you install ripgrep?

Installed directly from the GitHub release

What operating system are you using ripgrep on?

CentOS Stream 8

Describe your bug.

Ripgrep is ignoring files found in an .ignore file in the parent directory?

What is the expected behavior?

I was ripgreping for a pattern I knew was in my source, and wasn't getting a result. I immediately checked .gitignore and .ignore files in the current directory and there was nothing that would have filtered out my source. Testing again with --no-ignore showed the content I was expecting.

I'm assuming this is the intended behavior? I couldn't find any reference in the docs to ripgrep going up the tree looking for .ignore files. I would maybe expect it to look in each sub directory, but not go up. If this is not a bug then the documentation should be updated to indicate that

@BurntSushi
Copy link
Owner

Yes, it is definitely intended. Basically, ripgrep farms out a lot of the docs for this to man gitignore. For example, from the GUIDE:

For a more in depth description of how glob patterns in a .gitignore file are interpreted, please see man gitignore.

Now obviously man gitignore doesn't mention .ignore, so I think we can improve the docs there by essentially mentioning that ".ignore and .rgignore work just like .gitignore, but with no special connection to git and the presence of .git directories."

I don't think I documented this because it never occurred to me that someone would expect the behavior you want. Moreover, the presence of the --no-ignore-parent flag (and its docs) implies the behavior that ripgrep has.

I was ripgreping for a pattern I knew was in my source, and wasn't getting a result. I immediately checked .gitignore and .ignore files in the current directory and there was nothing that would have filtered out my source. Testing again with --no-ignore showed the content I was expecting.

I'd strongly recommend that you check out the --debug flag. It will tell you what things ripgrep is skipping. That way, you don't have to read gitignore files and apply the matching rules mentally. You can just see exactly what ripgrep is doing.

@BurntSushi BurntSushi added the doc An issue with or an improvement to documentation. label Mar 27, 2023
@scottchiefbaker
Copy link
Author

My real-world use case for this was that I had a directory ~/html/content/books/2023/ that I was trying to ripgrep. I had a .gitignore file in ~/html/ which was three directories up from where I was, so it was out of sight, out of mind. I had an overly broad rule that applied to the HTML directory, but not the books sub-dir. I didn't know about --no-ignore-parent until you mentioned it. That would have helped also.

Ultimately I think a modification to the docs that mentions that ripgrep will look for ignore files in all parent directories would be sufficient. That's where I was expecting to find this information.

Thanks for a great tool. I could not code nearly as efficiently without ripgrep. It's been a real game-changer in my workflow.

@BurntSushi
Copy link
Owner

Yeah the problem is where to put them. There are a lot of these sorts of caveats, and they just can't all be front and center. So if this information is buried in the GUIDE somewhere, would have it actually helped you? If it has to go in the very top of the man page to have helped you, then I'm not actually sure it's worth doing. Because that space is very content dense, and adding more to it reduces the visibility of other things that are perhaps more important than a detail like this.

@Timmmm
Copy link

Timmmm commented May 22, 2023

It would be good to put this comment in the docs for the ignore crate too (on the first page). It's currently a bit unclear which .gitignore files it uses.

@githorse
Copy link

githorse commented Aug 24, 2023

This one bit me as well. I had **/node_modules/** in my .gitignore. But sometimes I do need to find something inside node_modules/, so I $ cd node_modules/library-whatever and rg thingamabob ... and I get nothing.

If I replace **/node_modules/** with **/node_modules/ in .gitignore, then everything works as expected. So seems the problem is this overly broad ignore pattern is screening out any file that has node_modules anywhere in the path.

Ok, my bad. But maybe rg could handle this case better? It took me a while to figure out what was going on here. The distinction between **/node_modules/** and **/node_modules/ is pretty subtle, and it's non-obvious how that should affect the behavior of rg. If I'm currently inside /node_modules, my .ignore file says to ignore **/node_modules/**, and I run a rg search, clearly I'm doing something wrong. So maybe rg could either (1) ignore my .ignore in this case, since I didn't really mean it; or (2) issue a (more specific) warning about what's going on. (I did try --debug and the answer is in there but hard to find and parse in all that output.)

(1) is a little questionable but I think you could make a pretty good argument that, if the current working directory (not subdirectories, obviously) matches a pattern in some parent .ignore file, that particular ignore pattern should be skipped (since not doing so can only ever result in zero results, which is clearly not what the user wanted).

@BurntSushi
Copy link
Owner

@githorse I suspect doing something smarter like what you want without breaking other things is harder than you imagine. And in particular, "looking for patterns that match the cwd" is highly suspect.

ripgrep should emit a warning if it searches nothing. That is the intended failure mode here.

@BurntSushi BurntSushi added the rollup A PR that has been merged with many others in a rollup. label Nov 22, 2023
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Nov 28, 2023
14.0.2 (2023-11-27)
===================
This is a patch release with a few small bug fixes.

Bug fixes:

* [BUG #2654](BurntSushi/ripgrep#2654):
  Fix `deb` release sha256 sum file.
* [BUG #2658](BurntSushi/ripgrep#2658):
  Fix partial regression in the behavior of `--null-data --line-regexp`.
* [BUG #2659](BurntSushi/ripgrep#2659):
  Fix Fish shell completions.
* [BUG #2662](BurntSushi/ripgrep#2662):
  Fix typo in documentation for `-i/--ignore-case`.


14.0.1 (2023-11-26)
===================
This a patch release meant to fix `cargo install ripgrep` on Windows.

Bug fixes:

* [BUG #2653](BurntSushi/ripgrep#2653):
  Include `pkg/windows/Manifest.xml` in crate package.


14.0.0 (2023-11-26)
===================
ripgrep 14 is a new major version release of ripgrep that has some new
features, performance improvements and a lot of bug fixes.

The headlining feature in this release is hyperlink support. In this release,
they are an opt-in feature but may change to an opt-out feature in the future.
To enable them, try passing `--hyperlink-format default`. If you use [VS Code],
then try passing `--hyperlink-format vscode`. Please [report your experience
with hyperlinks][report-hyperlinks], positive or negative.

[VS Code]: https://code.visualstudio.com/
[report-hyperlinks]: BurntSushi/ripgrep#2611

Another headlining development in this release is that it contains a rewrite
of its regex engine. You generally shouldn't notice any changes, except for
some searches may get faster. You can read more about the [regex engine rewrite
on my blog][regex-internals]. Please [report your performance improvements or
regressions that you notice][report-perf].

[report-perf]: BurntSushi/ripgrep#2652

Finally, ripgrep switched the library it uses for argument parsing. Users
should not notice a difference in most cases (error messages have changed
somewhat), but flag overrides should generally be more consistent. For example,
things like `--no-ignore --ignore-vcs` work as one would expect (disables all
filtering related to ignore rules except for rules found in version control
systems such as `git`).

[regex-internals]: https://blog.burntsushi.net/regex-internals/

**BREAKING CHANGES**:

* `rg -C1 -A2` used to be equivalent to `rg -A2`, but now it is equivalent to
  `rg -B1 -A2`. That is, `-A` and `-B` no longer completely override `-C`.
  Instead, they only partially override `-C`.

Build process changes:

* ripgrep's shell completions and man page are now created by running ripgrep
with a new `--generate` flag. For example, `rg --generate man` will write a
man page in `roff` format on stdout. The release archives have not changed.
* The optional build dependency on `asciidoc` or `asciidoctor` has been
dropped. Previously, it was used to produce ripgrep's man page. ripgrep now
owns this process itself by writing `roff` directly.

Performance improvements:

* [PERF #1746](BurntSushi/ripgrep#1746):
  Make some cases with inner literals faster.
* [PERF #1760](BurntSushi/ripgrep#1760):
  Make most searches with `\b` look-arounds (among others) much faster.
* [PERF #2591](BurntSushi/ripgrep#2591):
  Parallel directory traversal now uses work stealing for faster searches.
* [PERF #2642](BurntSushi/ripgrep#2642):
  Parallel directory traversal has some contention reduced.

Feature enhancements:

* Added or improved file type filtering for Ada, DITA, Elixir, Fuchsia, Gentoo,
  Gradle, GraphQL, Markdown, Prolog, Raku, TypeScript, USD, V
* [FEATURE #665](BurntSushi/ripgrep#665):
  Add a new `--hyperlink-format` flag that turns file paths into hyperlinks.
* [FEATURE #1709](BurntSushi/ripgrep#1709):
  Improve documentation of ripgrep's behavior when stdout is a tty.
* [FEATURE #1737](BurntSushi/ripgrep#1737):
  Provide binaries for Apple silicon.
* [FEATURE #1790](BurntSushi/ripgrep#1790):
  Add new `--stop-on-nonmatch` flag.
* [FEATURE #1814](BurntSushi/ripgrep#1814):
  Flags are now categorized in `-h/--help` output and ripgrep's man page.
* [FEATURE #1838](BurntSushi/ripgrep#1838):
  An error is shown when searching for NUL bytes with binary detection enabled.
* [FEATURE #2195](BurntSushi/ripgrep#2195):
  When `extra-verbose` mode is enabled in zsh, show extra file type info.
* [FEATURE #2298](BurntSushi/ripgrep#2298):
  Add instructions for installing ripgrep using `cargo binstall`.
* [FEATURE #2409](BurntSushi/ripgrep#2409):
  Added installation instructions for `winget`.
* [FEATURE #2425](BurntSushi/ripgrep#2425):
  Shell completions (and man page) can be created via `rg --generate`.
* [FEATURE #2524](BurntSushi/ripgrep#2524):
  The `--debug` flag now indicates whether stdin or `./` is being searched.
* [FEATURE #2643](BurntSushi/ripgrep#2643):
  Make `-d` a short flag for `--max-depth`.
* [FEATURE #2645](BurntSushi/ripgrep#2645):
  The `--version` output will now also contain PCRE2 availability information.

Bug fixes:

* [BUG #884](BurntSushi/ripgrep#884):
  Don't error when `-v/--invert-match` is used multiple times.
* [BUG #1275](BurntSushi/ripgrep#1275):
  Fix bug with `\b` assertion in the regex engine.
* [BUG #1376](BurntSushi/ripgrep#1376):
  Using `--no-ignore --ignore-vcs` now works as one would expect.
* [BUG #1622](BurntSushi/ripgrep#1622):
  Add note about error messages to `-z/--search-zip` documentation.
* [BUG #1648](BurntSushi/ripgrep#1648):
  Fix bug where sometimes short flags with values, e.g., `-M 900`, would fail.
* [BUG #1701](BurntSushi/ripgrep#1701):
  Fix bug where some flags could not be repeated.
* [BUG #1757](BurntSushi/ripgrep#1757):
  Fix bug when searching a sub-directory didn't have ignores applied correctly.
* [BUG #1891](BurntSushi/ripgrep#1891):
  Fix bug when using `-w` with a regex that can match the empty string.
* [BUG #1911](BurntSushi/ripgrep#1911):
  Disable mmap searching in all non-64-bit environments.
* [BUG #1966](BurntSushi/ripgrep#1966):
  Fix bug where ripgrep can panic when printing to stderr.
* [BUG #2046](BurntSushi/ripgrep#2046):
  Clarify that `--pre` can accept any kind of path in the documentation.
* [BUG #2108](BurntSushi/ripgrep#2108):
  Improve docs for `-r/--replace` syntax.
* [BUG #2198](BurntSushi/ripgrep#2198):
  Fix bug where `--no-ignore-dot` would not ignore `.rgignore`.
* [BUG #2201](BurntSushi/ripgrep#2201):
  Improve docs for `-r/--replace` flag.
* [BUG #2288](BurntSushi/ripgrep#2288):
  `-A` and `-B` now only each partially override `-C`.
* [BUG #2236](BurntSushi/ripgrep#2236):
  Fix gitignore parsing bug where a trailing `\/` resulted in an error.
* [BUG #2243](BurntSushi/ripgrep#2243):
  Fix `--sort` flag for values other than `path`.
* [BUG #2246](BurntSushi/ripgrep#2246):
  Add note in `--debug` logs when binary files are ignored.
* [BUG #2337](BurntSushi/ripgrep#2337):
  Improve docs to mention that `--stats` is always implied by `--json`.
* [BUG #2381](BurntSushi/ripgrep#2381):
  Make `-p/--pretty` override flags like `--no-line-number`.
* [BUG #2392](BurntSushi/ripgrep#2392):
  Improve global git config parsing of the `excludesFile` field.
* [BUG #2418](BurntSushi/ripgrep#2418):
  Clarify sorting semantics of `--sort=path`.
* [BUG #2458](BurntSushi/ripgrep#2458):
  Make `--trim` run before `-M/--max-columns` takes effect.
* [BUG #2479](BurntSushi/ripgrep#2479):
  Add documentation about `.ignore`/`.rgignore` files in parent directories.
* [BUG #2480](BurntSushi/ripgrep#2480):
  Fix bug when using inline regex flags with `-e/--regexp`.
* [BUG #2505](BurntSushi/ripgrep#2505):
  Improve docs for `--vimgrep` by mentioning footguns and some work-arounds.
* [BUG #2519](BurntSushi/ripgrep#2519):
  Fix incorrect default value in documentation for `--field-match-separator`.
* [BUG #2523](BurntSushi/ripgrep#2523):
  Make executable searching take `.com` into account on Windows.
* [BUG #2574](BurntSushi/ripgrep#2574):
  Fix bug in `-w/--word-regexp` that would result in incorrect match offsets.
* [BUG #2623](BurntSushi/ripgrep#2623):
  Fix a number of bugs with the `-w/--word-regexp` flag.
* [BUG #2636](BurntSushi/ripgrep#2636):
  Strip release binaries for macOS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc An issue with or an improvement to documentation. rollup A PR that has been merged with many others in a rollup.
Projects
None yet
Development

No branches or pull requests

4 participants