Skip to content

fix: bulletproof external diff isolation (#380)#409

Merged
tomasz-tomczyk merged 1 commit intomainfrom
fix-380-difft-duplicate
May 1, 2026
Merged

fix: bulletproof external diff isolation (#380)#409
tomasz-tomczyk merged 1 commit intomainfrom
fix-380-difft-duplicate

Conversation

@tomasz-tomczyk
Copy link
Copy Markdown
Owner

Summary

Issue #380 reports duplicate lines in the rendered diff. The reporter has `diff.external = difft` set and noted that `git diff --no-ext-diff` still produced difftastic output for them — meaning crit could be receiving non-unified-diff content that breaks `ParseUnifiedDiff`.

I couldn't reproduce the duplicate locally with a synthetic 3000-line .js fixture matching the screenshot pattern, even with `diff.external = difft` and `diff.suppressBlankEmpty = true`. So the root cause for that specific user is still unconfirmed — but their environment clearly has a path where `--no-ext-diff` alone isn't enough.

This PR makes external-diff disabling defense-in-depth:

  • `-c diff.external=` as a command-line config override on every `git diff` invocation that parses output. Different mechanism from `--no-ext-diff`, so it works even if that flag is bypassed.
  • `GIT_EXTERNAL_DIFF` and `GIT_DIFF_OPTS` stripped from each git subprocess's environment. Scoped per-subprocess via `cmd.Env` — the parent process and the user's shell environment are not touched.
  • Existing `--no-ext-diff` flag retained so any one of the three is sufficient.

If the duplicate truly stems from difft output leaking into crit's diff parser, this fixes it. If it doesn't, this is still correct hygiene and rules out one class of cause.

Test plan

  • `go test ./...` passes
  • Smoke-tested with `diff.external = difft` set in repo config — diff API returns correct unified hunks
  • Reporter (@TheCoreMan) builds from source and confirms whether the duplicate persists

🤖 Generated with Claude Code

@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

❌ Patch coverage is 88.46154% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.32%. Comparing base (23e4615) to head (351028f).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
git.go 88.46% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #409      +/-   ##
==========================================
+ Coverage   67.26%   67.32%   +0.06%     
==========================================
  Files          26       26              
  Lines        9650     9665      +15     
==========================================
+ Hits         6491     6507      +16     
+ Misses       2649     2648       -1     
  Partials      510      510              
Flag Coverage Δ
e2e 34.18% <53.84%> (+0.04%) ⬆️
unit 63.52% <88.46%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Some users report `--no-ext-diff` not suppressing their configured
external diff tool (e.g. difftastic), causing crit to receive
non-unified-diff output that breaks rendering.

Belt-and-suspenders the disable: pass `-c diff.external=` to override
the config at the command line, and strip GIT_EXTERNAL_DIFF /
GIT_DIFF_OPTS from the subprocess environment. Both mechanisms run
alongside the existing `--no-ext-diff` flag so any one of them is
sufficient on its own.

The env override is scoped to each git subprocess via cmd.Env — the
parent process and shell environment are untouched.
@tomasz-tomczyk tomasz-tomczyk force-pushed the fix-380-difft-duplicate branch from 9c3cc59 to 351028f Compare May 1, 2026 07:36
@tomasz-tomczyk tomasz-tomczyk merged commit 20c1de9 into main May 1, 2026
8 checks passed
@tomasz-tomczyk tomasz-tomczyk deleted the fix-380-difft-duplicate branch May 1, 2026 07:48
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.

1 participant