дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 01:57:13 +02:00
* fix(vcs): keep local changes and staging intact across commit, checkout and history edits - Commit: changes left out of a commit keep their staged state. The commit is made from a copy of the index (included files staged there, excluded ones reset to HEAD), so the user's index and other repositories are untouched. - Smart Checkout restores staged changes as staged; untracked files a checkout would overwrite are listed instead of a raw git error. - Edit Commit Message rewrites the commit and its descendants without a rebase, so the working tree and local changes stay as they are. - Edit Commit Message, Drop and Squash offer Undo in their notification while the branch hasn't moved since. - Interactive rebases (Drop, Squash, Interactively Rebase) put local changes aside themselves and bring them back with their staged state once the rebase is over, also after a stop for conflicts. - Undo Commit asks for the target changelist (a new one named after the commit) and puts the commit message back into the commit message field. - Cherry-pick and revert skip commits whose changes are already applied instead of stopping with an empty commit; commits cherry-picked from a protected branch get "(cherry picked from commit …)". - Commit tool window: Commit File…, Accept Yours / Accept Theirs on conflicted files and Copy as Patch to Clipboard. * fix(vcs): restore staged changes after merge, rebase and update; roll back partial multi-repository operations - Merge, rebase, pull / Update Project and the rebase of a diverged checkout put local changes aside themselves and bring them back with --index, so staged changes stay staged (git's --autostash restored them unstaged). An operation stopped on conflicts keeps them aside until it is continued, skipped, aborted or concluded by a commit. - Checkout, New Branch, Merge, Rebase and Delete over several repositories: when one repository fails after others succeeded, ask whether to roll those back (check out the previous branch, delete the new branch, reset to the commit before, restore the branch); not when it stopped on conflicts. - Fixup… / Squash Into…: while the prepared message is in the field, the second commit button is Commit and Rebase, which commits and autosquashes the new commit into its target. - Undo on a history rewrite replaces its notification, so the link is gone once used.
84 рядки
3.1 KiB
TypeScript
84 рядки
3.1 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const mocks = vi.hoisted(() => ({
|
|
ask: vi.fn(),
|
|
merge: vi.fn(),
|
|
restore: vi.fn(),
|
|
heads: {} as Record<string, string>,
|
|
ops: {} as Record<string, string | null>,
|
|
}));
|
|
vi.mock("@/platform/ipc", async (original) => {
|
|
const real = await original<typeof import("@/platform/ipc")>();
|
|
const ok = (data: unknown) => Promise.resolve({ status: "ok" as const, data });
|
|
const fail = (message: string) => Promise.resolve({ status: "error" as const, error: { kind: "failed", message } });
|
|
return {
|
|
...real,
|
|
isTauri: () => false,
|
|
call: async (p: Promise<{ status: string; data?: unknown; error?: unknown }>) => {
|
|
const r = await p;
|
|
if (r.status === "error") throw r.error;
|
|
return r.data;
|
|
},
|
|
commands: {
|
|
...real.commands,
|
|
vcsBranchInfo: (root: string) =>
|
|
ok({ head: "main", headCommit: mocks.heads[root], operation: mocks.ops[root] ?? null }),
|
|
vcsMerge: (root: string, branch: string) => {
|
|
mocks.merge(root, branch);
|
|
if (root === "/b") return fail("merge refused");
|
|
mocks.heads[root] = `${root}-merged`;
|
|
return ok(null);
|
|
},
|
|
vcsRestoreHead: (root: string, before: string, after: string) => {
|
|
mocks.restore(root, before, after);
|
|
return ok(null);
|
|
},
|
|
},
|
|
};
|
|
});
|
|
vi.mock("@/workbench/messages", () => ({ ask: mocks.ask, showError: vi.fn() }));
|
|
|
|
import { mergeInRepos } from "../branchOps";
|
|
import { pendingFixup } from "../commitStore";
|
|
import type { Commit } from "@/bindings";
|
|
|
|
describe("an operation over several repositories that fails part way (IDEA's rollback proposal)", () => {
|
|
beforeEach(() => {
|
|
mocks.ask.mockReset();
|
|
mocks.merge.mockReset();
|
|
mocks.restore.mockReset();
|
|
mocks.heads = { "/a": "a1", "/b": "b1", "/c": "c1" };
|
|
mocks.ops = {};
|
|
});
|
|
|
|
it("offers to reset the repositories it already merged, and does so on Rollback", async () => {
|
|
mocks.ask.mockResolvedValue({ button: "rollback" });
|
|
await mergeInRepos("feature", ["/a", "/b", "/c"]);
|
|
expect(mocks.merge.mock.calls.map((c) => c[0])).toEqual(["/a", "/b"]);
|
|
expect(mocks.ask).toHaveBeenCalledTimes(1);
|
|
expect(mocks.restore).toHaveBeenCalledWith("/a", "a1", "/a-merged");
|
|
});
|
|
|
|
it("leaves them merged on Don't Rollback", async () => {
|
|
mocks.ask.mockResolvedValue({ button: "keep" });
|
|
await mergeInRepos("feature", ["/a", "/b"]);
|
|
expect(mocks.restore).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("doesn't ask when the failed repository stopped on conflicts", async () => {
|
|
mocks.ops = { "/b": "merge" };
|
|
await mergeInRepos("feature", ["/a", "/b"]);
|
|
expect(mocks.ask).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe("Commit and Rebase after Fixup…", () => {
|
|
const target = { id: "c1", summary: "Add parser" } as Commit;
|
|
it("is offered while the message is the one prepared for the target", () => {
|
|
expect(pendingFixup("fixup! Add parser", target)).toBe(target);
|
|
expect(pendingFixup("squash! Add parser\n\nmore", target)).toBe(target);
|
|
expect(pendingFixup("Something else", target)).toBeNull();
|
|
expect(pendingFixup("fixup! Add parser", null)).toBeNull();
|
|
});
|
|
});
|