Repository navigation
feat: show untracked and staged-only files in file tree (u toggle) - #62
Conversation
umputun
left a comment
There was a problem hiding this comment.
thx for the rewrite, much cleaner than #55. couple things to address before merge:
-
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 -
ReadFileAsAddedinconsistent withreadFileAsContext(fallback.go) - missing broken-symlink handling and error wrapping that its sibling function has in the same file. pls align -
silently swallowed errors (model.go:234, 249) - both
ChangedFiles("", true)andloadUntracked()failures are completely ignored. at minimum log them -
handleFileLoadedfallback 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 isFileUntracked -
no dedup between untracked and staged-only (model.go:235-254) - if a file appears in both
git diff --cachedandgit ls-files --others, it could show twice in the tree
There was a problem hiding this comment.
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.
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
umputun
left a comment
There was a problem hiding this comment.
thx for the thorough update, all 5 items from my review are addressed. two more things from copilot's review that are worth fixing:
-
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=falselater, producing empty diffs. pls restrict toFileAddedonly, which matches the intent ("new files added to index") -
restoreReviewedis O(n*m) (filetree.go:374) -slices.Contains(ft.allFiles, path)in a loop. build a map offt.allFilesfirst 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)
37970d6 to
05c9ac4
Compare
umputun
left a comment
There was a problem hiding this comment.
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:
-
ReadFileAsAddederror 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 alog.Printf("[WARN] ...")for consistency -
no broken symlink test for
ReadFileAsAdded(fallback.go:272-274) - code handles broken symlinks correctly, but unlike the siblingreadFileAsContextthere's no test for that path. not a blocker but would be nice for completeness
|
thanks for the thorough reviews across all rounds — every point is addressed. appreciate the patience and the high bar for code quality. |
…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
Follow-up to #55, rewritten to address all feedback.
What changed from #55
git add,git restore --staged, or staging of any kind. revdiff stays read-only.UntrackedFiles()lives only on*Git, injected viaModelConfig.LoadUntrackedcallback. No changes toRendererinterface or other implementations.What this adds
ukey — toggle untracked files in the file tree?status icon — shown next to untracked files (green, same style asA)git added but not committed now appear automatically (they were missing becausegit diffwithout--cachedskips them)+) since there is no git diff for untracked filesWhy staged-only files matter
When an AI agent (or a user) runs
git addon 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 aftergit addwith no further edits. Previously you had to run revdiff with--stagedto 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,FileUntrackedstatusapp/diff/fallback.go—ReadFileAsAdded()helper for showing untracked file contentapp/keymap/keymap.go—ActionToggleUntracked,ubindingapp/main.go— wireLoadUntrackedcallback from*Gitinstanceapp/ui/model.go— toggle logic, staged-only merge, untracked fallback inhandleFileLoadedapp/ui/styles.go—StatusUntrackedstyle