M4.7: blame annotations in the editor gutter

- crates/vcs: blame.rs (git blame --porcelain, --contents - from a
  buffer, revisions, untracked files and empty repositories give no
  lines; property-tested parser, ISO dates without a date crate)
- engine: git.blame {path, rev?} -> {lines, version} through start_with;
  an open buffer is blamed as it would be saved (line ending, BOM)
- ui: blame.ts gutter toggled per file (vcs.toggleBlame, Git menu, no
  shortcut), date + author per run, bar coloured by age from tokens,
  hover card with the full commit message, click opens the commit in
  the Log (vcs.showCommit); refreshed on edits and gitChanged
- docs: architecture "Blame (M4.7)"

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-30 17:52:44 +01:00
parent dc4a00ea0b
commit 2f758d76b9
18 changed files with 2003 additions and 3 deletions

View file

@ -4,7 +4,8 @@
* `gitChanged` when HEAD moves, commit details, the Log window (rows,
* badges, keyboard, filters, history chip), a file's diff at a commit in
* the diff viewer (both sides read-only), `vcs.showHistory` and the tree's
* context menu. The engine is a fake behind the mocked Tauri `invoke` and
* context menu, and `vcs.showCommit` / `vcs.toggleBlame` from the main
* layout (M4.7). The engine is a fake behind the mocked Tauri `invoke` and
* `listen`.
*/
import { flushPromises, mount, type VueWrapper } from "@vue/test-utils";
@ -18,7 +19,9 @@ vi.mock("@tauri-apps/api/event", () => ({ listen }));
import { useCommandsStore } from "../../src/commands/store";
import { UI_COMMANDS } from "../../src/commands/uiCommands";
import { isBlameShown, SHOW_COMMIT_COMMAND, TOGGLE_BLAME_COMMAND } from "../../src/components/editor/blame";
import EditorArea from "../../src/components/editor/EditorArea.vue";
import MainLayout from "../../src/components/layout/MainLayout.vue";
import TreeContextMenu from "../../src/components/project/TreeContextMenu.vue";
import { commitDiffKey, useDiffStore } from "../../src/components/vcs/diff/diff";
import { currentMerge } from "../../src/components/vcs/diff/navigation";
@ -481,3 +484,32 @@ describe("commands", () => {
expect(run).toHaveBeenCalledWith({ path: "src/a.php" });
});
});
describe("blame commands in the main layout (M4.7)", () => {
it("shows a commit in the Log and toggles a file's annotations", async () => {
useProjectStore(pinia).root = { path: "/p", name: "p" };
const wrapper = mount(MainLayout, {
attachTo: document.body,
global: { plugins: [pinia], stubs: { ProjectToolWindow: true, StatusBar: true } },
});
mounted.push(wrapper);
const commands = useCommandsStore(pinia);
await commands.start();
await flushPromises();
await commands.execute(SHOW_COMMIT_COMMAND, { hash: "a" });
await flushPromises();
expect(callsOf("git.showCommit")).toEqual([]);
await commands.execute(SHOW_COMMIT_COMMAND, { hash: "abcd" });
await flushPromises();
const log = useLogStore(pinia);
expect(log.visible).toBe(true);
expect(log.selected).toBe("abcd");
expect(callsOf("git.showCommit").at(-1)).toEqual({ hash: "abcd" });
await commands.execute(TOGGLE_BLAME_COMMAND, { path: "src/a.php" });
expect(isBlameShown("src/a.php")).toBe(true);
await commands.execute(TOGGLE_BLAME_COMMAND, { path: "src/a.php" });
expect(isBlameShown("src/a.php")).toBe(false);
});
});