ripgrep: an invalid pattern in gitignore causes all other patterns to be ignored

I have this line in my project .gitignore but when I do search for a string it still returns results from these paths. While ag respect the ignored paths & doesn’t show any results from there. Maybe I’m missing something here?

public/assets/admin

Here the commands

$ rg -w -tjs document # not very creative :)
$ ag --js "\bdocument\b"

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 22 (22 by maintainers)

Most upvoted comments

The Rust book should help get you started!

@ahmedelgabri (1) is absolutely the way to go. We should dump the error message from parsing the pattern to the debug output (which is only shown when --debug is passed). The specific place in the code where this needs to happen is in both of these methods. Specifically, using try! causes the method to stop and report the error. Instead, we should extract the error explicitly, call debug!("{}", err) and keep on processing.

I think this means that add_str can’t ever fail, but add_path can still fail if it can’t read the file. That’s OK because sometimes the file doesn’t exist. This fact is used to avoid building a matcher for a particular directory if the file doesn’t exist.

I’d be happy to mentor this change (even if you don’t know Rust). Otherwise, I’m also happy to just fix it. 😃

@ahmedelgabri Oh! That will do it. The actual problem is that **no-vcs** actually isn’t a valid gitignore pattern. From man gitignore:

      Two consecutive asterisks ("**") in patterns matched against full
       pathname may have special meaning:

       ·   A leading "**" followed by a slash means match in all directories.
           For example, "**/foo" matches file or directory "foo" anywhere, the
           same as pattern "foo". "**/foo/bar" matches file or directory "bar"
           anywhere that is directly under directory "foo".

       ·   A trailing "/**" matches everything inside. For example, "abc/**"
           matches all files inside directory "abc", relative to the location
           of the .gitignore file, with infinite depth.

       ·   A slash followed by two consecutive asterisks then a slash matches
           zero or more directories. For example, "a/**/b" matches "a/b",
           "a/x/b", "a/x/y/b" and so on.

       ·   Other consecutive asterisks are considered invalid.

rg actually detects that this is an invalid pattern, which is fine, but then it completely drops every other pattern in the file, which is bad. (And it doesn’t tell you that it did this either.) So this one pattern essentially killed your entire .gitignore. 😃

To clarify, the correct way to write that pattern is **/no-vcs/**. Or, if you want to match any directory name with no-vcs in it, then, **/*no-vcs*/**.

Is there any way for you to try current master? It would require installing Rust and compiling ripgrep (instructions in the README).

If not, that’s OK, but I’d suggest we stop debugging the issue until I get the next release out for you to try (which should be today). I say this because I’ve fixed a few bugs related to gitignore.