fix(vcs): skip missing sources when jumping from Git Log (#7550)

Jump to Source in the Git Log opened an error tab when the selected file no longer exists at that path in the working tree. It now checks the working tree first and only opens an existing file. Open Repository Version still opens the historical snapshot.

Co-authored-by: faysou <[email protected]>
Цей коміт міститься в:
faysouтаfaysou authored and GitHub committed 2026-12-02 21:51:42 +08:00
1 джерело 1ba2ce55bb
коміт 099bb57abd
2 files changed
+31 -1

No files matched your search

+28
Переглянути файл
@@ -1,11 +1,13 @@
import type { Branch, Commit } from "@/bindings";
import { getAction } from "@/platform/actions";
import { maybeEditorService, provideEditorService } from "@/workbench/contributions";
import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
const vcsCommitFiles = vi.fn();
const vcsDiffNumstat = vi.fn();
const vcsTags = vi.fn();
const fsEntryKind = vi.fn();
const { deleteBranches, openRevisionFile } = vi.hoisted(() => ({ deleteBranches: vi.fn(), openRevisionFile: vi.fn() }));
vi.mock("../branchOps", async (original) => ({
...(await original<typeof import("../branchOps")>()),
@@ -22,6 +24,7 @@ vi.mock("@/platform/ipc", async (importOriginal) => {
...real,
commands: {
...real.commands,
fsEntryKind: (path: string) => fsEntryKind(path),
vcsCommitFiles: (repo: unknown, id: string) => vcsCommitFiles(repo, id),
vcsDiffNumstat: (repo: unknown, from: string, to: string, paths: string[]) =>
vcsDiffNumstat(repo, from, to, paths),
@@ -48,6 +51,7 @@ import {
flatFileNodes,
lineStatRanges,
logPatchRanges,
openChangeSource,
toLogChanges,
useLogChanges,
} from "../logChanges";
@@ -91,6 +95,7 @@ afterEach(() => {
vcsCommitFiles.mockReset();
vcsDiffNumstat.mockReset();
vcsTags.mockReset();
fsEntryKind.mockReset();
deleteBranches.mockReset();
openRevisionFile.mockReset();
useLogChanges.setState({ commits: [], all: [], selected: [] });
@@ -238,6 +243,29 @@ describe("changed files model", () => {
expect(item).toMatchObject({ disabled: true });
});
it("jumps only to existing working files from the Git Log", async () => {
const paths = ["docs/old-guide.md", "docs/guide.md", "replaced-by-directory.md"];
const changes = toLogChanges(
paths.map((path) => ({ path, kind: "added", oldPath: null })),
commit,
"/repo",
);
fsEntryKind
.mockResolvedValueOnce({ status: "error", error: { kind: "notFound", message: "File does not exist" } })
.mockResolvedValueOnce({ status: "ok", data: "file" })
.mockResolvedValueOnce({ status: "ok", data: "dir" });
const previousService = maybeEditorService();
const openFile = vi.fn(async () => {});
provideEditorService({ ...previousService!, openFile });
try {
await Promise.all(changes.map(openChangeSource));
} finally {
provideEditorService(previousService);
}
expect(fsEntryKind.mock.calls).toEqual(paths.map((path) => [`/repo/${path}`]));
expect(openFile.mock.calls).toEqual([[`/repo/${paths[1]}`, { focus: true }]]);
});
it("enables Open Repository Version for any file with an after revision, including read-only files", () => {
const [deleted, directory, readOnly] = toLogChanges(
[
+3 -1
Переглянути файл
@@ -358,7 +358,9 @@ export async function compareChangesWithLocal(changes: readonly LogChange[], sid
/** Jump to Source: the working file. */
export async function openChangeSource(change: LogChange) {
if (change.readOnly) return;
await editorService().openFile(absolutePath(change.path, change.repo), { focus: true });
const path = absolutePath(change.path, change.repo);
const kind = await call(commands.fsEntryKind(path)).catch(() => null);
if (kind === "file") await editorService().openFile(path, { focus: true });
}
/**