Skip to content
Myr

ignore_contain now has higher precedence than root check.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Ami Fischman · committed by Ami Fischman · parent 1df183e · Browse files · 2 files+24 added−16 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+24 added−16 removed

  • tests:+8 added−1 removed
  • other:+16 added−15 removed

2 files+24 added−16 removed

modified:src/walk.rs+16 added-15 removed
459 unmodified lines
460 if quit_flag.load(Ordering::Relaxed) {461 return WalkState::Quit;462 }463464 let entry = match entry {465 Ok(ref e) if e.depth() == 0 => {464 if let Ok(e) = &entry {465 let entry_path = e.path();466 if entry_path.is_dir()467 && config468 .ignore_contain469 .iter()470 .any(|ic| entry_path.join(ic).exists())471 {472 return WalkState::Skip;473 }474 if e.depth() == 0 {475 // Skip the root directory entry.476 return WalkState::Continue;477 }478 }479 let entry = match entry {480 Ok(e) => DirEntry::normal(e),481 Err(ignore::Error::WithPath {482 path,483 err: inner_err,
24 unmodified lines
508 };509 }510 };511501 // Check the depth & name first, since they don't require metadata.502 let entry_path = entry.path();503504 // Filter out directories containing a given name.505 if entry_path.is_dir()506 && config507 .ignore_contain508 .iter()509 .any(|ic| entry_path.join(ic).exists())510 {511 return WalkState::Skip;512 }513512 if let Some(min_depth) = config.min_depth513 && entry.depth().is_none_or(|d| d < min_depth)514 {515 return WalkState::Continue;516 }517518 // Check the name first, since it doesn't require metadata519 let entry_path = entry.path();520521 let search_str: Cow<OsStr> = if config.search_full_path {522 let path_abs_buf = filesystem::path_absolute_form(entry_path)523 .expect("Retrieving absolute path succeeds");524 Cow::Owned(path_abs_buf.as_os_str().to_os_string())
156 unmodified lines
modified:tests/tests.rs+8 added-1 removed
2733 unmodified lines
2734 );2735}27362737#[test]2738fn test_ignore_contain_has_highest_precedence() {2738fn test_ignore_contain_precedence_over_depth_check() {2739 let te = TestEnv::new(2740 &["include", "exclude", "exclude/sub"],2741 &[2742 "top",
7 unmodified lines
2750 &["--ignore-contain=CACHEDIR.TAG", "--min-depth=2", "."],2751 expected,2752 );2753}27542755#[test]2756fn test_ignore_contain_precedence_over_root_check() {2757 let te = TestEnv::new(&["include"], &["CACHEDIR.TAG", "top", "include/foo"]);2758 let expected = "";2759 te.assert_output(&["--ignore-contain=CACHEDIR.TAG", "."], expected);2760}