Skip to content

feat: show untracked and staged-only files in file tree (u toggle) - #62

Merged
umputun merged 11 commits into
umputun:masterfrom
sanchesfree:feature/new-file-and-untracked-support
Apr 8, 2026
Merged

umputun merged 11 commits into
umputun:masterfrom
sanchesfree:feature/new-file-and-untracked-support

Conversation

@sanchesfree

@sanchesfree sanchesfree commented Apr 8, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #55, rewritten to address all feedback.

What changed from #55

  • No git mutations — no git add, git restore --staged, or staging of any kind. revdiff stays read-only.
  • No interface pollution — UntrackedFiles() lives only on *Git, injected via ModelConfig.LoadUntracked callback. No changes to Renderer interface or other implementations.
  • ~130 lines vs 1000+ in the original PR.

What this adds

  • u key — toggle untracked files in the file tree
  • ? status icon — shown next to untracked files (green, same style as A)
  • Staged-only files — new files that are git added but not committed now appear automatically (they were missing because git diff without --cached skips them)
  • Untracked file content — shown as all-added lines (green +) since there is no git diff for untracked files

Why staged-only files matter

When an AI agent (or a user) runs git add on new files before reviewing, those files become invisible in revdiff. git diff (working tree vs index) skips files that are identical in both — which is exactly the state after git add with no further edits. Previously you had to run revdiff with --staged to see them, but then you would lose unstaged changes. Now both are visible at once.

Files changed (8, +131 -13)

  • app/diff/diff.go — UntrackedFiles() on *Git, FileUntracked status
  • app/diff/fallback.go — ReadFileAsAdded() helper for showing untracked file content
  • app/keymap/keymap.go — ActionToggleUntracked, u binding
  • app/main.go — wire LoadUntracked callback from *Git instance
  • app/ui/model.go — toggle logic, staged-only merge, untracked fallback in handleFileLoaded
  • app/ui/styles.go — StatusUntracked style

@sanchesfree
sanchesfree requested a review from umputun as a code owner April 8, 2026 04:41
@umputun
umputun requested a review from Copilot April 8, 2026 05:00

@umputun umputun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx for the rewrite, much cleaner than #55. couple things to address before merge:

  1. missing tests - no tests for UntrackedFiles(), ReadFileAsAdded(), staged-only merge logic, or the toggle cycle. the project has thorough test coverage for comparable features (FallbackRenderer, blame toggle, wrap toggle all have dedicated tests), so this needs to match

  2. ReadFileAsAdded inconsistent with readFileAsContext (fallback.go) - missing broken-symlink handling and error wrapping that its sibling function has in the same file. pls align

  3. silently swallowed errors (model.go:234, 249) - both ChangedFiles("", true) and loadUntracked() failures are completely ignored. at minimum log them

  4. handleFileLoaded fallback too broad (model.go:812-816) - len(m.diffLines) == 0 && m.workDir != "" triggers for any file with empty diff, not just untracked. should check the file's status is FileUntracked

  5. no dedup between untracked and staged-only (model.go:235-254) - if a file appears in both git diff --cached and git ls-files --others, it could show twice in the tree

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for surfacing untracked files (toggleable via u) and “staged-only” files in the TUI file tree, plus a fallback rendering path for files without a git diff, while keeping the app read-only.

Changes:

  • Add git untracked file discovery (git ls-files --others --exclude-standard) and a ? file status.
  • Extend UI model/file loading to merge staged-only entries and optionally append untracked entries; add “read file as all-added” fallback rendering.
  • Add keybinding/action for toggling untracked files and style support for the new status icon.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
app/diff/diff.go Adds FileUntracked status and (*Git).UntrackedFiles() implementation.
app/diff/fallback.go Introduces ReadFileAsAdded() helper for rendering file contents as added lines.
app/keymap/keymap.go Adds ActionToggleUntracked and binds it to u with help text.
app/keymap/keymap_test.go Updates default binding expectations to include u.
app/main.go Wires *diff.Git’s untracked listing into ui.ModelConfig.
app/ui/filetree.go Adds restoreReviewed to preserve reviewed marks across tree rebuilds.
app/ui/model.go Implements untracked toggle + staged-only merge + empty-diff fallback and status bar ? mode icon.
app/ui/model_test.go Adjusts a status bar truncation test width expectation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/ui/model.go Resolved
Comment thread app/ui/model.go Resolved
Comment thread app/diff/fallback.go Resolved
Comment thread app/ui/filetree.go Resolved
Comment thread app/ui/model.go Resolved

