diff --git a/CHANGELOG.md b/CHANGELOG.md index 08f447f32..85713ec02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ ## Bugfixes - Respect NO_COLOR environment variable with `--list-details` option. (#1455) +- Fix bug that would cause hidden files to be included despite gitignore rules + if search path is "." (#1461, BurntSushi/ripgrep#2711). ## Changes diff --git a/src/cli.rs b/src/cli.rs index 6e6163664..def42ede3 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -643,7 +643,7 @@ impl Opts { } else if !self.search_path.is_empty() { &self.search_path } else { - let current_directory = Path::new("."); + let current_directory = Path::new("./"); ensure_current_directory_exists(current_directory)?; return Ok(vec![self.normalize_path(current_directory)]); }; @@ -666,6 +666,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() } diff --git a/tests/tests.rs b/tests/tests.rs index 1edbeaed1..256615787 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -2590,3 +2590,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", "."], ""); +}