Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai be9b00a255 fix(vcs): the staging area commits a staged addition deleted from disk 2026-11-16 18:45:50 +08:00
l0ng-ai f74bc7abac fix(vcs): collapsing a file in the all-files diff keeps its unsaved edits (#3739)
Collapsing a block unmounted its diff editor and released the working-tree document, which with autosave off drops its unsaved edits. A loaded block now keeps its diff while collapsed, hidden.
2026-11-16 18:43:09 +08:00
7 змінених файлів з 66 додано та 19 видалено

No files matched your search

+3
Переглянути файл
@@ -71,6 +71,9 @@
display: flex;
flex-direction: column;
}
.body[hidden] {
display: none;
}
/* Space a block takes before its diff loads, so the scrollbar is roughly right. */
.placeholder {
height: 160px;
+9 -8
Переглянути файл
@@ -98,14 +98,15 @@ function Block({
/>
)}
</div>
{!collapsed &&
(near ? (
<div className={styles.body}>
<DiffEditor input={input} fit />
</div>
) : (
<div className={styles.placeholder} />
))}
{/* A collapsed block keeps its loaded diff, hidden: unmounting it would release the
working-tree document and, with autosave off, drop its unsaved edits. */}
{near ? (
<div className={styles.body} hidden={collapsed}>
<DiffEditor input={input} fit />
</div>
) : (
!collapsed && <div className={styles.placeholder} />
)}
</section>
);
}
+8 -4
Переглянути файл
@@ -83,20 +83,24 @@ describe("the all-in-one diff tab", () => {
expect(screen.getAllByText("src")).toHaveLength(2);
});
it("collapses a file and all files", () => {
it("collapses a file and all files, keeping their diffs (and unsaved edits) loaded", () => {
render(<CombinedDiffTab input={input} />);
const shown = () => screen.queryAllByTestId("block-diff").filter((b) => !b.closest("[hidden]"));
const first = screen.getAllByTestId("block-diff")[0]!;
act(() => {
fireEvent.click(screen.getAllByRole("button", { name: "Collapse File" })[0]!);
});
expect(screen.getAllByTestId("block-diff")).toHaveLength(2);
expect(shown()).toHaveLength(2);
act(() => {
fireEvent.click(screen.getByRole("button", { name: "Collapse All Files" }));
});
expect(screen.queryAllByTestId("block-diff")).toHaveLength(0);
expect(shown()).toHaveLength(0);
act(() => {
fireEvent.click(screen.getByRole("button", { name: "Expand All Files" }));
});
expect(screen.getAllByTestId("block-diff")).toHaveLength(3);
expect(shown()).toHaveLength(3);
// The same diff all along: collapsing never released its document.
expect(screen.getAllByTestId("block-diff")[0]).toBe(first);
});
it("switches every block between side-by-side and unified", () => {
+20
Переглянути файл
@@ -59,6 +59,26 @@ describe("staging area inclusion", () => {
expect(plan.stage).toEqual(["/p/src/Unstaged.kt", "/p/src/Gone.kt"]);
});
it("lists and commits a staged addition deleted from disk; the change lists leave it out", () => {
const gone = file("src/New.txt", "added", "deleted");
const status = [gone, unstagedOnly];
expect(isCommitAll(status)).toBe(false);
const plan = planCommit(status, stagingChecks(status));
expect(plan.included.map((f) => f.relPath)).toEqual(["src/New.txt"]);
expect(plan.exclude).toEqual([]);
// Staged shows the addition, Unstaged the deletion.
const tree = buildChangeTree(status, "/p", false, undefined, [], true);
const kinds = (group: string) =>
tree.find((n) => n.group === group)?.children?.flatMap((n) => (n.label === "New.txt" ? [n.kind] : []));
expect(kinds("staged")).toEqual(["added"]);
expect(kinds("unstaged")).toEqual(["deleted"]);
// Without the staging area it is no change against HEAD: listed nowhere, never committed.
expect(buildChangeTree(status, "/p", false).flatMap((n) => n.files.map((f) => f.relPath))).toEqual([
"src/Unstaged.kt",
]);
expect(planCommit(status, new Map([[unstagedOnly.path, "all" as const]])).exclude).toEqual(["/p/src/New.txt"]);
});
it("is not Commit All when only unversioned files changed", () => {
expect(isCommitAll([untracked])).toBe(false);
});
+5 -2
Переглянути файл
@@ -4,7 +4,7 @@ import type { FileStatus, Stash } from "@/bindings";
import { call, commands } from "@/platform/ipc";
import { Checkbox, Dialog, Icon, IconButton, Input, T, fileIconName } from "@/ui";
import { notifications } from "@/workbench/contributions";
import { groupOf, remainingOverrides, renamedFromPath } from "./changes";
import { addedThenDeleted, groupOf, remainingOverrides, renamedFromPath } from "./changes";
import { runCommitChecks } from "./commitChecks";
import { contributedCheckProblems, currentPlan, selectionOf } from "./commitSelection";
import { forgetAmendDraft, keepMessageAfterCommit, rememberMessage, useCommit } from "./commitStore";
@@ -54,7 +54,10 @@ export async function commitChanges(): Promise<string | undefined> {
});
return undefined;
}
const candidates = plan.included.map((f) => ({ path: stripSlash(f.path), exists: effectiveKind(f) !== "deleted" }));
const candidates = plan.included.map((f) => ({
path: stripSlash(f.path),
exists: effectiveKind(f) !== "deleted" && !addedThenDeleted(f),
}));
// IDEA: failed checks show in the commit panel; the next Commit ("Commit Anyway") skips them.
const checked = !useCommit.getState().checkProblems.length;
if (checked) {
+18 -4
Переглянути файл
@@ -57,6 +57,14 @@ export function groupOf(fs: FileStatus): GroupId | null {
return "changes";
}
/**
* Added to the index, then deleted from disk: no change against HEAD, so the change list leaves
* it out, but the staging area shows the staged addition (and the deletion, unstaged).
*/
export function addedThenDeleted(fs: Pick<FileStatus, "staged" | "unstaged">): boolean {
return fs.staged === "added" && fs.unstaged === "deleted";
}
export function isPartiallyStaged(fs: FileStatus): boolean {
return (
!!fs.staged &&
@@ -99,7 +107,9 @@ const KIND_ORDER: GroupId[] = ["conflicts", "changes", "unversioned"];
function fileNode(fs: FileStatus, root: string, group: GroupId, flat: boolean, scope: string = group): ChangeNode {
const path = stripSlash(fs.path);
const rel = relTo(root, path);
const kind = effectiveKind(fs) ?? "modified";
// Under Staged / Unstaged, a file without an overall kind (added, then deleted) shows its side's.
const side = group === "staged" ? fs.staged : group === "unstaged" ? fs.unstaged : null;
const kind = effectiveKind(fs) ?? (side === "added" || side === "deleted" ? side : "modified");
const dir = dirName(rel);
return {
key: `${scope}:${path}`,
@@ -259,7 +269,7 @@ export function buildChangeTree(
const repoRoots = byRepo ? repos : [];
const byGroup = new Map<GroupId, FileStatus[]>();
for (const fs of status) {
const g = groupOf(fs);
const g = groupOf(fs) ?? (byStaging && addedThenDeleted(fs) ? "changes" : null);
if (!g) continue;
let list = byGroup.get(g);
if (!list) byGroup.set(g, (list = []));
@@ -400,8 +410,12 @@ export function planCommit(status: readonly FileStatus[], checks: ReadonlyMap<st
const plan: CommitPlan = { stage: [], exclude: [], included: [], partial: [] };
for (const fs of status) {
if (!groupOf(fs)) {
// Listed nowhere, yet staged: added to the index, then deleted from disk. It is no
// change against HEAD, so the commit must not pick up the staged addition.
// Added to the index, then deleted from disk: no change against HEAD, so the commit
// leaves the staged addition out, unless the staging area commits it (checked "staged").
if (addedThenDeleted(fs) && (checks.get(fs.path) ?? checks.get(stripSlash(fs.path))) === "staged") {
plan.included.push(fs);
continue;
}
if (fs.staged && fs.staged !== "conflicted" && fs.unstaged !== "ignored") plan.exclude.push(stripSlash(fs.path));
continue;
}
+3 -1
Переглянути файл
@@ -5,7 +5,7 @@
*/
import type { ChangelistState, FileStatus } from "@/bindings";
import { useWorkflowSettings, workflowSettings } from "@/platform/workflowSettings";
import { groupOf, type CheckState } from "./changes";
import { addedThenDeleted, groupOf, type CheckState } from "./changes";
import { withListDefaults } from "./changelists";
const enabled = (vcs: { git: { stagingArea: boolean }; commit: { nonModal: boolean } }) =>
@@ -31,6 +31,8 @@ export function stagingChecks(status: readonly FileStatus[]): Map<string, CheckS
const all = isCommitAll(status);
const out = new Map<string, CheckState>();
for (const f of status) {
// A staged addition deleted from disk is committed as staged (nothing against HEAD for Commit All).
if (addedThenDeleted(f) && !all) out.set(f.path, "staged");
if (groupOf(f) !== "changes") continue;
out.set(f.path, all ? "all" : staged(f) ? "staged" : "none");
}