Skip to content

git: Rescan repositories when window regains focus#48704

Closed
lex00 wants to merge 1 commit intozed-industries:mainfrom
lex00:fix/git-rescan-on-window-activation
Closed

git: Rescan repositories when window regains focus#48704
lex00 wants to merge 1 commit intozed-industries:mainfrom
lex00:fix/git-rescan-on-window-activation

Conversation

@lex00
Copy link
Copy Markdown
Contributor

@lex00 lex00 commented Feb 7, 2026

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 from Workspace::on_window_activation_changed when the window becomes active. This triggers schedule_scan() for all repositories, running a full git status . on a background thread.

Performance

schedule_scan uses keyed job deduplication (GitJobKey::ReloadGitState), so rapid window switches collapse into one scan. In large monorepos git status can 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: new reload_repositories() method
  • workspace.rs: call it on window activation
  • git_panel.rs: test

Test plan

  • New: test_git_panel_updates_on_reload_repositories sets up git panel, changes git status without firing events (simulating lost FSEvents), calls reload_repositories, verifies panel updates
  • All 12 existing git panel tests pass
  • clippy clean

Release Notes:

  • Fixed an issue where the git panel could show stale branch and file status after switching back from a terminal or after sleep/wake.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 7, 2026
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>
@lex00 lex00 force-pushed the fix/git-rescan-on-window-activation branch from c9b05bf to bac9aad Compare February 13, 2026 19:01
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
@lex00 lex00 closed this Mar 1, 2026
@lex00 lex00 deleted the fix/git-rescan-on-window-activation branch March 1, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Git panel shows stale status after switching back from terminal or sleep/wake

2 participants