Ripgrep: $HOME/.gitignore is incorrectly used when searching in other directories such as /tmp

Created on 2 Jun 2018  Â·  10Comments  Â·  Source: BurntSushi/ripgrep

What version of ripgrep are you using?

ripgrep 0.8.1
-SIMD -AVX

How did you install ripgrep?

 brew install ripgrep

What operating system are you using ripgrep on?

mac 10.13.4

Describe your question, feature request, or bug.

Create a .gitignore in your $HOME directory. Cd over to /tmp, mkdir a pattern excluded in .gitignore and execute rg.

If this is a bug, what are the steps to reproduce the behavior?

echo "*.apk" > ~/.gitignore
cd /tmp
touch foo.apk
rg --debug --files
DEBUG/grep::search/grep/src/search.rs:195: regex ast:
Repeat {
    e: Literal {
        chars: [
            'z'
        ],
        casei: false
    },
    r: Range {
        min: 0,
        max: Some(
            0
        )
    },
    greedy: true
}
DEBUG/globset/globset/src/lib.rs:401: built glob set; 0 literals, 0 basenames, 1 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
DEBUG/ignore::walk/ignore/src/walk.rs:1428: ignoring ./.keystone_install_lock: Ignore(IgnoreMatch(Hidden))
DEBUG/ignore::walk/ignore/src/walk.rs:1428: ignoring ./foo.apk: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/Users/junger/.gitignore"), original: "*.apk", actual: "**/*.apk", is_whitelist: false, is_only_dir: false })))

If this is a bug, what is the actual behavior?

See above.

If this is a bug, what is the expected behavior?

ripgrep should not use .gitignore in your $HOME directory when searching in other directories such as /tmp

bug

Most helpful comment

In case anyone else lands here and was using this as a "feature" (with apologies for the xkcd.com/1172/):

I had been using this bug to add a local .gitignore at the root of a tree that isn't itself a git repo to ignore additional things inside child git repos. Renaming .gitignore to .rgignore restores the previous behaviour.

All 10 comments

Hmm, I can't seem to reproduce this issue on master:

$ pwd
/tmp/ripgrep-934
$ echo foo > $HOME/.gitignore
$ cat $HOME/.gitignore
foo
$ touch foo bar
$ rg --files
bar
foo

How do I install master?

➜  /tmp mkdir ripgrep-934
➜  /tmp cd ripgrep-934 
➜  ripgrep-934 echo foo > $HOME/.gitignore
➜  ripgrep-934 cat $HOME/.gitignore
foo
➜  ripgrep-934 touch foo bar
➜  ripgrep-934 rg --files
bar
➜  ripgrep-934 

I can't reproduce this in 0.8.1 either.

Do you have any global git configuration set? For example, if you have core.excludesFile set in your ~/.gitconfig to $HOME/.gitignore, then that might be the cause. Indeed, if I add

[core]
  excludesFile = /home/andrew/.gitignore

to my $HOME/.gitconfig, then I can reproduce the problem:

$ rg --files
bar

where my --debug output is:

DEBUG/grep::search/grep/src/search.rs:195: regex ast:
Repeat {
    e: Literal {
        chars: [
            'z'
        ],
        casei: false
    },
    r: Range {
        min: 0,
        max: Some(
            0
        )
    },
    greedy: true
}
DEBUG/globset/globset/src/lib.rs:401: built glob set; 0 literals, 1 basenames, 0 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
DEBUG/ignore::walk/ignore/src/walk.rs:1428: ignoring ./foo: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/home/andrew/.gitignore"), original: "foo", actual: "**/foo", is_whitelist: false, is_only_dir: false })))

This does actually seem like a bug to me. I don't think ripgrep should be applying global gitignore rules outside of a git repo.

How do I install master?

The README has build instructions. But given my previous comment, I don't think it's necessary, assuming the issue here is indeed your global git config.

@BurntSushi awesome catch!

➜  ripgrep-934 git config --global -l       
hub.host=...
hub.protocol=http
hub.host=...
hub.host=...
hub.host=...
hub.host=...
core.excludesfile=~/.gitignore
➜  ripgrep-934 

I also have a ton of hub.host but that can be ignored. 🤔

I also don't recalled why this is set in excludesfile.

I don't think ripgrep should be applying global gitignore rules outside of a git repo.

Even inside a git repo, this might be confusing for the same reasons that led me to use --no-ignore-parent in vscode. If it still uses global gitignore rules in git repos, it would be nice to be able to disable that.

This bug is fixed on master, and @roblourens I've added a new --no-ignore-global flag that should do what you want!

Thanks @BurntSushi !

Thanks, reopening the vscode issue to use it.

In case anyone else lands here and was using this as a "feature" (with apologies for the xkcd.com/1172/):

I had been using this bug to add a local .gitignore at the root of a tree that isn't itself a git repo to ignore additional things inside child git repos. Renaming .gitignore to .rgignore restores the previous behaviour.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kenorb picture kenorb  Â·  3Comments

Limeth picture Limeth  Â·  3Comments

timotheecour picture timotheecour  Â·  3Comments

danpintara picture danpintara  Â·  3Comments

davidtwco picture davidtwco  Â·  3Comments