Файли
openidea/src/platform/gitEnabled.ts
T
Bert Verhelstтаbertyhell d897236bd7 feat(vcs): add a global Enable Git integration switch (#6704)
Settings > Version Control > Git gets an Enable Git integration master toggle (global, on by default). While it is off the IDE discovers no repositories and runs no git: status, log, blame, fetch, clone, GitHub, the MCP git tools, plugin repository access and agent worktrees refuse to run, and the Git menu, Get from Version Control, the Git, Commit and GitHub Actions tool windows, Git actions and the branch widget are hidden. Turning it back on restores them without reopening the project. Settings pages gain a reusable master toggle that disables the page's sections, and MenuConfig gains a hidden list applied to the native and in-app menus.

Co-authored-by: bertyhell <[email protected]>
2026-11-29 15:45:38 +08:00

51 рядки
1.6 KiB
TypeScript
Неформатований Анотація Історія

Цей файл містить неоднозначні символи Юнікоду
Цей файл містить символи Юнікоду, які можна сплутати з іншими символами. Якщо ви вважаєте, що це зроблено навмисно, можете сміливо ігнорувати це попередження. Щоб показати їх, скористайтеся кнопкою Escape.
/**
* Settings › Version Control › Git › Enable Git integration. Off, the backend finds no
* repositories and refuses the commands that start git on their own (clone, init, GitHub);
* the frontend leaves out every Git action, tool window and menu.
*/
import { setContext } from "./context";
import { onWorkflowSettingsChange, useWorkflowSettings, workflowSettings } from "./workflowSettings";
export function gitEnabled(): boolean {
return workflowSettings().vcs.git.enabled;
}
export function useGitEnabled(): boolean {
return useWorkflowSettings((w) => w.vcs.git.enabled);
}
/**
* Keeps the `gitDisabled` context key (for `when` clauses) in step with the setting.
* Unset it reads as enabled, so a window that never installs it keeps its Git actions.
*/
export function installGitEnabledContext(): () => void {
setContext("gitDisabled", !gitEnabled());
const off = onWorkflowSettingsChange(
(w) => w.vcs.git.enabled,
(on) => setContext("gitDisabled", !on),
);
return () => {
off();
setContext("gitDisabled", false);
};
}
/** Runs `register` while Git integration is on and disposes what it registered while it is off. */
export function whileGitEnabled(register: () => () => void): () => void {
let dispose: (() => void) | null = null;
const sync = (on: boolean) => {
if (on && !dispose) dispose = register();
else if (!on && dispose) {
dispose();
dispose = null;
}
};
sync(gitEnabled());
const off = onWorkflowSettingsChange((w) => w.vcs.git.enabled, sync);
return () => {
off();
dispose?.();
dispose = null;
};
}