fix(explorer): clear dir_status on git refresh so committed files under a new folder don't stay untracked - #2934
Open
OsoRojo wants to merge 1 commit into
Open
Conversation
The _update reset clears each node's status and ignored but not dir_status, so a file committed under a previously-untracked folder keeps inheriting the folder's stale "??" and shows as untracked until restart. Clear dir_status too so it is re-derived from git status on each refresh.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(explorer): clear
dir_statuson git refresh so committed files under a new folder don't stay "untracked"What
In the explorer, a file added inside a folder git hasn't tracked yet keeps the untracked (
?) marker after it has been committed, even thoughgit statusreports it clean. The stale marker survivesexplorer_update(u) and only clears on a full restart.This is a small state bug and is distinct from the known "explorer doesn't auto-detect external git changes" reports (#1630 / #2030 / discussion #2509) — see Not this bug below. It reproduces with a fully in-editor workflow.
Repro (deterministic)
In any repo with at least one commit:
note.mdshows untracked?✅git add, lazygit, …) → shows staged ✅?untracked, thoughgit statusis clean ❌It persists through
u/ refresh and clears only on restart. It does not happen for a file at the repo root, or in a folder that already contains a tracked file — that asymmetry is the tell.Root cause
git status --porcelaincollapses an untracked directory to a single entry,?? newfolder/— it never listsnewfolder/note.mdindividually. Inlua/snacks/explorer/git.lua,M._updaterecords that on the directory node asn.dir_status = s.status("??").The per-refresh reset walk clears each node's
statusandignored, but notdir_status:Because
Tree:childreuses nodes,dir_statussticks for the session, and a file with nostatusof its own inheritsparent.dir_statusfor display (lua/snacks/picker/source/explorer.lua). Instrumenting the real modules through the lifecycle:Before (current
main):At
commit, the file's own status correctly clears, but it falls back to the folder's staledir_status.Fix
Clear
dir_statusin the same reset walk, so it's re-derived from the currentgit statuson each refresh:Tree:walk(node, function(n) n.status = nil n.ignored = nil + n.dir_status = nil end, { all = true })After:
The legitimate untracked-folder display still works (re-derived from the live
?? newfolder/), staging shows staged, and commit correctly shows clean.Not this bug (to avoid conflation)
This is not the "explorer doesn't update when git state changes outside the explorer" issue (#1630, #2030, discussion #2509). That one is about detecting external changes and is worked around with
u/ aFocusGainedautocmd / the tab-switch refresh (#2348). This bug is a stale field that survivesu— which is exactly why several people in #2509 (e.g. @metal3d, @redoxahmii) report thatudoesn't help them and only a restart does.Environment
882c996(currentmain)