Add test for gitignore workaround

And make sure it works for user-supplied path of "."

Also add changelog entry
This commit is contained in:
Thayne McCombs 2024-04-30 00:02:27 -06:00 committed by David Peter
parent 6af8f092ee
commit 6647085015
3 changed files with 18 additions and 0 deletions

View File

@ -12,6 +12,8 @@
## Bugfixes
- Respect NO_COLOR environment variable with `--list-details` option. (#1455)
- Fix bug that would cause hidden files to be includeddespite gitignore rules
if search path is "." (#1461, BurntSushi/ripgrep#2711).
## Changes

View File

@ -665,6 +665,9 @@ impl Opts {
fn normalize_path(&self, path: &Path) -> PathBuf {
if self.absolute_path {
filesystem::absolute_path(path.normalize().unwrap().as_path()).unwrap()
} else if path == Path::new(".") {
// Change "." to "./" as a workaround for https://github.com/BurntSushi/ripgrep/pull/2711
PathBuf::from("./")
} else {
path.to_path_buf()
}

View File

@ -2599,3 +2599,16 @@ fn test_git_dir() {
nested/dir/.git/foo2",
);
}
#[test]
fn test_gitignore_parent() {
let te = TestEnv::new(&["sub"], &[".abc", "sub/.abc"]);
fs::File::create(te.test_root().join(".gitignore"))
.unwrap()
.write_all(b".abc\n")
.unwrap();
te.assert_output_subdirectory("sub", &["--hidden"], "");
te.assert_output_subdirectory("sub", &["--hidden", "--search-path", "."], "");
}