fix(git): refresh status when branch ref changes#2249
Conversation
Greptile SummaryThis PR fixes the diff-view git status not refreshing when an external commit advances the current workspace branch ref (e.g., another workspace or tool pushes to the same branch). It introduces a new
Confidence Score: 4/5The production change is small and well-contained; the main gap is test coverage for two edge-case branches the handler already handles correctly in code. The new event listener's filter logic is sound — it correctly falls back to reloading when changedRefs is absent (packed-refs scenario) and when no branch is known (detached HEAD / initial load). The tests cover the core happy path and the 'different branch' no-op, but the absent-changedRefs fallback and workspace-ID scoping guard are untested, leaving those paths open to silent regression. The test file (git-store.test.ts) would benefit from two additional cases: a changedRefs-absent event and a same-branch event scoped to a different workspace.
|
| Filename | Overview |
|---|---|
| src/renderer/features/tasks/diff-view/stores/git-store.ts | Adds a new gitRefChangedChannel event listener that filters by project, optional workspace, event kind, and the current branch ref to trigger status reloads only when the workspace's active branch changes. |
| src/renderer/features/tasks/diff-view/stores/git-store.test.ts | New test file covering the happy-path reload and the 'different branch' no-op case; missing coverage for the absent-changedRefs fallback and workspace-scoped event filtering. |
Sequence Diagram
sequenceDiagram
participant FS as File System Watcher
participant BE as Backend / Main Process
participant CH as gitRefChangedChannel
participant GS as GitStore (renderer)
participant RPC as rpc.git.getFullStatus
FS->>BE: ".git/refs/heads/<branch> changed"
BE->>CH: "emit { projectId, kind: 'local-refs', changedRefs: [localRef(branch)] }"
CH->>GS: handler receives payload
GS->>GS: filter: projectId match?
GS->>GS: filter: workspaceId match (if present)?
GS->>GS: "filter: kind === 'local-refs'?"
GS->>GS: filter: changedRef matches currentBranch?
alt ref matches current branch (or changedRefs absent)
GS->>GS: debounce 500ms → handler()
GS->>RPC: getFullStatus(projectId, workspaceId)
RPC-->>GS: FullGitStatus (updated staged/unstaged)
GS->>GS: fullStatus.data updated → UI re-renders
else ref is for a different branch
GS->>GS: return (no reload)
end
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
src/renderer/features/tasks/diff-view/stores/git-store.test.ts:99-165
**Missing test for absent `changedRefs` fallback**
The `GitRefChange` type explicitly documents that `changedRefs` is absent for packed-refs changes and bare HEAD pointer changes. The new handler correctly falls through to `handler()` in that case (because `payload.changedRefs &&` is falsy), but this path has no test. A packed-refs write that advances the current branch would silently fail to trigger a reload if the fallback logic were accidentally broken.
### Issue 2 of 2
src/renderer/features/tasks/diff-view/stores/git-store.test.ts:99-165
**Missing test for workspace-scoped event filtering**
The handler guards `payload.workspaceId !== undefined && payload.workspaceId !== this.workspaceId` to drop events belonging to a different workspace. Neither test exercises this path — both payloads omit `workspaceId` entirely (project-level event). A test with `workspaceId: 'workspace-other'` would confirm the filter actually prevents a spurious reload.
Reviews (1): Last reviewed commit: "fix(git): refresh status when branch ref..." | Re-trigger Greptile
No description provided.