ignore_contain now has higher precedence than root check.

This commit is contained in:
Ami Fischman
2026-01-14 07:58:30 -08:00
parent 1df183e0cd
commit f3a8bb7ce6
2 changed files with 24 additions and 16 deletions
+16 -15
View File
@@ -461,11 +461,22 @@ impl WorkerState {
return WalkState::Quit;
}
let entry = match entry {
Ok(ref e) if e.depth() == 0 => {
if let Ok(e) = &entry {
let entry_path = e.path();
if entry_path.is_dir()
&& config
.ignore_contain
.iter()
.any(|ic| entry_path.join(ic).exists())
{
return WalkState::Skip;
}
if e.depth() == 0 {
// Skip the root directory entry.
return WalkState::Continue;
}
}
let entry = match entry {
Ok(e) => DirEntry::normal(e),
Err(ignore::Error::WithPath {
path,
@@ -498,25 +509,15 @@ impl WorkerState {
}
};
// Check the depth & name first, since they don't require metadata.
let entry_path = entry.path();
// Filter out directories containing a given name.
if entry_path.is_dir()
&& config
.ignore_contain
.iter()
.any(|ic| entry_path.join(ic).exists())
{
return WalkState::Skip;
}
if let Some(min_depth) = config.min_depth
&& entry.depth().is_none_or(|d| d < min_depth)
{
return WalkState::Continue;
}
// Check the name first, since it doesn't require metadata
let entry_path = entry.path();
let search_str: Cow<OsStr> = if config.search_full_path {
let path_abs_buf = filesystem::path_absolute_form(entry_path)
.expect("Retrieving absolute path succeeds");
+8 -1
View File
@@ -2735,7 +2735,7 @@ fn test_ignore_contain() {
}
#[test]
fn test_ignore_contain_has_highest_precedence() {
fn test_ignore_contain_precedence_over_depth_check() {
let te = TestEnv::new(
&["include", "exclude", "exclude/sub"],
&[
@@ -2751,3 +2751,10 @@ fn test_ignore_contain_has_highest_precedence() {
expected,
);
}
#[test]
fn test_ignore_contain_precedence_over_root_check() {
let te = TestEnv::new(&["include"], &["CACHEDIR.TAG", "top", "include/foo"]);
let expected = "";
te.assert_output(&["--ignore-contain=CACHEDIR.TAG", "."], expected);
}