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

...
Автор SHA1 Повідомлення Дата
l0ng-ai 234072e740 fix(vcs): list a merge's own changes above its parents' in Git Log
With Show Changes from Parents on, a merge commit's changes listed only
one group per parent ("Parent 1: <hash>"), and in the flat view those
groups were not shown at all, so the files of both parents interleaved.

The merge's own changes (files changed against every parent) now come
first, followed by a "Changes to <hash> <subject>" node per parent, in
both the flat and the directory view. A merge with no changes of its own
shows "No merge conflicts" there. The parent filter keeps the merge's
own changes and the chosen parent's node.

Fixes #6691
2026-11-28 20:45:09 +08:00
3 змінених файлів з 105 додано та 14 видалено

No files matched your search

+51 -1
Переглянути файл
@@ -544,11 +544,61 @@ describe("commit details", () => {
<ContextMenuHost />
</>,
);
expect(await screen.findByText("4 files")).toBeInTheDocument();
// The merge's own two changes, then each parent's two under "Changes to <parent>".
expect(await screen.findByText("6 files")).toBeInTheDocument();
expect(api.diff).toHaveBeenCalledWith("/repo", "p1", "merge");
expect(screen.getByText("Changes to p1")).toBeInTheDocument();
expect(screen.getByText("Changes to p2")).toBeInTheDocument();
expect(screen.queryByText("c.ts")).toBeNull();
fireEvent.click(screen.getByRole("button", { name: "All Parents" }));
fireEvent.click(await screen.findByRole("menuitemcheckbox", { name: "Parent 2: p2" }));
await waitFor(() => expect(api.diff).toHaveBeenLastCalledWith("/repo", "p2", "merge"));
expect(await screen.findByText("4 files")).toBeInTheDocument();
expect(screen.queryByText("Changes to p1")).toBeNull();
expect(screen.getByText("Changes to p2")).toBeInTheDocument();
});
it("lists a merge's own changes above each parent's, like IDEA's Show Changes to Parents", async () => {
const merge = { ...c("merge", ["p1", "p2"]), repo: "/repo" };
const p2 = { ...c("p2", ["base"]), repo: "/repo", summary: "fix: pricing" };
api.diff.mockImplementation(async (_repo: string, from: string) => ({
status: "ok",
data:
from === "p1"
? [
{ path: "app/Posts.php", kind: "modified", oldPath: null, before: "p1", after: "merge" },
{ path: "config/pricing.php", kind: "modified", oldPath: null, before: "p1", after: "merge" },
]
: [{ path: "app/Posts.php", kind: "modified", oldPath: null, before: "p2", after: "merge" }],
}));
useGitLog.setState({ commits: [merge, p2], selected: commitKey(merge), selection: [commitKey(merge)] });
useLogOptions.setState({ changesFromParents: false, showOnlyAffected: false });
const view = render(<CommitDetails commits={[merge, p2]} />);
// Off: only the merge's own change.
expect(await screen.findByText("Posts.php")).toBeInTheDocument();
expect(screen.queryByText("pricing.php")).toBeNull();
expect(screen.queryByText(/^Changes to/)).toBeNull();
view.unmount();
useLogOptions.setState({ changesFromParents: true });
render(<CommitDetails commits={[merge, p2]} />);
expect(await screen.findByText("4 files")).toBeInTheDocument();
const rows = screen.getAllByRole("treeitem").map((r) => r.textContent ?? "");
const at = (text: string) => rows.findIndex((r) => r.includes(text));
expect(at("Posts.php")).toBeLessThan(at("Changes to p1"));
expect(at("Changes to p1")).toBeLessThan(at("Changes to p2 fix: pricing"));
});
it("says a merge without changes of its own has no merge conflicts", async () => {
const merge = { ...c("merge", ["p1", "p2"]), repo: "/repo" };
api.diff.mockImplementation(async (_repo: string, from: string) => ({
status: "ok",
data: [{ path: `${from}.ts`, kind: "modified", oldPath: null, before: from, after: "merge" }],
}));
useGitLog.setState({ commits: [merge], selected: commitKey(merge), selection: [commitKey(merge)] });
useLogOptions.setState({ changesFromParents: true, showOnlyAffected: false });
render(<CommitDetails commits={[merge]} />);
expect(await screen.findByText("No merge conflicts")).toBeInTheDocument();
expect(screen.getByText("2 files")).toBeInTheDocument();
});
});
+53 -13
Переглянути файл
@@ -76,6 +76,11 @@ function fileNodeAt<F>(nodes: readonly FileTreeNode<F>[], key: string): FileTree
return null;
}
/** `nodes` with `prefix` on every key: the same file under two parents of a merge stays two rows. */
function keyPrefixed<F>(nodes: readonly FileTreeNode<F>[], prefix: string): FileTreeNode<F>[] {
return nodes.map((n) => ({ ...n, key: `${prefix}${n.key}`, children: keyPrefixed(n.children, prefix) }));
}
/**
* The selected commits' changes: one commit's files against its first parent, or, for several
* (IDEA), their combined changes with every selected commit listed below.
@@ -139,25 +144,28 @@ export function CommitDetails({ commits, fileHistory = false }: { commits: Commi
const c = chosen[0]!;
if (c.parents.length > 1) {
const groups = await Promise.all(
c.parents.map(async (id, index) => {
c.parents.map(async (id) => {
const files = await call(commands.vcsDiffRevisions(commitRoot ?? currentRepo(), id, c.id));
return toLogChanges(files, { ...c, parents: [id] }, commitRoot, readOnly).map((f) => ({
...f,
group: `${tx("Parent")} ${index + 1}: ${id.slice(0, 8)}`,
}));
return toLogChanges(files, { ...c, parents: [id] }, commitRoot, readOnly);
}),
);
if (fromParents) return parentIndex < 0 ? groups.flat() : (groups[parentIndex] ?? []);
// A merge's combined changes are files changed against every parent.
return groups[0]!
const merged = groups[0]!
.filter((f) => groups.every((group) => group.some((x) => x.path === f.path)))
.map((f) => ({
...f,
group: undefined,
mergeParents: c.parents
.slice(0, 2)
.map((rev, i) => ({ rev, path: groups[i]!.find((x) => x.path === f.path)?.oldPath ?? f.path })),
}));
if (!fromParents) return merged;
// IDEA's Show Changes to Parents: the merge's own changes, then "Changes to <parent>" for each parent.
return [
...merged,
...groups.flatMap((files, index) =>
parentIndex < 0 || parentIndex === index ? files.map((f) => ({ ...f, group: c.parents[index]! })) : [],
),
];
}
const files = await call(commands.vcsCommitFiles(commitRoot ?? currentRepo(), c.id));
return toLogChanges(files, c, commitRoot, readOnly);
@@ -204,13 +212,35 @@ export function CommitDetails({ commits, fileHistory = false }: { commits: Commi
}, [changes, showLineStats]);
const multipleRoots = new Set(chosen.map(commitRepo)).size > 1;
const changeTreePath = useCallback(
(f: LogChange) => `${multipleRoots ? `${repoName(f.repo ?? "")}/` : ""}${f.group ? `${f.group}/` : ""}${f.path}`,
(f: LogChange) => `${multipleRoots ? `${repoName(f.repo ?? "")}/` : ""}${f.path}`,
[multipleRoots],
);
const tree = useMemo(
() => (groupByDirectory ? buildFileTree(changes, changeTreePath) : flatFileNodes(changes, changeTreePath)),
[changes, groupByDirectory, changeTreePath],
);
const tree = useMemo(() => {
const build = (files: readonly LogChange[]) =>
groupByDirectory ? buildFileTree(files, changeTreePath) : flatFileNodes(files, changeTreePath);
const parents = [...new Set(changes.flatMap((f) => (f.group ? [f.group] : [])))];
if (!parents.length) return build(changes);
// A merge with Show Changes to Parents (IDEA): its own changes, then a node per parent.
const own = changes.filter((f) => !f.group);
const ownNodes: FileTreeNode<LogChange>[] = own.length
? build(own)
: [{ key: "merge:none", name: tx("No merge conflicts"), file: null, children: [], count: 0 }];
return [
...ownNodes,
...parents.map((id): FileTreeNode<LogChange> => {
const children = keyPrefixed(build(changes.filter((f) => f.group === id)), `parent:${id}:`);
const summary = commit && commits.find((p) => p.id === id && commitRepo(p) === commitRoot)?.summary;
const parent = summary ? `${id.slice(0, 8)} ${summary}` : id.slice(0, 8);
return {
key: `parent:${id}`,
name: tx`Changes to ${parent}`,
file: null,
children,
count: children.reduce((n, c) => n + c.count, 0),
};
}),
];
}, [changes, groupByDirectory, changeTreePath, commits, commit, commitRoot]);
const allDirs = useMemo(() => dirKeys(tree), [tree]);
const ordered = useMemo(() => filesUnder(tree), [tree]);
const chosenChanges = useMemo(() => filesUnder(tree, selectedKeys), [tree, selectedKeys]);
@@ -610,6 +640,16 @@ function LineStats({ added, removed }: { added: number; removed: number }) {
function ChangedFileRow({ node, flat = false }: { node: FileTreeNode<ChangedFile | LogChange>; flat?: boolean }) {
const stats = nodeLineCount(node);
// A merge's "No merge conflicts" and "Changes to <parent>" nodes are labels, not folders (IDEA's tag nodes).
if (node.key === "merge:none") return <span className={clsx(styles.fileRow, styles.fileDir)}>{node.name}</span>;
if (!node.file && node.key.startsWith("parent:") && !node.key.slice("parent:".length).includes(":"))
return (
<span className={styles.fileRow}>
<span className={styles.fileName}>{node.name}</span>
<span className={styles.fileDir}>{fileCount(node.count)}</span>
{stats && <LineStats added={stats.added} removed={stats.removed} />}
</span>
);
if (!node.file)
return (
<span className={styles.fileRow}>
+1
Переглянути файл
@@ -7940,6 +7940,7 @@
"Collapse or expand this branch": "折叠或展开此分支",
"Diff Preview Location": "差异预览位置",
"Parent": "父提交",
"Changes to {parent}": "对 {parent} 的更改",
"Committed by": "提交者",
"Merge of": "合并自",
"Containing branches": "包含此提交的分支",