Skip to content
Draft
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

192 changes: 192 additions & 0 deletions GB-1727-WORKSPACE-REVISION.md

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion apps/desktop/src/lib/stacks/stackInvalidation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ const headInfo = {
],
} as RefInfo;
const integrationResult = {
workspaceState: { headInfo, replacedCommits: {}, checkoutConflictOccurred: false },
workspaceState: {
headInfo,
replacedCommits: {},
workspaceRevision: null,
checkoutConflictOccurred: false,
},
worktreeConflicts: [],
} satisfies WorkspaceIntegrateUpstreamOutcome;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ describe("branchIntegrationView", () => {
test("builds preview rows from workspace state", () => {
const workspace: WorkspaceState = {
replacedCommits: {},
workspaceRevision: null,
headInfo: {
workspaceRef: null,
stacks: [
Expand Down
54 changes: 54 additions & 0 deletions apps/lite/e2e/tests/branches.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { expect, test } from "../test.ts";
import { execFileSync } from "node:child_process";
import path from "node:path";

test.describe("branches", () => {
test.use({ scenario: "project-with-remote-branches.sh" });
Expand Down Expand Up @@ -29,4 +31,56 @@ test.describe("branches", () => {
await expect(secondCommit).toBeVisible();
await expect(firstCommit).toBeVisible();
});

test("does not fetch head info after a cached branch creation", async ({
appWindow,
mainProcessLogs,
}) => {
await expect(appWindow.getByRole("button", { name: "New branch" })).toBeVisible();
await appWindow.waitForTimeout(1_000);
const headInfoCalls = () =>
mainProcessLogs.filter((message) => message.includes("[lite-e2e] headInfo")).length;
const callsBeforeMutation = headInfoCalls();
expect(callsBeforeMutation).toBeGreaterThan(0);

await appWindow.keyboard.press("ControlOrMeta+N");
await expect(
appWindow.getByRole("treeitem", { name: "bm-branch-1", exact: true }),
).toBeVisible();

// Let the mutation's watcher event settle. Its revision matches the response already cached
// by the mutation, so it must not trigger another full head-info traversal.
await appWindow.waitForTimeout(1_000);
expect(headInfoCalls()).toBe(callsBeforeMutation);
});

test("refreshes head info after deleting a packed-only branch", async ({
appWindow,
mainProcessLogs,
testEnvironment,
}) => {
await expect(appWindow.getByRole("button", { name: "New branch" })).toBeVisible();
const repositoryPath = path.join(testEnvironment.workdir, "local-clone");
const git = (...args: Array<string>) =>
execFileSync("git", ["-C", repositoryPath, ...args], { encoding: "utf8" });
const headInfoCalls = () =>
mainProcessLogs.filter((message) => message.includes("[lite-e2e] headInfo")).length;
await expect.poll(headInfoCalls).toBeGreaterThan(0);

await appWindow.keyboard.press("ControlOrMeta+N");
await expect(
appWindow.getByRole("treeitem", { name: "bm-branch-1", exact: true }),
).toBeVisible();

const callsBeforePacking = headInfoCalls();
git("pack-refs", "--all", "--prune");
await expect.poll(headInfoCalls).toBeGreaterThan(callsBeforePacking);
const callsBeforeDeletion = headInfoCalls();
git("branch", "-D", "bm-branch-1");

await expect.poll(headInfoCalls).toBeGreaterThan(callsBeforeDeletion);
await expect(appWindow.getByRole("treeitem", { name: "bm-branch-1", exact: true })).toHaveCount(
0,
);
});
});
8 changes: 7 additions & 1 deletion apps/lite/electron/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,13 @@ const registerIpcHandlers = (): void => {
const captureWrapped = Object.hasOwn(apiParamNames, name)
? withApiCommandCapture(name, handler)
: handler;
senderValidatingHandle(name, (_e, params: unknown) => captureWrapped(params));
senderValidatingHandle(name, (_e, params: unknown) => {
if (name === "headInfoSnapshot" && process.env.E2E_TEST_APP_DATA_DIR !== undefined) {
// oxlint-disable-next-line no-console
console.log("[lite-e2e] headInfo");
}
return captureWrapped(params);
});
}
senderValidatingHandle("watcherUnsubscribe", (_e, { subscriptionId }: WatcherUnsubscribeParams) =>
WatcherManager.getInstance().removeSubscription(subscriptionId),
Expand Down
6 changes: 3 additions & 3 deletions apps/lite/harness/tests/panel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ test("renders the applied branches, their commits, and the uncommitted files", a
const worktreeChanges = fixtureWorktreeChanges([fixtureFileChange("src/edited-file.ts")]);

const panel = mountPanel({
headInfo: () => headInfo,
headInfoSnapshot: () => ({ headInfo, workspaceRevision: null }),
changesInWorktree: () => worktreeChanges,
});

Expand All @@ -87,7 +87,7 @@ test("a failed mutation surfaces the declared toast", async () => {
],
]);
const panel = mountPanel({
headInfo: () => headInfo,
headInfoSnapshot: () => ({ headInfo, workspaceRevision: null }),
changesInWorktree: () => fixtureWorktreeChanges([]),
});

Expand All @@ -111,7 +111,7 @@ test("a watcher event refreshes the uncommitted files", async () => {
// the same answer to any consumer that refetches instead.
let worktree: WorktreeChanges = fixtureWorktreeChanges([]);
const panel = mountPanel({
headInfo: () => fixtureHeadInfo([]),
headInfoSnapshot: () => ({ headInfo: fixtureHeadInfo([]), workspaceRevision: null }),
changesInWorktree: () => worktree,
});

Expand Down
48 changes: 29 additions & 19 deletions apps/lite/ui/src/api/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
currentForgeLoginQueryOptions,
getReviewQueryOptions,
headInfoQueryOptions,
headInfoSnapshotQueryOptions,
guiSettingsQueryOptions,
listCommentReactionsQueryOptions,
listReviewCommentsQueryOptions,
Expand Down Expand Up @@ -62,7 +63,7 @@ declare module "@tanstack/react-query" {
* write `onError` only for work of their own, like rolling back an
* optimistic write or wording a title dynamically.
*/
mutationMeta: { failureTitle?: string };
mutationMeta: { failureTitle?: string; updatesWorkspace?: boolean; projectId?: string };
}
}

Expand Down Expand Up @@ -121,7 +122,10 @@ export const syncCoreCaches = (
: null;
if (workspace === null) return;

queryClient.setQueryData(headInfoQueryOptions(projectId).queryKey, workspace.headInfo);
queryClient.setQueryData(headInfoSnapshotQueryOptions(projectId).queryKey, {
headInfo: workspace.headInfo,
workspaceRevision: workspace.workspaceRevision,
});
dispatch(
projectSlice.actions.updateRewrittenCommitReferences({
projectId,
Expand Down Expand Up @@ -160,11 +164,16 @@ export const useApply = () => {
children: "Switch to branch instead",
onClick: () => {
(async () => {
const checkoutResponse = await window.lite.branchCheckout({
const checkout = mutation.client.getMutationCache().build(mutation.client, {
mutationFn: window.lite.branchCheckout,
meta: { updatesWorkspace: true },
onSuccess: (response, checkoutInput) =>
syncCoreCaches(mutation.client, dispatch, checkoutInput.projectId, response),
});
await checkout.execute({
projectId: input.projectId,
branch: encodeBytes(input.existingBranch),
});
syncCoreCaches(mutation.client, dispatch, input.projectId, checkoutResponse);
toastManager.close(toastId);
})().catch((error) => {
// oxlint-disable-next-line no-console
Expand Down Expand Up @@ -193,7 +202,7 @@ export const useBranchCreate = () => {
onSuccess: async (response, input, _context, mutation) => {
syncCoreCaches(mutation.client, dispatch, input.projectId, response);
},
meta: { failureTitle: "Failed to create branch" },
meta: { failureTitle: "Failed to create branch", updatesWorkspace: true },
});
};

Expand All @@ -209,7 +218,7 @@ export const useBranchCheckoutNew = () => {
onSuccess: async (response, input, _context, mutation) => {
syncCoreCaches(mutation.client, dispatch, input.projectId, response);
},
meta: { failureTitle: "Failed to create and switch to branch" },
meta: { failureTitle: "Failed to create and switch to branch", updatesWorkspace: true },
});
};

Expand Down Expand Up @@ -790,7 +799,7 @@ export const useCommitAmend = (projectId: string) => {
);
}
},
meta: { failureTitle: "Failed to amend commit" },
meta: { failureTitle: "Failed to amend commit", updatesWorkspace: true },
});
};

Expand Down Expand Up @@ -827,7 +836,7 @@ export const useCommitCreate = () => {
);
}
},
meta: { failureTitle: "Failed to commit" },
meta: { failureTitle: "Failed to commit", updatesWorkspace: true },
});
};

Expand All @@ -838,7 +847,7 @@ export const useCommitDiscard = () => {
onSuccess: async (response, input, _context, mutation) => {
syncCoreCaches(mutation.client, dispatch, input.projectId, response);
},
meta: { failureTitle: "Failed to discard commit" },
meta: { failureTitle: "Failed to discard commit", updatesWorkspace: true },
});
};

Expand All @@ -849,7 +858,7 @@ export const useCommitDiscardChanges = () => {
onSuccess: async (response, input, _context, mutation) => {
syncCoreCaches(mutation.client, dispatch, input.projectId, response);
},
meta: { failureTitle: "Failed to discard changes" },
meta: { failureTitle: "Failed to discard changes", updatesWorkspace: true },
});
};

Expand Down Expand Up @@ -996,7 +1005,7 @@ export const useCommitInsertBlank = () => {
);
}
},
meta: { failureTitle: "Failed to insert commit" },
meta: { failureTitle: "Failed to insert commit", updatesWorkspace: true },
});
};

