diff --git a/apps/emdash-desktop/src/main/core/git/impl/git-service.ts b/apps/emdash-desktop/src/main/core/git/impl/git-service.ts index bd2171739..d77b57de2 100644 --- a/apps/emdash-desktop/src/main/core/git/impl/git-service.ts +++ b/apps/emdash-desktop/src/main/core/git/impl/git-service.ts @@ -500,19 +500,15 @@ export class GitService implements GitProvider, IDisposable { } async getFileAtIndex(filePath: string): Promise { - const cf = this._getCatFile(); - if (cf) { - try { - return await cf.read(`:0:${filePath}`); - } catch { - // Fall back - } - } + // Must NOT go through the persistent cat-file --batch channel: git caches + // the in-core index on the first `:0:` read and never re-reads it, + // so a long-lived batch process keeps serving stale staged content after + // the index changes (git add / commit). A one-shot process is always fresh. try { - const { stdout } = await this.ctx.exec('git', ['show', `:0:${filePath}`], { + const { stdout } = await this.ctx.exec('git', ['cat-file', 'blob', `:0:${filePath}`], { maxBuffer: MAX_DIFF_CONTENT_BYTES, }); - return stripTrailingNewline(stdout); + return stdout; } catch { return null; } diff --git a/apps/emdash-desktop/src/renderer/lib/monaco/invalidation-bridges.ts b/apps/emdash-desktop/src/renderer/lib/monaco/invalidation-bridges.ts index 536e1e400..898f25413 100644 --- a/apps/emdash-desktop/src/renderer/lib/monaco/invalidation-bridges.ts +++ b/apps/emdash-desktop/src/renderer/lib/monaco/invalidation-bridges.ts @@ -58,6 +58,14 @@ export function wireModelRegistryInvalidation(registry: MonacoModelRegistry): () // Local/remote ref changes → invalidate matching git:// models (exact ref when known). const unsubRefs = events.on(gitRefChangedChannel, ({ projectId, kind, changedRefs }) => { if (kind === 'config') return; + // A commit moves the local branch ref but never touches the worktree HEAD + // file, so no workspace-level 'head' event fires — refresh HEAD models on + // any local ref change to keep HEAD-based diffs in sync after commits. + if (kind === 'local-refs') { + for (const uri of registry.findGitUris({ projectId, ref: HEAD_REF })) { + void registry.invalidateModel(uri); + } + } if (changedRefs) { for (const ref of changedRefs) { for (const uri of registry.findGitUris({ projectId, ref })) {