Skip to content

Commit

Permalink
Ignore .git subdirectories when diffing directoriesa
Browse files Browse the repository at this point in the history
Closes #798
  • Loading branch information
Wilfred committed Jan 22, 2025
1 parent 56bf026 commit 8fcfdae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 10 additions & 2 deletions src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 8fcfdae

Please sign in to comment.