Skip to content

Commit bdd0224

Browse files
committed
tidy always ignore untracked
1 parent 616eb44 commit bdd0224

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/tools/tidy/src/walk.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
use std::collections::HashSet;
12
use std::ffi::OsStr;
23
use std::fs::File;
34
use std::io::Read;
4-
use std::path::Path;
5+
use std::path::{Path, PathBuf};
56

7+
use build_helper::git::get_git_untracked_files;
68
use ignore::DirEntry;
79

810
/// The default directory filter.
@@ -75,12 +77,20 @@ pub(crate) fn walk_no_read(
7577
skip: impl Send + Sync + 'static + Fn(&Path, bool) -> bool,
7678
f: &mut dyn FnMut(&DirEntry),
7779
) {
80+
let untracked_files: HashSet<PathBuf> = match get_git_untracked_files(Some(paths[0])) {
81+
Ok(Some(untracked_paths)) => {
82+
untracked_paths.into_iter().map(|s| PathBuf::from(paths[0]).join(s)).collect()
83+
}
84+
_ => HashSet::new(),
85+
};
86+
7887
let mut walker = ignore::WalkBuilder::new(paths[0]);
7988
for path in &paths[1..] {
8089
walker.add(path);
8190
}
8291
let walker = walker.filter_entry(move |e| {
8392
!skip(e.path(), e.file_type().map(|ft| ft.is_dir()).unwrap_or(false))
93+
&& !untracked_files.contains(e.path())
8494
});
8595
for entry in walker.build().flatten() {
8696
if entry.file_type().is_none_or(|kind| kind.is_dir() || kind.is_symlink()) {

0 commit comments

Comments
 (0)