Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions crates/ignore/src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ impl WalkBuilder {
it: None,
ig_root: ig_root.clone(),
ig: ig_root.clone(),
max_depth: self.max_depth,
max_filesize: self.max_filesize,
skip: self.skip.clone(),
filter: self.filter.clone(),
Expand Down Expand Up @@ -1118,6 +1119,7 @@ pub struct Walk {
it: Option<WalkEventIter>,
ig_root: Ignore,
ig: Ignore,
max_depth: Option<usize>,
max_filesize: Option<u64>,
skip: Option<Arc<Handle>>,
filter: Option<Filter>,
Expand Down Expand Up @@ -1228,12 +1230,17 @@ impl Iterator for Walk {
self.it.as_mut().unwrap().it.skip_current_dir();
// Still need to push this on the stack because
// we'll get a WalkEvent::Exit event for this dir.
// We don't care if it errors though.
let (igtmp, _) = self.ig.add_child(ent.path());
// Its ignore files cannot apply to any visited entry.
let (igtmp, _) =
self.ig.add_child_with_entries(ent.path(), &[]);
self.ig = igtmp;
continue;
}
let (igtmp, err) = self.ig.add_child(ent.path());
let (igtmp, err) = if self.max_depth == Some(ent.depth()) {
self.ig.add_child_with_entries(ent.path(), &[])
} else {
self.ig.add_child(ent.path())
};
self.ig = igtmp;
ent.err = err;
return Some(Ok(ent));
Expand Down Expand Up @@ -2427,6 +2434,27 @@ mod tests {
);
}

#[test]
fn max_depth_does_not_load_unreachable_ignore_files() {
let td = tmpdir();
let leaf = td.path().join("leaf");
mkdirp(&leaf);
wfile(leaf.join(".ignore"), "{invalid\n");

let mut builder = WalkBuilder::new(td.path());
builder.max_depth(Some(1));
let entry = builder
.build()
.find_map(|result| {
let entry = result.unwrap();
(entry.path() == leaf).then_some(entry)
})
.unwrap();

assert!(entry.error().is_none());
assert_paths(td.path(), &builder, &["leaf"]);
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, clever test.


#[test]
fn min_depth() {
let td = tmpdir();
Expand Down
Loading