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

Ignoring of subdirectories is inconsistent with git #16

Closed
dmit opened this issue Sep 23, 2016 · 2 comments
Closed

Ignoring of subdirectories is inconsistent with git #16

dmit opened this issue Sep 23, 2016 · 2 comments
Labels
bug A bug.

Comments

@dmit
Copy link

dmit commented Sep 23, 2016

I have an entry target/ in .gitignore to ignore all target directories in the project. ag handles it fine and ignores all matching directories. rg only ignores the matching top level directory. If I change the pattern to **/target/ then rg works as expected, but ag stops ignoring all target directories. In both cases git ignores both the top level directory and the subdirectories.

Here's a shell session to illustrate the issue:

/p/tmp> rg --version
0.1.16
/p/tmp> git init abc
Initialized empty Git repository in /private/tmp/abc/.git/
/p/tmp> cd abc/
/p/t/abc> mkdir ghi
/p/t/abc> mkdir -p def/ghi
/p/t/abc> echo ghi/ > .gitignore
/p/t/abc> echo xyz > ghi/toplevel.txt
/p/t/abc> echo xyz > def/ghi/subdir.txt
/p/t/abc> ag xyz
/p/t/abc> rg xyz
def/ghi/subdir.txt
1:xyz
/p/t/abc> git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitignore

nothing added to commit but untracked files present (use "git add" to track)
/p/t/abc> echo '**/ghi/' > .gitignore
/p/t/abc> ag xyz
def/ghi/subdir.txt
1:xyz

ghi/toplevel.txt
1:xyz
/p/t/abc> rg xyz
No files were searched, which means ripgrep probably applied a filter you didn't expect. Try running again with --debug.
/p/t/abc> git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitignore

nothing added to commit but untracked files present (use "git add" to track)
DEBUG:rg::ignore: ./ghi ignored by Pattern { from: "./.gitignore", original: "ghi/", pat: "ghi", whitelist: false, only_dir: true }
@BurntSushi BurntSushi added the bug A bug. label Sep 24, 2016
@BurntSushi
Copy link
Owner

Confirmed. This one is embarrassing.

@BurntSushi
Copy link
Owner

The specific problem here was a bug translating the .gitignore path into a glob with the right semantics defined by gitignore. Specifically, it was being treated as an absolute path, which of course, it's not (because it lacks the leading /).

amsharma91 added a commit to amsharma91/ripgrep that referenced this issue Sep 27, 2016
We were erroneously neglecting to prefix a pattern like `foo/`
with `**/` (to make `**/foo/`) because it had a slash in it. In fact, the
only reason to neglect a **/ prefix is if the pattern already starts
with **/, or if the pattern is absolute.

Fixes BurntSushi#16, BurntSushi#49, BurntSushi#50, BurntSushi#65
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug.
Projects
None yet
Development

No branches or pull requests

2 participants