Skip to content

[Git] Add DiffUntracked to render untracked file contents - #41

Merged
KCaverly merged 1 commit into
mainfrom
ct/diff_view/303beec7
Jul 26, 2026
Merged

[Git] Add DiffUntracked to render untracked file contents#41
KCaverly merged 1 commit into
mainfrom
ct/diff_view/303beec7

Conversation

@KCaverly

@KCaverly KCaverly commented Jul 26, 2026

Copy link
Copy Markdown
Owner

The diff viewer lists untracked files by name in its file index but shows
nothing of what is in them, because git diff HEAD never reports a file git
isn't tracking. For a brand-new file that leaves the most interesting part
invisible — the contents are the whole change.

DiffUntracked diffs each path against os.DevNull with git diff --no-index,
which renders it as a whole-file addition beneath an ordinary diff --git
header. That shape matters: the diff builder indexes those headers for its
file-jump keys and colours the + lines, so new files behave like tracked ones
with no styler changes. Binary files collapse to git's one-line notice rather
than inlining their bytes.

--no-index follows diff(1) and signals "the inputs differ" with exit 1, which
Git treats as failure. Rather than a second runner, Git now delegates to an
internal git() that takes one forgivable exit code; -1 (accept only 0) keeps
every existing caller's behaviour byte-identical. Only an ExitError is
forgiven, so a timeout or a missing binary still fails.

Per-path errors are skipped rather than propagated. An untracked file is by
definition outside git's control and can vanish between the status call that
listed it and this one; losing every other file's diff to that race would be
the wrong trade.

Caller-driven path list: each file costs a subprocess, so the cap belongs
with the caller that knows what it is willing to render.

Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com


Stack (bottom → top):

  1. [Git] Add DiffUntracked to render untracked file contents #41 ← this PR
  2. [UI] Show uncommitted work as a row in the stack #42
  3. [UI] Name one way out of the stack preview #43
  4. [UI] Give d the preview and esc the way out #44
  5. [UI] Drop the branch-diff jump from the stack screen #45
  6. [UI] Stop the stack preview overrunning a narrow terminal #46
  7. [Git] Pin the diff flags the body parser depends on #47
  8. [UI] Teach both diff viewers the same file-jump key #48
  9. [Diff] Thread the [diff] config through the viewer and zoom with z #49
  10. [Git] Carry diff args and excludes through every diff call #50
  11. [Diff] Add the external diff pager package #51
  12. [Config] Accept a [diff] section with an optional pager #52
  13. [Docs] Document the diff viewer settings #53

The diff viewer lists untracked files by name in its file index but shows
nothing of what is in them, because `git diff HEAD` never reports a file git
isn't tracking. For a brand-new file that leaves the most interesting part
invisible — the contents are the whole change.

DiffUntracked diffs each path against os.DevNull with `git diff --no-index`,
which renders it as a whole-file addition beneath an ordinary `diff --git`
header. That shape matters: the diff builder indexes those headers for its
file-jump keys and colours the + lines, so new files behave like tracked ones
with no styler changes. Binary files collapse to git's one-line notice rather
than inlining their bytes.

--no-index follows diff(1) and signals "the inputs differ" with exit 1, which
Git treats as failure. Rather than a second runner, Git now delegates to an
internal git() that takes one forgivable exit code; -1 (accept only 0) keeps
every existing caller's behaviour byte-identical. Only an ExitError is
forgiven, so a timeout or a missing binary still fails.

Per-path errors are skipped rather than propagated. An untracked file is by
definition outside git's control and can vanish between the status call that
listed it and this one; losing every other file's diff to that race would be
the wrong trade.

Caller-driven path list: each file costs a subprocess, so the cap belongs
with the caller that knows what it is willing to render.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ct-stack-id: 303beec7
@KCaverly
KCaverly force-pushed the ct/diff_view/303beec7 branch from 8644387 to 88bf444 Compare July 26, 2026 19:30
@KCaverly
KCaverly merged commit d150484 into main Jul 26, 2026
2 checks passed
@KCaverly
KCaverly deleted the ct/diff_view/303beec7 branch July 26, 2026 19:32
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