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

WalkDir ignores files that are in .gitignore outside of current git repository #2812

Closed
1 task done
RudolfVonKrugstein opened this issue May 20, 2024 · 2 comments
Closed
1 task done
Labels
wontfix A feature or bug that is unlikely to be implemented or fixed.

Comments

@RudolfVonKrugstein
Copy link

Please tick this box to confirm you have reviewed the above.

  • I have a different issue.

What version of ripgrep are you using?

git clone of master (f1d23c0)

How did you install ripgrep?

cargo/I used the source

What operating system are you using ripgrep on?

Ubuntu in WSL2

Describe your bug.

When WalkDir is created via WalkBuilder and reguire_git(false) enabled, files that are ignored by an .gitignore above the current git repository root directory, are ignored (also git would not ignore them). When require_git(treu) is enabled, this is not the case.

What are the steps to reproduce the behavior?

  1. Create this test applicatin:
use std::env;

use ignore::WalkBuilder;

fn main() {
    let require_git_arg = if env::args().nth(1).unwrap() == "true" {
        true
    } else { false };

    let walker = WalkBuilder::new(".").require_git(require_git_arg).build();
    for result in walker {
        println!("{:?}", result.unwrap())
    }
}
  1. Create a git repository with a file in it:
git init
touch test
  1. Create a .gitignore outside of the git repoistory:
echo "test\n" > ../.gitignore
  1. run the application with require_git(true) and see, that the .gitignore is not considered:
cargo run -- true
DirEntry { dent: Walkdir(DirEntry(".")), err: None }                                                                                                                                                                                                        DirEntry { dent: Walkdir(DirEntry("./test")), err: None }  
  1. run the application with require_git(rqlw3) and see, that the .gitignore is considered:
cargo run -- true
DirEntry { dent: Walkdir(DirEntry(".")), err: None }                                                                                                                                                                                                       

What is the actual behavior?

WalkDir, created from WalkBuilder withrequire_git(false) uses any .gitignore files, that are outside of the current git repo (and therefor are not used by git) while require_git(true) does not use them.

What is the expected behavior?

The .gitignore outside/above the current git reo should not be used, regardless if require_git is called with true or false.

@BurntSushi
Copy link
Owner

The .gitignore outside/above the current git reo should not be used, regardless if require_git is called with true or false.

That's the entire point of require_git: it ignores whether .git is present or not and just uses every .gitignore that it finds. If you don't want ripgrep to cross git repository boundaries, then you should enable require_git.

@BurntSushi BurntSushi closed this as not planned Won't fix, can't repro, duplicate, stale May 20, 2024
@BurntSushi BurntSushi added the wontfix A feature or bug that is unlikely to be implemented or fixed. label May 20, 2024
@RudolfVonKrugstein
Copy link
Author

RudolfVonKrugstein commented May 20, 2024

Thank you for your reply. Just for completenes my perspective and how I got to creating this issue:

I thought the point of require_git(false) is to apply gitignore rules even when there is no git repository. I did not expect require_git(false) to behave differently from require_git(true) when there is a git repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix A feature or bug that is unlikely to be implemented or fixed.
Projects
None yet
Development

No branches or pull requests

2 participants