[ignore] Fallback to use git check-ignore or support hook iteration
tisonkun opened this issue · 3 comments
Since ignore is unaware of git index, there is a pitfall that a file force added to Git repository is ignored.
Currently, I write the logic below to switch the manner:
let walker = ignore::WalkBuilder::new(&self.basedir)
.ignore(false) // do not use .ignore file
.hidden(false) // check hidden files
.follow_links(true) // proper path name
.parents(turn_on_ignore)
.git_exclude(turn_on_ignore)
.git_global(turn_on_ignore)
.git_ignore(turn_on_ignore)
.overrides( ... );
for mat in walker {
...
if let Some(helper) = git_helper.as_ref()
&& helper.ignored(mat.path())?
{
continue;
}
result.push(mat.into_path())
}
where ignored is a wrapper of git2::Repository::is_path_ignored
.
However, this solution has a shortcoming that the walker iteration is determinated unaware of the Git ignore result, so it cannot skip directory ignored but must process all the files.
So I propose add an option to fallback to use git check-ignore or support hook iteration.
cc @BurntSushi
Source code is publicly available at -
https://github.com/korandoru/hawkeye/blob/v5.0.0/fmt/src/selection.rs#L99-L136
https://github.com/korandoru/hawkeye/blob/v5.0.0/fmt/src/git.rs#L65-L70
Or I may use Override
directly and do a manual walk through. I don't give it a try though.
Try to use a bare Override
with walkdir
crate. So far so good - korandoru/hawkeye@e7be36c