Ripgrep: Home as git repo: troubles with ignore files

Created on 21 Feb 2017  路  3Comments  路  Source: BurntSushi/ripgrep

I've set up my $HOME as git repository to manage my dotfiles. Thus, I ignore all files via ~/.gitignore and force-add the config files I want to track with git.

This now causes some troubles:

  1. If I am in a project directory with its own gitignore/ignore files, I obviously want to use them, so I just call rg [pattern] which then works nicely out of the box.
  2. If I am in a directory without any ignore files, the parent ignore file in $HOME is parsed and I have to use rg -u [pattern] to avoid this. If rg now descents down into subdirectories with ignore files, these are also not parsed.
  3. If I un-ignore all files via !* in ~/.ignore, all files are searched, including hidden files (which I can filter out by ignoring them again with .* in ~/.ignore) and binary files (which I can not filter out).

I was hoping to find a way to have rg act identical in all directories, i.e. the same way as ~/.gitignore would not exist. I've tried adding ^.gitignore into ~/.ignore but this did not help.

Is there an option I've overlooked to achieve this behavior?

question

Most helpful comment

If I am in a directory without any ignore files, the parent ignore file in $HOME is parsed and I have to use rg -u [pattern] to avoid this. If rg now descents down into subdirectories with ignore files, these are also not parsed.

Yup, this is intended behavior. This isn't something that ripgrep imposes. These are the semantics of gitignore matching as described in man gitignore.

A very simple work-around is to run rg [pattern] *, which will override your $HOME/.gitignore because the paths are explicitly provided.

If I un-ignore all files via !* in ~/.ignore, all files are searched, including hidden files (which I can filter out by ignoring them again with .* in ~/.ignore) and binary files (which I can not filter out).

You might try something like ![!.]* in your $HOME/.ignore to whitelist all non-hidden files, although I suppose this large achieves the same thing as adding !* and .*.

Binary files should be automatically filtered out even if they aren't in your .gitignore. Are you seeing something different?

I was hoping to find a way to have rg act identical in all directories, i.e. the same way as ~/.gitignore would not exist. I've tried adding ^.gitignore into ~/.ignore but this did not help.

You could try using --no-ignore-parent, which specifically won't acknowledge .gitignore files in parent directories. The option isn't exactly short, so you'd probably want to create an alias of some sort.

FWIW, I also have a similar setup as you. I don't often search in my $HOME outside of other git directories, but when I do, I just use rg [pattern] *.

All 3 comments

If I am in a directory without any ignore files, the parent ignore file in $HOME is parsed and I have to use rg -u [pattern] to avoid this. If rg now descents down into subdirectories with ignore files, these are also not parsed.

Yup, this is intended behavior. This isn't something that ripgrep imposes. These are the semantics of gitignore matching as described in man gitignore.

A very simple work-around is to run rg [pattern] *, which will override your $HOME/.gitignore because the paths are explicitly provided.

If I un-ignore all files via !* in ~/.ignore, all files are searched, including hidden files (which I can filter out by ignoring them again with .* in ~/.ignore) and binary files (which I can not filter out).

You might try something like ![!.]* in your $HOME/.ignore to whitelist all non-hidden files, although I suppose this large achieves the same thing as adding !* and .*.

Binary files should be automatically filtered out even if they aren't in your .gitignore. Are you seeing something different?

I was hoping to find a way to have rg act identical in all directories, i.e. the same way as ~/.gitignore would not exist. I've tried adding ^.gitignore into ~/.ignore but this did not help.

You could try using --no-ignore-parent, which specifically won't acknowledge .gitignore files in parent directories. The option isn't exactly short, so you'd probably want to create an alias of some sort.

FWIW, I also have a similar setup as you. I don't often search in my $HOME outside of other git directories, but when I do, I just use rg [pattern] *.

A very simple work-around is to run rg [pattern] *, which will override your $HOME/.gitignore because the paths are explicitly provided.

This is probably what I was looking for! :smile:

Binary files should be automatically filtered out even if they aren't in your .gitignore. Are you seeing something different?

You' re right, I should have read the output more carefully. I got tons of additional output complaining about illegal .gitignore files ("invalid use of **; must be one path component") which were in a large repository in a subdir.

You could try using --no-ignore-parent, which specifically won't acknowledge .gitignore files in parent directories. The option isn't exactly short, so you'd probably want to create an alias of some sort.

FWIW, I also have a similar setup as you. I don't often search in my $HOME outside of other git directories, but when I do, I just use rg [pattern] *.

Works perfectly for me. Thanks for your answer and thanks for ripgrep!

I got tons of additional output complaining about illegal .gitignore files ("invalid use of **; must be one path component") which were in a large repository in a subdir.

Ah hmm. Unless there's a bug in ripgrep, that means you have some incorrect rules in your .gitignore. :-) I guess git is probably just not telling you.

Glad it all worked out!

Was this page helpful?
0 / 5 - 0 ratings