дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-03 16:51:16 +02:00
fix(vcs): show why checkout was blocked
Цей коміт міститься в:
1 джерело
471bce2bb1
коміт
3ddd1ea9b8
5 files changed
+53
-37
No files matched your search
@@ -233,6 +233,7 @@ function WorktreeForm({
|
||||
level: "warning",
|
||||
title: tx("Some worktree configuration could not be copied"),
|
||||
body: result.copyWarning,
|
||||
userInitiated: true,
|
||||
});
|
||||
}
|
||||
if (result.setupWarning) {
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createElement } from "react";
|
||||
import { fireEvent, render, screen, within } from "@testing-library/react";
|
||||
import { MessagesHost } from "@/workbench/messages";
|
||||
import type { Branch, BranchInfo, ProjectInfo, Worktree } from "@/bindings";
|
||||
const mocks = vi.hoisted(() => ({
|
||||
prompt: vi.fn(),
|
||||
@@ -312,6 +315,7 @@ it("shows a partial failure without claiming that the rename failed", async () =
|
||||
expect(mocks.notify).toHaveBeenCalledExactlyOnceWith({
|
||||
group: "vcs",
|
||||
level: "error",
|
||||
userInitiated: true,
|
||||
title: "Rename branch topic",
|
||||
body: message,
|
||||
});
|
||||
@@ -411,7 +415,9 @@ it("checks every affected repository before moving any HEAD", async () => {
|
||||
await checkoutRevision({ repos });
|
||||
expect(mocks.hasCommit.mock.calls).toEqual(repos.map((root) => [root, "release"]));
|
||||
expect(mocks.checkout).not.toHaveBeenCalled();
|
||||
expect(mocks.notify).toHaveBeenCalledWith(expect.objectContaining({ body: "Revision was not found in nested" }));
|
||||
expect(mocks.notify).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ userInitiated: true, body: "Revision was not found in nested" }),
|
||||
);
|
||||
|
||||
mocks.hasCommit.mockResolvedValue(ok(true));
|
||||
mocks.checkout.mockResolvedValue(ok({ kind: "done" }));
|
||||
@@ -478,32 +484,19 @@ it("does not open the worktree when the checkout offer is declined", async () =>
|
||||
expect(mocks.executeAction).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("names the files git would remove when untracked ones block the checkout", async () => {
|
||||
mocks.checkout.mockResolvedValue(ok({ kind: "untrackedFiles", files: ["TEST.md"], removed: true }));
|
||||
await checkoutBranch(local("feature/x"));
|
||||
it.each([
|
||||
[true, "removed"],
|
||||
[false, "overwritten"],
|
||||
])("shows the files that checkout would affect in an error dialog (%s)", async (removed, verb) => {
|
||||
mocks.checkout.mockResolvedValue(ok({ kind: "untrackedFiles", files: ["TEST.md", "dir/new.txt"], removed }));
|
||||
render(createElement(MessagesHost));
|
||||
const checkout = checkoutBranch(local("feature/x"));
|
||||
const dialog = await screen.findByRole("dialog", { name: "Untracked files prevent checkout" });
|
||||
expect(dialog).toHaveTextContent(`The following untracked working tree files would be ${verb} by checkout:`);
|
||||
expect(dialog).toHaveTextContent("TEST.md dir/new.txt");
|
||||
fireEvent.click(within(dialog).getByRole("button", { name: "OK" }));
|
||||
await checkout;
|
||||
expect(mocks.checkout).toHaveBeenCalledTimes(1);
|
||||
expect(mocks.notify).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
level: "error",
|
||||
title: "Untracked files prevent checkout",
|
||||
body: expect.stringContaining(
|
||||
"The following untracked working tree files would be removed by checkout:\nTEST.md",
|
||||
),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("still says overwritten when untracked files would be overwritten", async () => {
|
||||
mocks.checkout.mockResolvedValue(ok({ kind: "untrackedFiles", files: ["dir/new.txt"], removed: false }));
|
||||
await checkoutBranch(local("feature/x"));
|
||||
expect(mocks.notify).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
level: "error",
|
||||
body: expect.stringContaining(
|
||||
"The following untracked working tree files would be overwritten by checkout:\ndir/new.txt",
|
||||
),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps the branch when the worktree question is turned down", async () => {
|
||||
|
||||
@@ -269,6 +269,17 @@ describe("Checkout and Update", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("reports a failed HEAD read before the update", async () => {
|
||||
mocks.checkout.mockResolvedValue({ status: "ok", data: { kind: "done" } });
|
||||
mocks.head.mockResolvedValue({ status: "error", error: { kind: "io", message: "Cannot read HEAD" } });
|
||||
await checkoutAndUpdate(branch("topic"));
|
||||
expect(mocks.notify).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ level: "error", userInitiated: true, body: "Cannot read HEAD" }),
|
||||
);
|
||||
expect(mocks.updateCurrent).not.toHaveBeenCalled();
|
||||
expect(mocks.update).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("updates nothing when the checkout did not happen", async () => {
|
||||
mocks.checkout.mockResolvedValue({ status: "error", error: { kind: "failed", message: "nope" } });
|
||||
await checkoutAndUpdate(branch("topic"));
|
||||
|
||||
@@ -19,7 +19,7 @@ import { notifications } from "@/workbench/contributions";
|
||||
import { openWorktree } from "./openWorktree";
|
||||
import { githubHttpsFailureHelp } from "./githubHttpsFailure";
|
||||
import { activeRepository } from "./activeRepository";
|
||||
import { ask, confirmChecked } from "@/workbench/messages";
|
||||
import { ask, confirmChecked, showError } from "@/workbench/messages";
|
||||
import { branchNamePrefixes, isFavoriteBranch, isProtectedBranch, pushRecent, shortRemoteName } from "./branches";
|
||||
import { showCommitRanges } from "./CompareBranches";
|
||||
import type { AffectedFiles } from "./LocalChangesReviewDialog";
|
||||
@@ -27,6 +27,7 @@ import { confirmDialog, promptText } from "./dialogs";
|
||||
import { cleanUpBranchNameOnTyping } from "@/platform/gitRefName";
|
||||
import {
|
||||
errorMessage,
|
||||
logConsole,
|
||||
runBranchUpdates,
|
||||
runGitOperation,
|
||||
runOp,
|
||||
@@ -206,6 +207,7 @@ async function reviewCheckout<T>(
|
||||
const shelved = workflowSettings().vcs.git.saveChangesPolicy === "shelve";
|
||||
notifications().notify({
|
||||
group: "vcs",
|
||||
userInitiated: true,
|
||||
level: "warning",
|
||||
title: tx("Could not restore local changes after checkout"),
|
||||
body: outcome.message,
|
||||
@@ -221,6 +223,7 @@ async function reviewCheckout<T>(
|
||||
const shelved = opts.mode === "smart" && workflowSettings().vcs.git.saveChangesPolicy === "shelve";
|
||||
notifications().notify({
|
||||
group: "vcs",
|
||||
userInitiated: true,
|
||||
level: "warning",
|
||||
title: `${success()}, with conflicts`,
|
||||
body: outcome.files.join("\n"),
|
||||
@@ -241,12 +244,9 @@ async function reviewCheckout<T>(
|
||||
const body = outcome.removed
|
||||
? tx`The following untracked working tree files would be removed by checkout:\n${files}\nPlease move or remove them before you switch branches.`
|
||||
: tx`The following untracked working tree files would be overwritten by checkout:\n${files}\nPlease move or remove them before you switch branches.`;
|
||||
notifications().notify({
|
||||
group: "vcs",
|
||||
level: "error",
|
||||
title: "Untracked files prevent checkout",
|
||||
body,
|
||||
});
|
||||
logConsole("err", body);
|
||||
// oxlint-disable-next-line no-await-in-loop -- acknowledge the blocked checkout before a possible multi-root rollback
|
||||
await showError(tx("Untracked files prevent checkout"), body);
|
||||
return undefined;
|
||||
}
|
||||
case "localChanges": {
|
||||
@@ -604,6 +604,7 @@ export async function checkoutRevision(scope?: CheckoutRevisionScope) {
|
||||
notifications().notify({
|
||||
group: "vcs",
|
||||
level: "error",
|
||||
userInitiated: true,
|
||||
title: tx`Could not check out ${label}`,
|
||||
body: names ? tx`Revision was not found in ${names}` : tx("Revision was not found"),
|
||||
});
|
||||
@@ -784,7 +785,13 @@ export async function renameBranch(branch: Branch) {
|
||||
success: tx`Renamed branch ${name} to ${to}`,
|
||||
onError: (message) => {
|
||||
// Unsetting the upstream can fail after the rename has succeeded.
|
||||
notifications().notify({ group: "vcs", level: "error", title: tx`Rename branch ${name}`, body: message });
|
||||
notifications().notify({
|
||||
group: "vcs",
|
||||
userInitiated: true,
|
||||
level: "error",
|
||||
title: tx`Rename branch ${name}`,
|
||||
body: message,
|
||||
});
|
||||
return true;
|
||||
},
|
||||
},
|
||||
@@ -1420,7 +1427,12 @@ export async function checkoutAndUpdate(branch: NamedBranch, roots?: readonly st
|
||||
if (useProject.getState().project !== project) return;
|
||||
const repos: readonly (string | null)[] = roots ?? [currentRepo()];
|
||||
const heads = await Promise.all(
|
||||
repos.map(async (repo) => [repo, await call(commands.vcsBranchInfo(repo)).catch(() => null)] as const),
|
||||
repos.map(async (repo) => {
|
||||
const head = await runOp(tx("Read repository HEAD"), () => call(commands.vcsBranchInfo(repo)), {
|
||||
refresh: false,
|
||||
});
|
||||
return [repo, head] as const;
|
||||
}),
|
||||
);
|
||||
if (useProject.getState().project !== project) return;
|
||||
const targets = heads
|
||||
|
||||
@@ -139,8 +139,7 @@ export async function saveAll() {
|
||||
try {
|
||||
await saveDiffWindows();
|
||||
} catch (error) {
|
||||
notifications().notify({
|
||||
group: "vcs",
|
||||
notify({
|
||||
level: "error",
|
||||
title: tx("Could not save diff"),
|
||||
body: errorMessage(error),
|
||||
|
||||
Reference in new issue
Заблокувати користувача