git: Rescan repositories when window regains focus#48704
Closed
lex00 wants to merge 1 commit intozed-industries:mainfrom
Closed
git: Rescan repositories when window regains focus#48704lex00 wants to merge 1 commit intozed-industries:mainfrom
lex00 wants to merge 1 commit intozed-industries:mainfrom
Conversation
When Zed is backgrounded or the laptop sleeps while external git operations happen (branch switches, rebases, file modifications), FSEvents can be lost and the git panel stays permanently stale. Trigger a full git status rescan for all repositories when the window becomes active. schedule_scan uses keyed job deduplication so rapid window switches don't cause redundant scans. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
c9b05bf to
bac9aad
Compare
pcfreak30
added a commit
to pcfreak30/zed
that referenced
this pull request
Feb 13, 2026
Applied 5 PRs to fix Zed getting out of sync with filesystem changes: - zed-industries#48691: Include file size in DiskState to fix stale buffer reload - zed-industries#48695: Map EventKind::Other to Changed instead of None - zed-industries#48698: Reload after undo when file changed while dirty - zed-industries#48704: Rescan repositories when window regains focus - zed-industries#47462: Handle removed Linux watch paths
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.
Fixes #48703
Related to #38109, #13176
Problem
The git panel can show stale branch and file status after switching back from a terminal where you ran git commands (checkout, rebase, reset, stash pop). Same thing happens after laptop sleep/wake.
Git state only refreshes when Zed sees changes inside
.git/via filesystem events. If those events are lost, stale state persists indefinitely. No manual refresh, no periodic rescan.Approach
This is a safety net, not a targeted fix for a specific event-loss path. We can't reliably prove which FSEvents get dropped during sleep/wake or heavy IO, but we can make sure the git panel recovers when the user comes back to Zed.
Add
reload_repositories()to GitStore, called fromWorkspace::on_window_activation_changedwhen the window becomes active. This triggersschedule_scan()for all repositories, running a fullgit status .on a background thread.Performance
schedule_scanuses keyed job deduplication (GitJobKey::ReloadGitState), so rapid window switches collapse into one scan. In large monoreposgit statuscan be slow (see #43861). If this turns out to be a problem, a cooldown or debounce could be added, but the dedup already prevents the worst case.Changes
3 files, ~20 lines of production code:
git_store.rs: newreload_repositories()methodworkspace.rs: call it on window activationgit_panel.rs: testTest plan
test_git_panel_updates_on_reload_repositoriessets up git panel, changes git status without firing events (simulating lost FSEvents), callsreload_repositories, verifies panel updatesRelease Notes: