Skip to content

feat: add untracked/staged file support (u toggle + s stage/unstage) - #55

Closed
sanchesfree wants to merge 4 commits into
umputun:masterfrom
sanchesfree:feature/new-file-and-untracked-support
Closed

sanchesfree wants to merge 4 commits into
umputun:masterfrom
sanchesfree:feature/new-file-and-untracked-support

Conversation

@sanchesfree

Copy link
Copy Markdown
Contributor

Hi! First off — apologies if this falls outside the original vision for revdiff. I might be misunderstanding the concept, but man, I really missed being able to browse untracked files and stage/unstage them right from the TUI. Like, a lot. So here we go.

What this adds

u — toggle untracked files in the tree

Press u to show/hide untracked files (from git ls-files --others --exclude-standard) alongside changed files in the file tree. Untracked files get a ? prefix, staged files get a + prefix.

s — stage / unstage the selected file

  • s on an untracked file → git add
  • s on a file you staged via revdiff → git restore --staged
  • No-op on regular changed files (those already have a diff)

Staged-only files (auto-discovered)

Files that exist in git diff --cached but have no unstaged changes are automatically included in the tree (not gated behind the u toggle). These are real working changes, not "untracked."

Other bits

  • Untracked/staged files render as all-added lines (green +) since there's no previous version to diff against
  • Navigating away from an untracked/staged file and back works correctly (no more "no changes" after round-trip)
  • ? mode icon in the status bar when untracked files are visible
  • [s] stage / [s] unstage hint in the status bar when cursor is on an applicable file
  • "no untracked files" hint when u is on but none exist
  • Fallback to ReadFileAsAdded for files with empty diff (covers both untracked and staged-only)

Interface changes

  • Added UntrackedFiles() to the ui.Renderer interface (and internal diff.renderer)
  • Added ReadFileAsAdded() to diff package for reading files as all-added DiffLines
  • UntrackedFiles() implemented on all renderers: Git, FallbackRenderer, FileReader, DirectoryReader, ExcludeFilter, StdinReader

Testing

17 new tests covering toggle, fetchStagedOnly, handleStaged (duplicates, unstage, preserves others), handleStage guards, handleFileLoaded fallback, and error handling. UI coverage: 93.5%.

Keybindings

Key Action
u toggle untracked files
s stage / unstage selected file

Both are configurable via ~/.config/revdiff/keybindings.

Let me know if this is useful or if I'm totally off base with the direction. Happy to adjust!

@sanchesfree
sanchesfree requested a review from umputun as a code owner April 7, 2026 14:11
@sanchesfree
sanchesfree force-pushed the feature/new-file-and-untracked-support branch from d1f2c45 to 34e7340 Compare April 7, 2026 18:47
Rebased on upstream/master with FileEntry API adaptation.

- u toggle shows/hides untracked files in file tree
- s key stages untracked files / unstages staged-by-revdiff files
- Added UntrackedFiles() to Renderer interface and all implementations
- Added ReadFileAsAdded for rendering untracked/staged files as all-added lines
- Fallback in handleFileLoaded for untracked/staged files with empty diff
- Status bar shows ? icon when untracked mode active
@sanchesfree
sanchesfree force-pushed the feature/new-file-and-untracked-support branch from 7c6a740 to 6150d92 Compare April 7, 2026 19:30

@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 effort, I can see this is well-tested with solid code quality. however, I can't merge this for a few reasons.

revdiff is a read-only review tool. adding git add and git restore --staged turns it into a staging tool, which is a different category. I don't want revdiff to mutate git state, the whole point is it's safe to run on any repo without side effects.

issue #48 is already fixed in ce35fb0 - the detect-ref script handles fresh repos and falls back to --all-files mode. the user just needs to git add first, which is the normal workflow anyway.

interface pollution - UntrackedFiles() forced onto all 6 Renderer implementations when only Git has real logic, the rest return nil, nil.

I appreciate the work, especially the test coverage. if showing untracked files turns out to be needed, it's a ~20 line change to DirectoryReader, not a 1000+ line feature with git mutations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wontfix This will not be worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants