Ignore .git subdirectories when diffing directoriesa

Closes #798
pull/813/head
Wilfred Hughes 2025-01-21 21:54:00 +07:00
parent 56bf026c49
commit 8fcfdae7bd
2 changed files with 14 additions and 2 deletions

@ -1,5 +1,9 @@
## 0.63 (unreleased)
### Diffing
When diffing directories, difftastic now ignores the `.git` directory.
### Command Line Interface
Difftastic no longer accepts the `--missing-as-empty`. This has had no

@ -242,9 +242,17 @@ pub(crate) fn guess_content(bytes: &[u8]) -> ProbableFileKind {
/// All the files in `dir`, including subdirectories.
fn relative_file_paths_in_dir(dir: &Path) -> Vec<PathBuf> {
WalkBuilder::new(dir)
// Walk all the files in `dir`, excluding those mentioned in .git.
let walker = WalkBuilder::new(dir)
// Include files whose name starts with a dot.
.hidden(false)
.build()
// Exclude the .git directory.
.filter_entry(|e| {
!(e.file_type().map(|ft| ft.is_dir()).unwrap_or(false) && e.file_name() == ".git")
})
.build();
walker
.filter_map(Result::ok)
.map(|entry| Path::new(entry.path()).to_owned())
.filter(|path| !path.is_dir())