Skip to content

fix(git): pass --no-ext-diff when diffing untracked files#259

Merged
benvinegar merged 4 commits into
modem-dev:mainfrom
iamken1204:fix-untracked-no-ext-diff
May 10, 2026
Merged

fix(git): pass --no-ext-diff when diffing untracked files#259
benvinegar merged 4 commits into
modem-dev:mainfrom
iamken1204:fix-untracked-no-ext-diff

Conversation

@iamken1204
Copy link
Copy Markdown
Contributor

Summary

If you have diff.external set in git config (difftastic, delta, etc.), hunk diff crashes on any untracked file:

$ hunk diff
hunk: Expected one parsed file for untracked patch "foo.txt", got 0.

hunk forms untracked patches via git diff --no-index, which honors diff.external and outputs whatever that tool prints instead of unified diff. The regular diff/show paths already use --no-ext-diff, the untracked path was missing it.

Test

  • Added a regression that sets diff.external on a temp repo and loads an untracked file.
  • Repro'd locally with diff.external = difft; works after the fix.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 9, 2026

Greptile Summary

This PR fixes a crash in hunk diff when a user has diff.external configured in git (e.g. difftastic, delta): the untracked-file synthetic-patch path was missing --no-ext-diff, so git replaced unified-diff output with whatever the external tool produces, which the parser couldn't handle. A regression test covering the exact failure mode is also added.

  • src/core/git.ts — adds --no-ext-diff to buildGitNewFileDiffArgs, aligning it with buildGitDiffArgs and buildGitShowArgs which already carry the flag. buildGitStashShowArgs is still missing it (see inline comment).
  • src/core/loaders.test.ts — adds a regression test that writes diff.external=/usr/bin/true into a temp repo config and asserts an untracked file loads without error.

Confidence Score: 3/5

The untracked-file fix is correct and well-tested, but hunk stash show carries the same unfixed bug for users with diff.external configured.

The fix is correct and directly addresses the reported crash. However, buildGitStashShowArgs is still missing --no-ext-diff — the same condition that broke the untracked path will produce an identical parse failure when a user runs hunk stash show with diff.external set. The PR partially solves the problem it sets out to fix.

src/core/git.ts — specifically buildGitStashShowArgs which should mirror the flag added to the other three diff-producing functions.

Important Files Changed

Filename Overview
src/core/git.ts Adds --no-ext-diff to buildGitNewFileDiffArgs fixing the untracked-file crash; buildGitStashShowArgs is still missing the same flag and will break with diff.external configured.
src/core/loaders.test.ts Adds a targeted regression test that configures diff.external=/usr/bin/true in a temp repo and asserts the untracked file is loaded correctly; well-scoped and sufficient for the fix it covers.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[hunk diff] --> B{File type?}
    B -->|Tracked changes| C[buildGitDiffArgs\n--no-ext-diff ✓]
    B -->|Commit show| D[buildGitShowArgs\n--no-ext-diff ✓]
    B -->|Untracked file| E[buildGitNewFileDiffArgs\n--no-ext-diff ✓ FIXED]
    B -->|Stash show| F[buildGitStashShowArgs\n--no-ext-diff ✗ MISSING]
    C --> G[Unified diff output → parser]
    D --> G
    E --> G
    F -->|diff.external configured| H[External tool output → parser CRASH]
    F -->|No diff.external| G
Loading

Comments Outside Diff (1)

  1. src/core/git.ts, line 104 (link)

    P1 buildGitStashShowArgs is missing --no-ext-diff, the same flag this PR adds to buildGitNewFileDiffArgs. A user with diff.external set will get the same unparseable output from hunk stash show that motivated this fix — git stash show -p honors diff.external just like git diff --no-index does.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/core/git.ts
    Line: 104
    
    Comment:
    `buildGitStashShowArgs` is missing `--no-ext-diff`, the same flag this PR adds to `buildGitNewFileDiffArgs`. A user with `diff.external` set will get the same unparseable output from `hunk stash show` that motivated this fix — `git stash show -p` honors `diff.external` just like `git diff --no-index` does.
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
src/core/git.ts:104
`buildGitStashShowArgs` is missing `--no-ext-diff`, the same flag this PR adds to `buildGitNewFileDiffArgs`. A user with `diff.external` set will get the same unparseable output from `hunk stash show` that motivated this fix — `git stash show -p` honors `diff.external` just like `git diff --no-index` does.

```suggestion
  const args = ["stash", "show", "-p", "--no-ext-diff", "--find-renames", "--no-color"];
```

Reviews (1): Last reviewed commit: "fix(git): pass --no-ext-diff when synthe..." | Re-trigger Greptile

iscoolkettan and others added 3 commits May 9, 2026 20:21
A user-configured diff.external (e.g. difftastic, delta) replaced git's
unified-diff output for the synthetic untracked-file patch, leaving Pierre
nothing to parse and crashing `hunk diff` with "Expected one parsed file
for untracked patch ..., got 0". The other git invocations already pass
--no-ext-diff for this exact reason; the untracked path just missed it.
@benvinegar benvinegar force-pushed the fix-untracked-no-ext-diff branch from a804c81 to 298498d Compare May 10, 2026 00:28
@benvinegar
Copy link
Copy Markdown
Member

Addressed the Greptile note by making hunk stash show pass --no-ext-diff too, so all Git-backed patch-producing paths now explicitly avoid external diff tools. I also adjusted the existing untracked-file regression to avoid the Unix-only /usr/bin/true command.

This comment was generated by Pi using OpenAI GPT-5

@benvinegar benvinegar merged commit cac04aa into modem-dev:main May 10, 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.

3 participants