Expand All @@ -1007,7 +1016,7 @@ export const useCommitMove = () => {
onSuccess: async (response, input, _context, mutation) => {
syncCoreCaches(mutation.client, dispatch, input.projectId, response);
},
meta: { failureTitle: "Failed to move commit" },
meta: { failureTitle: "Failed to move commit", updatesWorkspace: true },
});
};

Expand All @@ -1018,7 +1027,7 @@ export const useCommitReword = () => {
onSuccess: async (response, input, _context, mutation) => {
syncCoreCaches(mutation.client, dispatch, input.projectId, response);
},
meta: { failureTitle: "Failed to reword commit" },
meta: { failureTitle: "Failed to reword commit", updatesWorkspace: true },
});
};

Expand Down Expand Up @@ -1065,7 +1074,7 @@ export const useResolveCommitConflictHunks = () => {
});
}
},
meta: { failureTitle: "Failed to resolve the conflict" },
meta: { failureTitle: "Failed to resolve the conflict", updatesWorkspace: true },
});
};

Expand All @@ -1076,7 +1085,7 @@ export const useCommitUncommit = () => {
onSuccess: async (response, input, _context, mutation) => {
syncCoreCaches(mutation.client, dispatch, input.projectId, response);
},
meta: { failureTitle: "Failed to uncommit" },
meta: { failureTitle: "Failed to uncommit", updatesWorkspace: true },
});
};

