mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
fix(vcs): Add to .gitignore and Show History act on the focused Project view (#5215)
Add to .gitignore, Add to .git/info/exclude and Show History for File took the active editor's file even when the shortcut was pressed in the Project view. Like Add to VCS they now take the Project view's selection while it has focus and the open file otherwise.
This commit is contained in:
@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { FileStatus } from "@/bindings";
|
||||
|
||||
const stage = vi.hoisted(() => vi.fn(async () => ({ status: "ok", data: null })));
|
||||
const ignore = vi.hoisted(() => vi.fn(async () => ({ status: "ok", data: [] })));
|
||||
const notify = vi.hoisted(() => vi.fn());
|
||||
const project = vi.hoisted(() => ({ paths: [] as string[] }));
|
||||
|
||||
@@ -12,6 +13,7 @@ vi.mock("@/platform/ipc", async (importOriginal) => {
|
||||
commands: {
|
||||
...real.commands,
|
||||
vcsStage: stage,
|
||||
vcsAddToIgnore: ignore,
|
||||
vcsStatus: async () => ({ status: "ok", data: [] }),
|
||||
vcsBranchInfo: async () => ({ status: "ok", data: null }),
|
||||
vcsRoots: async () => ({ status: "ok", data: [{ root: "/repo", operation: null }] }),
|
||||
@@ -43,6 +45,7 @@ let unregister: () => void;
|
||||
|
||||
beforeEach(() => {
|
||||
stage.mockClear();
|
||||
ignore.mockClear();
|
||||
notify.mockClear();
|
||||
project.paths = [];
|
||||
const files = [fs("dir/new.ts", "untracked"), fs("dir/sub/n2.ts", "untracked"), fs("dir/tracked.ts", "modified")];
|
||||
@@ -82,3 +85,14 @@ describe("Add to VCS", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Add to .gitignore", () => {
|
||||
it("ignores the Project view's selection while it has focus, and not otherwise", async () => {
|
||||
project.paths = ["/repo/dir/new.ts"];
|
||||
await getAction("vcs.ignoreShared")!.run({ arg: undefined, ctx: { vcsAvailable: true, projectViewFocus: true } });
|
||||
expect(ignore).toHaveBeenCalledWith(["/repo/dir/new.ts"], "gitignore");
|
||||
ignore.mockClear();
|
||||
await getAction("vcs.ignoreShared")!.run({ arg: undefined, ctx: { vcsAvailable: true } });
|
||||
expect(ignore).not.toHaveBeenCalledWith(["/repo/dir/new.ts"], "gitignore");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -156,6 +156,11 @@ function selectedPaths(arg: unknown): string[] {
|
||||
return project.length ? project : contextPaths(arg);
|
||||
}
|
||||
|
||||
/** Paths a file action targets: the Project view's selection while it has focus, else the open file. */
|
||||
function focusedPaths(arg: unknown, ctx: { projectViewFocus?: unknown }): string[] {
|
||||
return ctx.projectViewFocus ? selectedPaths(arg) : contextPaths(arg);
|
||||
}
|
||||
|
||||
/**
|
||||
* The repository a repository-wide dialog (Pull, Merge, Rebase) starts on: the one holding the
|
||||
* action's file, else the Project view's selection while it has focus, else the active editor's
|
||||
@@ -661,8 +666,8 @@ export function registerVcsActions(): () => void {
|
||||
category: "Git",
|
||||
icon: "history",
|
||||
when: VCS,
|
||||
run: ({ arg }) => {
|
||||
const path = contextPaths(arg)[0];
|
||||
run: ({ arg, ctx }) => {
|
||||
const path = focusedPaths(arg, ctx)[0];
|
||||
if (!path) return;
|
||||
openLogTab("history", path);
|
||||
showGitWindow();
|
||||
@@ -717,7 +722,7 @@ export function registerVcsActions(): () => void {
|
||||
category: "Git",
|
||||
when: VCS,
|
||||
keywords: ["ignore", "unversioned", "exclude"],
|
||||
run: ({ arg }) => addToIgnore(contextPaths(arg), destination),
|
||||
run: ({ arg, ctx }) => addToIgnore(focusedPaths(arg, ctx), destination),
|
||||
})),
|
||||
{
|
||||
id: "vcs.addToVcs",
|
||||
@@ -726,8 +731,7 @@ export function registerVcsActions(): () => void {
|
||||
icon: "plus",
|
||||
when: VCS,
|
||||
keywords: ["git add", "stage"],
|
||||
// The Project view's selection only while it has focus: from the editor it is the open file.
|
||||
run: ({ arg, ctx }) => addToVcs(ctx.projectViewFocus ? selectedPaths(arg) : contextPaths(arg)),
|
||||
run: ({ arg, ctx }) => addToVcs(focusedPaths(arg, ctx)),
|
||||
},
|
||||
{
|
||||
id: "vcs.stash",
|
||||
|
||||
Reference in New Issue
Block a user