Preserve local git status fields on remote refresh

- Keep working tree and branch metadata intact when applying remote updates
- Remove the unused enqueueRefreshStatus API
This commit is contained in:
Julius Marminge committed 2026-04-05 18:52:05 -07:00
1 parent 5efdbb0d4c
commit 2c200cee78
4 files changed
+53 -22

No files matched your search

@@ -18,7 +18,6 @@ import type {
GitStatusRemoteResult,
GitStatusStreamEvent,
} from "@t3tools/contracts";
import { makeKeyedCoalescingWorker } from "@t3tools/shared/KeyedCoalescingWorker";
import { mergeGitStatusParts } from "@t3tools/shared/git";
import {
@@ -203,23 +202,6 @@ export const GitStatusBroadcasterLive = Layer.effect(
},
);
const refreshWorker = yield* makeKeyedCoalescingWorker<string, void, never, never>({
merge: () => undefined,
process: (cwd) =>
refreshStatus(cwd).pipe(
Effect.catchCause((cause) =>
Effect.logWarning("git status refresh failed", {
cwd,
cause,
}),
),
Effect.asVoid,
),
});
const enqueueRefreshStatus: GitStatusBroadcasterShape["enqueueRefreshStatus"] = (cwd) =>
refreshWorker.enqueue(normalizeCwd(cwd), undefined);
const makeRemoteRefreshLoop = (cwd: string) => {
const logRefreshFailure = (error: Error) =>
Effect.logWarning("git remote status refresh failed", {
@@ -320,7 +302,6 @@ export const GitStatusBroadcasterLive = Layer.effect(
return {
getStatus,
enqueueRefreshStatus,
refreshStatus,
streamStatus,
} satisfies GitStatusBroadcasterShape;
@@ -11,7 +11,6 @@ export interface GitStatusBroadcasterShape {
readonly getStatus: (
input: GitStatusInput,
) => Effect.Effect<GitStatusResult, GitManagerServiceError>;
readonly enqueueRefreshStatus: (cwd: string) => Effect.Effect<void>;
readonly refreshStatus: (cwd: string) => Effect.Effect<GitStatusResult, GitManagerServiceError>;
readonly streamStatus: (
input: GitStatusInput,
+40 -1
View File
@@ -1,4 +1,4 @@
import type { GitStatusRemoteResult } from "@t3tools/contracts";
import type { GitStatusRemoteResult, GitStatusResult } from "@t3tools/contracts";
import { describe, expect, it } from "vitest";
import { applyGitStatusStreamEvent } from "./git";
@@ -25,4 +25,43 @@ describe("applyGitStatusStreamEvent", () => {
pr: null,
});
});
it("preserves local-only fields when applying a remote update", () => {
const current: GitStatusResult = {
isRepo: true,
hostingProvider: {
kind: "github",
name: "GitHub",
baseUrl: "https://github.com",
},
hasOriginRemote: true,
isDefaultBranch: false,
branch: "feature/demo",
hasWorkingTreeChanges: true,
workingTree: {
files: [{ path: "src/demo.ts", insertions: 1, deletions: 0 }],
insertions: 1,
deletions: 0,
},
hasUpstream: false,
aheadCount: 0,
behindCount: 0,
pr: null,
};
const remote: GitStatusRemoteResult = {
hasUpstream: true,
aheadCount: 2,
behindCount: 1,
pr: null,
};
expect(applyGitStatusStreamEvent(current, { _tag: "remoteUpdated", remote })).toEqual({
...current,
hasUpstream: true,
aheadCount: 2,
behindCount: 1,
pr: null,
});
});
});
+13 -1
View File
@@ -218,6 +218,18 @@ function toRemoteStatusPart(status: GitStatusResult): GitStatusRemoteResult {
};
}
function toLocalStatusPart(status: GitStatusResult): GitStatusLocalResult {
return {
isRepo: status.isRepo,
...(status.hostingProvider ? { hostingProvider: status.hostingProvider } : {}),
hasOriginRemote: status.hasOriginRemote,
isDefaultBranch: status.isDefaultBranch,
branch: status.branch,
hasWorkingTreeChanges: status.hasWorkingTreeChanges,
workingTree: status.workingTree,
};
}
export function applyGitStatusStreamEvent(
current: GitStatusResult | null,
event: GitStatusStreamEvent,
@@ -241,6 +253,6 @@ export function applyGitStatusStreamEvent(
event.remote,
);
}
return mergeGitStatusParts(current, event.remote);
return mergeGitStatusParts(toLocalStatusPart(current), event.remote);
}
}