дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
fix(vcs): annotate, show history and gutter of a renamed file against its committed name (#8196)
After a staged rename (git mv, or a moved file added to the index) and an edit, Annotate said the file had no committed history, Show History for File was empty and the gutter marked every line as added: blame, the gutter's base and the file history looked the new name up in HEAD, which only has the old one. When a path is in the index but not in HEAD, Repo::committed_path finds HEAD's name from the staged rename with the same rename detection status uses, and blame, line hunks and the file history read the file under that name. Inline blame, Show Current Revision and Compare with Revision look it up under the committed name too; the author lens and "reformat only changed text" follow from the same commands. Co-authored-by: ntbang0901 <[email protected]>
Цей коміт міститься в:
1 джерело
94a28cbd1d
коміт
ec4da5efa5
11 files changed
+166
-11
No files matched your search
@@ -90,6 +90,20 @@ for (const id of ["vcs.compareWithRevision", "vcs.showCurrentRevision"]) {
|
||||
useVcs.setState({ statusLoaded: false });
|
||||
expect(isActionEnabled(action, { vcsAvailable: true })).toBe(false);
|
||||
});
|
||||
|
||||
it("offers a staged rename, whose history HEAD has under its old name", () => {
|
||||
const action = getAction(id)!;
|
||||
expect(isActionEnabled(action, { vcsAvailable: true }, "/repo/moved.txt")).toBe(false);
|
||||
const moved = {
|
||||
path: "/repo/moved.txt",
|
||||
relPath: "moved.txt",
|
||||
renamedFrom: "other.txt",
|
||||
staged: "renamed",
|
||||
unstaged: "modified",
|
||||
} as const;
|
||||
useVcs.setState({ byPath: new Map([["/repo/moved.txt", moved]]) });
|
||||
expect(isActionEnabled(action, { vcsAvailable: true }, "/repo/moved.txt")).toBe(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -363,6 +363,25 @@ describe("current line decoration", () => {
|
||||
expect(hint()).toBeNull();
|
||||
});
|
||||
|
||||
it("blames a staged rename, which HEAD has under its old name", async () => {
|
||||
const moved = {
|
||||
path: ctx.path,
|
||||
relPath: "file.ts",
|
||||
staged: "renamed",
|
||||
unstaged: null,
|
||||
renamedFrom: "old.ts",
|
||||
} as const;
|
||||
useVcs.setState({ byPath: new Map([[ctx.path, moved]]) });
|
||||
mocks.file.mockImplementation(async (path: string) => ({
|
||||
status: "ok",
|
||||
data: path === "/repo/old.ts" ? "x" : null,
|
||||
}));
|
||||
editor();
|
||||
await tick();
|
||||
expect(mocks.file).toHaveBeenCalledWith("/repo/old.ts", "HEAD");
|
||||
expect(hint()?.textContent).toContain("Alice Smith");
|
||||
});
|
||||
|
||||
it("skips paths outside repositories", async () => {
|
||||
editor("one", { ...ctx, path: "/elsewhere/file.ts" });
|
||||
await tick();
|
||||
|
||||
@@ -568,6 +568,11 @@ export function renamedFromPath(fs: FileStatus): string | null {
|
||||
return segments.length > depth ? `${segments.slice(0, -depth).join("/")}/${fs.renamedFrom}` : null;
|
||||
}
|
||||
|
||||
/** The path HEAD has the file at `path` under: the source of its staged rename, else `path`. */
|
||||
export function committedPath(fs: FileStatus | undefined, path: string): string {
|
||||
return (fs?.staged === "renamed" && renamedFromPath(fs)) || path;
|
||||
}
|
||||
|
||||
/** What the commit takes beyond the index, and what staged changes it leaves out. */
|
||||
export function planCommit(
|
||||
status: readonly FileStatus[],
|
||||
|
||||
@@ -3,6 +3,7 @@ import { setContext } from "@/platform/context";
|
||||
import { call, commands } from "@/platform/ipc";
|
||||
import { editorService, notifications, toolWindowService } from "@/workbench/contributions";
|
||||
import { isUncommitted } from "./blame";
|
||||
import { committedPath } from "./changes";
|
||||
import { revealCommit } from "./logStore";
|
||||
import { repoOf, statusOf, useVcs } from "./store";
|
||||
import { repositoryPath } from "./repositoryPaths";
|
||||
@@ -48,8 +49,8 @@ export function hasFileHistory(path: string | null | undefined): boolean {
|
||||
// A working copy of another system lists every file it does not have as unversioned (or added):
|
||||
// the others have a committed revision.
|
||||
const git = (useVcs.getState().kinds[repo] ?? "git") === "git";
|
||||
if (git && !historyFiles.get(repo)?.files.has(path)) return false;
|
||||
const status = statusOf(path);
|
||||
if (git && !historyFiles.get(repo)?.files.has(committedPath(status, path))) return false;
|
||||
return ![status?.staged, status?.unstaged].some(
|
||||
(kind) => kind === "untracked" || kind === "ignored" || kind === "added" || kind === "deleted",
|
||||
);
|
||||
|
||||
@@ -16,6 +16,7 @@ import { tx, useI18n } from "@/platform/i18n";
|
||||
import { call, commands, isTauri } from "@/platform/ipc";
|
||||
import { onWorkflowSettingsChange, workflowSettings } from "@/platform/workflowSettings";
|
||||
import { isUncommitted } from "./blame";
|
||||
import { committedPath } from "./changes";
|
||||
import { repoOf, statusOf, useVcs } from "./store";
|
||||
|
||||
export function relativeBlameDate(timeMs: number | null, now = Date.now()): string {
|
||||
@@ -404,7 +405,8 @@ export function inlineBlame(ctx: EditorDocContext): Extension {
|
||||
try {
|
||||
const lines = await this.cache.get(doc, async () => {
|
||||
// Blame also returns synthetic entries for paths absent from HEAD (ignored / new files).
|
||||
if ((await call(commands.vcsFileAt(ctx.path, "HEAD"))) === null) return [];
|
||||
const head = committedPath(statusOf(ctx.path), ctx.path);
|
||||
if ((await call(commands.vcsFileAt(head, "HEAD"))) === null) return [];
|
||||
return call(commands.vcsBlame(ctx.path, doc.toString(), null));
|
||||
});
|
||||
if (this.destroyed || generation !== this.generation || doc !== this.view.state.doc || !this.enabled())
|
||||
|
||||
Reference in new issue
Заблокувати користувача