@umputun umputun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx for the thorough update, all 5 items from my review are addressed. two more things from copilot's review that are worth fixing:

  1. staged-only merge too broad (model.go:248) - currently appends all staged entries not in the unstaged list, including staged-deleted or staged-renamed files. those get loaded with staged=false later, producing empty diffs. pls restrict to FileAdded only, which matches the intent ("new files added to index")

  2. restoreReviewed is O(n*m) (filetree.go:374) - slices.Contains(ft.allFiles, path) in a loop. build a map of ft.allFiles first for O(1) lookups

1. Add tests for UntrackedFiles, ReadFileAsAdded, toggle cycle,
   staged-only merge, dedup, and gated untracked fallback
2. Align ReadFileAsAdded with readFileAsContext: broken symlink
   handling, non-regular file placeholder, error wrapping
3. Log staged/untracked fetch failures as warnings instead of
   silently ignoring them
4. Gate handleFileLoaded disk fallback to FileUntracked status only
5. Dedup untracked files against existing entries (staged + unstaged)
@sanchesfree
sanchesfree force-pushed the feature/new-file-and-untracked-support branch from 37970d6 to 05c9ac4 Compare April 8, 2026 05:36

@umputun umputun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all 7 items from both rounds are addressed, thx for the thorough rework. tests pass, lint clean, race detector clean.

couple minor things I noticed:

  1. ReadFileAsAdded error silently ignored (model.go:846) - when the fallback disk read fails (permission denied, etc.), error is discarded and user sees empty content with no indication. other error paths in this PR properly log via warnings, so this one stands out. pls add a log.Printf("[WARN] ...") for consistency

  2. no broken symlink test for ReadFileAsAdded (fallback.go:272-274) - code handles broken symlinks correctly, but unlike the sibling readFileAsContext there's no test for that path. not a blocker but would be nice for completeness

@sanchesfree

Copy link
Copy Markdown
Contributor Author

thanks for the thorough reviews across all rounds — every point is addressed. appreciate the patience and the high bar for code quality.

@umputun umputun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, all addressed

@umputun
umputun merged commit 490d066 into umputun:master Apr 8, 2026
1 check passed
sanchesfree added a commit to sanchesfree/revdiff that referenced this pull request Apr 8, 2026
…mputun#62)

* feat: add u toggle to show/hide untracked files in file tree

Read-only implementation — no git mutations, no interface pollution.
- UntrackedFiles() added only to *Git, exposed via ModelConfig.LoadUntracked callback
- u key toggles untracked file visibility in tree
- ? icon shown in status bar when active

* fix: show untracked file contents as all-added lines, clear diff on empty tree

* feat: always show staged-only files (new files added to index)

* fix: preserve file selection when toggling untracked files

* feat: show ? status icon for untracked files in file tree

* fix: use m.diffLines for highlighting after untracked fallback, wrap errors

* fix: preserve reviewed marks when toggling untracked files

* fix: save reviewed marks BEFORE rebuilding tree, not after

* address review feedback: tests, error handling, dedup, gated fallback

1. Add tests for UntrackedFiles, ReadFileAsAdded, toggle cycle,
   staged-only merge, dedup, and gated untracked fallback
2. Align ReadFileAsAdded with readFileAsContext: broken symlink
   handling, non-regular file placeholder, error wrapping
3. Log staged/untracked fetch failures as warnings instead of
   silently ignoring them
4. Gate handleFileLoaded disk fallback to FileUntracked status only
5. Dedup untracked files against existing entries (staged + unstaged)

* restrict staged-only merge to FileAdded, O(1) restoreReviewed

* log untracked fallback read errors, add broken symlink test for ReadFileAsAdded
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