feat: ignore file listed in .gitignore, .ignore and .rgignore

This commit is contained in:
Paul Campbell 2024-09-18 11:26:33 +01:00
parent 37c354f8a2
commit 5f1a5b5608
2 changed files with 12 additions and 21 deletions

View file

@ -8,3 +8,4 @@ anyhow = "1.0"
regex = "1.10" regex = "1.10"
ureq = "2.10" ureq = "2.10"
kxio = "1.2" kxio = "1.2"
ignore = "0.4"

View file

@ -25,12 +25,19 @@ fn main() -> Result<()> {
println!("Prefix: {}", config.prefix_pattern); println!("Prefix: {}", config.prefix_pattern);
println!("Issues: {}", config.issue_pattern); println!("Issues: {}", config.issue_pattern);
// TODO: scan files in workdir
// TODO: ignore files listed in .rgignore .ignore or .gitignore
let mut found_markers = FoundMarkers::default(); let mut found_markers = FoundMarkers::default();
scan_files(&config, &mut found_markers)?; for file in ignore::WalkBuilder::new(config.fs.base())
.hidden(false)
.build()
.flatten()
{
let path = file.path();
if path.ends_with("/") {
continue;
}
scan_file(path, &config, &mut found_markers)?;
}
println!("{found_markers:?}"); println!("{found_markers:?}");
@ -82,23 +89,6 @@ impl FoundMarkers {
} }
} }
fn scan_files(config: &Config, found_markers: &mut FoundMarkers) -> Result<()> {
scan_dir(config.fs.base(), config, found_markers)
}
fn scan_dir(dir: &Path, config: &Config, found_markers: &mut FoundMarkers) -> Result<()> {
println!("dir : {}", dir.to_string_lossy());
let read_dir = config.fs.dir_read(dir)?;
for entry in read_dir {
match entry? {
DirItem::File(file) => scan_file(&file, config, found_markers),
DirItem::Dir(dir) => scan_dir(&dir, config, found_markers),
DirItem::SymLink(_) | DirItem::Fifo(_) | DirItem::Unsupported(_) => Ok(()),
}?;
}
Ok(())
}
fn scan_file(file: &Path, config: &Config, found_markers: &mut FoundMarkers) -> Result<()> { fn scan_file(file: &Path, config: &Config, found_markers: &mut FoundMarkers) -> Result<()> {
println!("file: {}", file.to_string_lossy()); println!("file: {}", file.to_string_lossy());
config config