fix: ensure WorkingCopy refreshes after commit
#1899
Closed
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.
In some cases,
WorkingCopyview fails to refresh after commit due to a race condition betweenFileSystemWatcher, manual refresh calls, and theIsChangedoptimization inSetData().Problem analysis by Claude:
Problem
After committing changes, the staged/unstaged files in WorkingCopy view sometimes remain visible instead of being cleared, even when manually calling
RefreshAll().Root Cause
This is caused by a race condition between multiple asynchronous refresh mechanisms:
LockWatcher()prevents FileSystemWatcher from processing git file changesMarkBranchesDirtyManually()is called, which:MarkBranchUpdated()setting_updateBranch = 0RefreshWorkingCopyChanges()asynchronouslyWorkingCopy._cachedhappens to also be empty (from a previous refresh)SetData()checksIsChanged(_cached, changes)which returnsfalsefor([], [])This timing issue is difficult to reproduce consistently but happens when:
_cachedstate happens to match the new query resultSolution
Call
MarkWorkingCopyDirtyManually()after commit to ensure WorkingCopy refresh is properly triggered:This additional call:
_updateWC = 0) to clear any pending delayed refreshRefreshWorkingCopyChanges()taskTesting
The issue is hard to reproduce consistently due to timing dependencies, but the fix: