fix(vcs): reflect external git changes in status via .git watcher#2987
fix(vcs): reflect external git changes in status via .git watcher#2987denniskasper wants to merge 1 commit into
Conversation
VCS status was only re-read on window focus / visibilitychange and after app-initiated git actions, so a branch switch or checkout made in a terminal (or another git client) was not reflected in the UI until the window regained focus. Add a filesystem watcher on the checkout's git directory (HEAD / packed-refs, resolving the worktree gitdir when .git is a file) that pushes a fresh local status on change, debounced so one operation triggers a single refresh. The watcher is ref-counted alongside the existing remote-status poller and torn down with the last subscriber. Related to pingdotgg#2926. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Needs human review Introduces new runtime behavior by adding filesystem watchers on .git directory to detect external git changes. New features that add continuous background behavior (file watching with side effects) warrant human review. You can customize Macroscope's approvability policy. Learn more. |
What Changed
Added a filesystem watcher on the checkout's git directory in
VcsStatusBroadcaster. WhenHEAD/packed-refschange on disk, it pushes a fresh local status (debounced so one operation = one refresh). It resolves the worktree gitdir when.gitis a file, and is ref-counted alongside the existing remote-status poller (torn down with the last subscriber). Includes an end-to-end test.Why
VCS status was only re-read on window
focus/visibilitychangeand after app-initiated git actions. So a branch switch or checkout done in a terminal (or another git client) wasn't reflected in the UI until the window regained focus. This is the root cause behind the stale-branch-list symptom in #2926 — the watcher resyncs automatically, so no manual refresh button is needed.Related to #2926.
UI Changes
No markup change — behavioral. Observable effect: after a terminal
git switch, the branch toolbar/list updates on its own instead of only after refocusing the window.Checklist
Note
Refresh VCS local status when
.gitdirectory changes on disk.gitdirectory (or linked worktree gitdir) inVcsStatusBroadcasterthat triggersrefreshLocalStatuswhenHEADorpacked-refschange..gitfile to resolve the actual gitdir path.ActiveRemotePollernow tracks two fibers; both are interrupted on teardown instead of only the remote polling fiber.Macroscope summarized 9cc0017.
vcs-status-live-update-external-git-switch.webm
Note
Medium Risk
Adds long-lived
fs.watchfibers tied to VCS status streaming lifecycle; incorrect gitdir resolution or watch teardown could miss updates or leak watchers, but scope is limited to local status refresh.Overview
VcsStatusBroadcasternow watches the checkout’s git metadata directory (.gitor a linked worktreegitdir) and callsrefreshLocalStatuswhenHEADorpacked-refschange on disk, so terminalgit switch/ checkout updates the UI without waiting for window focus.Watch events are debounced (150ms) to collapse multi-file git writes into one refresh. The watch runs in a second fiber started with the existing remote poller on first
streamStatussubscriber; both fibers are interrupted when the last subscriber disconnects.Adds a live
it.livetest that rewrites.git/HEADin a temp repo and asserts alocalUpdatedstream event.Reviewed by Cursor Bugbot for commit 9cc0017. Bugbot is set up for automated code reviews on this repo. Configure here.