mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
Git › Create Git Repository… asks for the folder (the project root by default), runs git init and rescans for repositories, so the branch widget, Commit tool window and file statuses appear right away. The title bar's Version Control menu for projects without a repository lists it first.
27 lines
1001 B
TypeScript
27 lines
1001 B
TypeScript
/** VCS › Create Git Repository…: `git init` in a folder chosen under the project. */
|
||
import { open } from "@/platform/dialog";
|
||
import { tx } from "@/platform/i18n";
|
||
import { call, commands } from "@/platform/ipc";
|
||
import { useProject } from "@/platform/project";
|
||
import { notifications } from "@/workbench/contributions";
|
||
import { discoverRoots } from "./store";
|
||
|
||
export async function createRepository() {
|
||
const root = useProject.getState().project?.root;
|
||
const dir = await open({ title: tx("Select Directory for Git Init"), directory: true, defaultPath: root });
|
||
if (typeof dir !== "string") return;
|
||
try {
|
||
await call(commands.vcsInit(dir));
|
||
} catch (e) {
|
||
notifications().notify({
|
||
group: "vcs",
|
||
level: "error",
|
||
title: tx("Couldn't create Git repository"),
|
||
body: String((e as Error)?.message ?? e),
|
||
});
|
||
return;
|
||
}
|
||
notifications().notify({ group: "vcs", level: "info", title: tx`Created Git repository in ${dir}` });
|
||
await discoverRoots();
|
||
}
|