Skip to content

fix(diff): refresh stale git diff models#2501

Open
janburzinski wants to merge 1 commit into
mainfrom
jan/eng-1579-code-editor-diff-is-out-of-sync-with-sidebar-diff
Open

fix(diff): refresh stale git diff models#2501
janburzinski wants to merge 1 commit into
mainfrom
jan/eng-1579-code-editor-diff-is-out-of-sync-with-sidebar-diff

Conversation

@janburzinski

Copy link
Copy Markdown
Collaborator

Description

  • fix code editor showing already commited diff
  • invalidate head based monaco models on local ref changes

Screenshot/Recording (if applicable)

https://streamable.com/z06c7i

Checklist
  • I kept this PR small and focused
  • I ran a self-review before opening this PR
  • I ran the relevant local checks or explained why not
  • I updated docs when behavior or setup changed
  • I added or updated tests when behavior changed, or explained why not
  • I only added comments where the logic is not obvious
  • I used Conventional Commits for commit
    messages and, when possible, the PR title

@greptile-apps

greptile-apps Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes stale git diff content in the Monaco editor by addressing two distinct root causes: a long-lived git cat-file --batch process that caches the in-core index (so :0:<path> reads go stale after git add/git commit), and HEAD-based Monaco models that were never invalidated when a commit moved the local branch ref without touching the worktree HEAD file.

  • git-service.ts: getFileAtIndex now spawns a fresh one-shot git cat-file blob :0:<path> process instead of routing through the persistent batch channel, guaranteeing the staged content is always up-to-date.
  • invalidation-bridges.ts: Adds a local-refs branch that proactively invalidates all HEAD-based Monaco models whenever a local ref changes, covering the gap left by the missing workspace-level head event on commits.

Confidence Score: 5/5

Safe to merge — both changes are tightly scoped, well-commented, and address distinct root causes of the stale diff bug without touching any shared state or auth paths.

The getFileAtIndex change correctly avoids the persistent cat-file batch channel (whose in-core index cache is the root cause of stale staged content) and the raw-stdout return is consistent with what the primary cat-file batch path already returned. The invalidation bridge change fills a real gap: commits advance the branch ref but never update the worktree HEAD file, so HEAD models were never refreshed — the new local-refs block handles exactly that case. Double-invalidation when changedRefs is also populated is harmless since invalidateModel is idempotent.

No files require special attention.

Important Files Changed

Filename Overview
apps/emdash-desktop/src/main/core/git/impl/git-service.ts Replaces the persistent cat-file batch channel with a one-shot git cat-file blob invocation for index reads; also removes stripTrailingNewline, which is consistent with the raw output already returned by the primary cat-file batch path.
apps/emdash-desktop/src/renderer/lib/monaco/invalidation-bridges.ts Adds HEAD model invalidation on local-refs events; falls through cleanly to the existing changedRefs processing, resulting in harmless double-invalidation for specific branch refs on the same event.

Sequence Diagram

sequenceDiagram
    participant User as User (commits)
    participant GitSvc as GitService
    participant CatFileBatch as CatFile Batch (persistent)
    participant OneShot as git cat-file blob (one-shot)
    participant Events as Event Bus
    participant Bridge as InvalidationBridge
    participant Registry as MonacoModelRegistry

    Note over User,Registry: Before fix — stale index read
    User->>GitSvc: getFileAtIndex(path)
    GitSvc->>CatFileBatch: :0:path (cached in-core index)
    CatFileBatch-->>GitSvc: stale staged content

    Note over User,Registry: After fix — fresh index read
    User->>GitSvc: getFileAtIndex(path)
    GitSvc->>OneShot: git cat-file blob :0:path
    OneShot-->>GitSvc: current staged content

    Note over User,Registry: HEAD model invalidation on commit
    User->>Events: commit (local ref changes)
    Events->>Bridge: "gitRefChanged { kind: local-refs }"
    Bridge->>Registry: "findGitUris({ projectId, ref: HEAD })"
    Registry-->>Bridge: HEAD model URIs
    Bridge->>Registry: invalidateModel(uri) for each
    Registry->>GitSvc: getFileAtRef(path, HEAD)
    GitSvc->>CatFileBatch: HEAD:path (dynamic, not cached)
    CatFileBatch-->>GitSvc: fresh HEAD content
Loading

Reviews (1): Last reviewed commit: "fix(diff): refresh stale git diff models" | Re-trigger Greptile

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