Skip to content

fix: add --no-ext-diff to git diff commands to support external diff tools#318

Merged
tomasz-tomczyk merged 2 commits intotomasz-tomczyk:mainfrom
Amwam:test-gitdiff
Apr 20, 2026
Merged

fix: add --no-ext-diff to git diff commands to support external diff tools#318
tomasz-tomczyk merged 2 commits intotomasz-tomczyk:mainfrom
Amwam:test-gitdiff

Conversation

@Amwam
Copy link
Copy Markdown
Contributor

@Amwam Amwam commented Apr 20, 2026

Problem

When a user has an external diff tool configured (e.g. difftastic, delta, or any tool set via GIT_EXTERNAL_DIFF or diff.external in gitconfig), git diff outputs in the tool's custom format rather than standard unified diff. Crit's ParseUnifiedDiff cannot parse these formats, so it returns 0 hunks — causing the diff view to appear completely blank even though the file is correctly detected as modified.

This is a silent failure: the file appears in the file list with a modified status icon, but clicking it shows no content. There is no error message to indicate why.

Example

With difftastic configured, git diff AGENTS.md outputs:

AGENTS.md --- Text
17 17
18 18 ## Microservices
19 19
.. 20 this is a test input
.. 21
20 22 ### a title

ParseUnifiedDiff expects lines starting with +, -, and @@ hunk headers — none of which appear in this output. Result: 0 hunks, blank UI.

Why detection still worked

The file list detection uses git diff --name-status, which only outputs filenames and status letters (M, A, D). External diff drivers are not invoked for --name-status output, so detection correctly identifies the file as modified. Only the content diff fetch is broken.

Fix

Add --no-ext-diff to all git diff invocations that produce diff content for parsing:

  • fileDiffUnified — default diff (vs HEAD or merge base)
  • fileDiffUnifiedCtx — same, with context cancellation for lazy loading
  • FileDiffScoped — branch/staged/unstaged scope diffs
  • FileDiffForCommit — per-commit diffs in the commit selector sidebar

--no-ext-diff tells git to always use its built-in unified diff driver, regardless of any external diff configuration. This is the correct approach for programmatic diff consumption — external diff tools are designed for human-readable terminal output, not machine parsing.

The --name-status detection commands are unchanged since they are unaffected by external diff drivers.

Testing

All 12 existing TestFileDiff* tests pass. These tests run against real git repos and cover all modified code paths.

Screenshots

Before

Screenshot 2026-04-20 at 16 55 56

After

(Actual diff cutt off here, to hide sensitive info)
Screenshot 2026-04-20 at 16 56 47

The --numstat call in DiffNumstatDir can also be affected by external
diff tools. Add the flag for consistency with the other diff commands.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tomasz-tomczyk
Copy link
Copy Markdown
Owner

Thank you!! 🧡 💛 💚

@tomasz-tomczyk tomasz-tomczyk merged commit 7c4a5e5 into tomasz-tomczyk:main Apr 20, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants