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

Surprising application of .gitignore in rust-lang/rust repo #25

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

Surprising application of .gitignore in rust-lang/rust repo #25

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

Comments

@brson
Copy link

brson commented Sep 23, 2016

This may be working as designed but it was quite surprising. If I run rg LLVM_BINDINGS from the top level of the rust repo I get results. If I do the same from src/ I get no results. The reason is that rust's .gitignore file contains /llvm/.

Perhaps this is how .gitignore is defined to work, but it's not what I expected. I might expect that .gitignore would by applied relative to the directory in which it is defined.

@foophoof
Copy link

According to gitignore(5) on my system (OS X running Git 2.9.0) (emphasis mine):

  • Patterns read from a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file. These patterns match relative to the location of the .gitignore file. A project normally includes such .gitignore files in its repository, containing patterns for files generated as part of the project build.

So I think your expectation is correct, that it should match relative to the location of the file, not the current directory.

@BurntSushi BurntSushi added the bug A bug. label Sep 24, 2016
@BurntSushi
Copy link
Owner

It is indeed a plain ol' bug.

amsharma91 added a commit to amsharma91/ripgrep that referenced this issue Sep 27, 2016
If a gitignore file in a *parent* directory is used, then it must be
matched relative to the directory it's in. ripgrep wasn't actually
adhering to this rule. Consider an example:

  .gitignore
  src
    llvm
      foo

Where `.gitignore` contains `/llvm/` and `foo` contains `test`. When
running `rg test` at the top-level directory, `foo` is correctly searched.
If you `cd` into `src` and re-run the same search, `foo` is ignored because
the `/llvm/` pattern is interpreted with respect to the current working
directory, which is wrong. The problem is that the path of `llvm` is
`./llvm`, which makes it look like it should match.

We fix this by rebuilding the directory path of each file when traversing
gitignores in parent directories. This does come with a small performance
hit.

Fixes BurntSushi#25.
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

3 participants