diff --git a/CHANGELOG.md b/CHANGELOG.md index a2950f794..2c5deeda4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/files.rs b/src/files.rs index 51c4b7633..7c9105ef1 100644 --- a/src/files.rs +++ b/src/files.rs @@ -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 { - 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())