mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 19:45:29 +00:00
feat: ignore .git folder in build_walker()
This commit is contained in:
parent
21e7fdf3d6
commit
104bb511ba
@ -1,4 +1,4 @@
|
|||||||
use std::path::Path;
|
use std::{ffi::OsStr, path::Path};
|
||||||
|
|
||||||
/// Determines which files should be read or ignored during directory walking
|
/// Determines which files should be read or ignored during directory walking
|
||||||
pub struct FileVisibilityPolicy {
|
pub struct FileVisibilityPolicy {
|
||||||
@ -69,11 +69,19 @@ impl FileVisibilityPolicy {
|
|||||||
|
|
||||||
/// Walks through a directory using [`ignore::Walk`]
|
/// Walks through a directory using [`ignore::Walk`]
|
||||||
pub fn build_walker(&self, path: impl AsRef<Path>) -> ignore::Walk {
|
pub fn build_walker(&self, path: impl AsRef<Path>) -> ignore::Walk {
|
||||||
ignore::WalkBuilder::new(path)
|
let mut builder = ignore::WalkBuilder::new(path);
|
||||||
|
|
||||||
|
builder
|
||||||
.git_exclude(self.read_git_exclude)
|
.git_exclude(self.read_git_exclude)
|
||||||
.git_ignore(self.read_git_ignore)
|
.git_ignore(self.read_git_ignore)
|
||||||
.ignore(self.read_ignore)
|
.ignore(self.read_ignore)
|
||||||
.hidden(self.read_hidden)
|
.hidden(self.read_hidden);
|
||||||
.build()
|
|
||||||
|
if self.read_git_ignore {
|
||||||
|
builder.filter_entry(|p| p.path().file_name() != Some(OsStr::new(".git")));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
builder.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user