Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/renderer/state/gitRefresh.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,69 @@ describe("watcher git status refresh", () => {
expect(useGitStore.getState().worktreeStatuses["/repo-wt"]).toEqual(worktreeStatus);
});

it("preserves cached worktree diff stats during fetch refreshes", async () => {
const cachedWorktreeStatus: GitStatusResult = {
...status,
branch: "feature/wt",
unstaged: [
{
path: "src/existing-change.ts",
status: "M",
staged: false,
insertions: 3,
deletions: 1,
},
],
totalInsertions: 3,
totalDeletions: 1,
};
const gitWatchWorktrees = vi.fn<() => Promise<void>>().mockResolvedValue(undefined);
const gitWorktreeStatusBatch = vi
.fn<
(payload: {
projectLocation: ProjectLocation;
worktreePaths: string[];
detail?: "summary" | "full";
}) => Promise<{ statuses: Record<string, GitStatusResult> }>
>()
.mockResolvedValue({ statuses: {} });
const gitProjectSnapshot = vi
.fn<
() => Promise<{
status: GitStatusResult;
branches: { current: string; branches: unknown[] };
worktrees: { path: string; branch: string; commit: string; isMain: boolean }[];
ghAvailable: boolean;
}>
>()
.mockResolvedValue({
status,
branches: { current: "feature/pr-checks", branches: [] },
worktrees: [{ path: "/repo", branch: "feature/pr-checks", commit: "abc123", isMain: true }],
ghAvailable: false,
});
Object.defineProperty(window, "lightcode", {
configurable: true,
value: {
platform: "darwin",
gitProjectSnapshot,
gitWatchWorktrees,
gitWorktreeStatusBatch,
},
});
useGitStore.getState().setWorktreeStatus("/repo-wt", cachedWorktreeStatus);
useAppStore.setState({ threads: [worktreeThread] });

await refreshGitProject(project, "fetch", "full");

expect(gitProjectSnapshot).toHaveBeenCalledWith({
projectLocation: location,
includeGhCheck: true,
});
expect(gitWorktreeStatusBatch).not.toHaveBeenCalled();
expect(useGitStore.getState().worktreeStatuses["/repo-wt"]).toEqual(cachedWorktreeStatus);
});

it("promotes watcher refresh to a full snapshot after a project becomes a Git repo", async () => {
const nonRepoStatus: GitStatusResult = {
isRepo: false,
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/state/gitRefresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ export async function refreshGitProject(
);

const statusesPromise =
watchWorktreePaths.length === 0
reason === "fetch" || watchWorktreePaths.length === 0
? Promise.resolve()
: readBridge()
.gitWorktreeStatusBatch({
Expand Down