Skip to content

fix(git): refresh status when branch ref changes#2249

Merged
jschwxrz merged 2 commits into
mainfrom
fix-stale-files-in-staged-section
May 27, 2026
Merged

fix(git): refresh status when branch ref changes#2249
jschwxrz merged 2 commits into
mainfrom
fix-stale-files-in-staged-section

Conversation

@jschwxrz
Copy link
Copy Markdown
Collaborator

No description provided.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 27, 2026

Greptile Summary

This 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 gitRefChangedChannel event subscription that filters by project, optional workspace scope, event kind, and the active branch name before triggering a reload.

  • git-store.ts: Adds a fourth event strategy to fullStatus's Resource that listens to gitRefChangedChannel, skips events for other projects/workspaces, and only reloads when the changed ref matches the currently checked-out branch (or falls back to always-reload when changedRefs is absent or no branch is known).
  • git-store.test.ts: New test file covering the happy-path reload and the "irrelevant branch" no-op case; the absent-changedRefs fallback and workspace-scoped filtering paths are not yet tested.

Confidence Score: 4/5

The 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.

Important Files Changed

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
Loading
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

Comment thread src/renderer/features/tasks/diff-view/stores/git-store.test.ts
Comment thread src/renderer/features/tasks/diff-view/stores/git-store.test.ts
@jschwxrz jschwxrz merged commit 3c61cd7 into main May 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant