From 099bb57abd9263ba49c91e89d64e6683cb78f437 Mon Sep 17 00:00:00 2001 From: faysou Date: Wed, 2 Dec 2026 13:51:42 +0000 Subject: [PATCH] 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 <893862+faysou@users.noreply.github.com> --- src/features/vcs/__tests__/logPanes.test.tsx | 28 ++++++++++++++++++++ src/features/vcs/logChanges.ts | 4 ++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/features/vcs/__tests__/logPanes.test.tsx b/src/features/vcs/__tests__/logPanes.test.tsx index 269cea458..aabfee7cb 100644 --- a/src/features/vcs/__tests__/logPanes.test.tsx +++ b/src/features/vcs/__tests__/logPanes.test.tsx @@ -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()), @@ -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( [ diff --git a/src/features/vcs/logChanges.ts b/src/features/vcs/logChanges.ts index 58a871bf0..09608d894 100644 --- a/src/features/vcs/logChanges.ts +++ b/src/features/vcs/logChanges.ts @@ -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 }); } /**