Expand All @@ -1087,7 +1096,7 @@ export const useCommitUncommitChanges = () => {
onSuccess: async (response, input, _context, mutation) => {
syncCoreCaches(mutation.client, dispatch, input.projectId, response);
},
meta: { failureTitle: "Failed to uncommit" },
meta: { failureTitle: "Failed to uncommit", updatesWorkspace: true },
});
};

Expand All @@ -1104,6 +1113,7 @@ export const useWorkspaceIntegrateUpstream = () => {

return useMutation({
mutationFn: window.lite.workspaceIntegrateUpstream,
meta: { updatesWorkspace: true },
onSuccess: (response, input, _context, mutation) => {
syncCoreCaches(mutation.client, dispatch, input.projectId, response);
},
Expand All @@ -1125,7 +1135,7 @@ export const useBranchRemove = () => {
onSuccess: (response, input, _context, mutation) => {
syncCoreCaches(mutation.client, dispatch, input.projectId, response);
},
meta: { failureTitle: "Failed to delete branch reference" },
meta: { failureTitle: "Failed to delete branch reference", updatesWorkspace: true },
});
};

Expand Down Expand Up @@ -1202,7 +1212,7 @@ export const useTearOffBranch = () => {
onSuccess: async (response, input, _context, mutation) => {
syncCoreCaches(mutation.client, dispatch, input.projectId, response);
},
meta: { failureTitle: "Failed to tear off branch" },
meta: { failureTitle: "Failed to tear off branch", updatesWorkspace: true },
});
};

Expand Down Expand Up @@ -1243,7 +1253,7 @@ export const useBranchRename = () => {

dispatch(projectSlice.actions.clearPendingOperation({ projectId: input.projectId }));
},
meta: { failureTitle: "Failed to rename branch" },
meta: { failureTitle: "Failed to rename branch", updatesWorkspace: true },
});
};

Expand Down
10 changes: 8 additions & 2 deletions apps/lite/ui/src/api/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,16 @@ export const editChangesFromInitialQueryOptions = (projectId: string) =>
queryFn: () => window.lite.editChangesFromInitial(projectId),
});

export const headInfoQueryOptions = (projectId: string) =>
export const headInfoSnapshotQueryOptions = (projectId: string) =>
queryOptions({
queryKey: [projectId, "headInfo"],
queryFn: () => window.lite.headInfo(projectId),
queryFn: () => window.lite.headInfoSnapshot(projectId),
});

export const headInfoQueryOptions = (projectId: string) =>
queryOptions({
...headInfoSnapshotQueryOptions(projectId),
select: (snapshot) => snapshot.headInfo,
});

export const getReviewQueryOptions = ({ projectId, reviewId }: PayloadFor<"getReview">) =>
Expand Down
1 change: 1 addition & 0 deletions apps/lite/ui/src/operations/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export const useExecuteOperation = (projectId: string) => {
const toastManager = Toast.useToastManager();

return useMutation({
meta: { updatesWorkspace: true, projectId },
mutationFn: (operation: Operation) =>
executeOperation({
projectId,
Expand Down
Loading
Loading