Compare commits

...
Author SHA1 Message Date
l0ng-ai 4522b9a5e1 feat(vcs): create a Git repository for a project that has none
Git › Create Git Repository… asks for the folder (the project root by default),
runs git init there and picks up the new repository, so the branch widget,
the Commit tool window and file statuses appear without reopening the project.
The title bar's Version Control menu, shown while a project has no repository,
lists it first.
2026-11-13 20:38:50 +08:00
6 changed files with 48 additions and 4 deletions

No files matched your search

+10
View File
@@ -49,6 +49,7 @@ import { allRepos, runRemote } from "./ops";
import { showPushDialog, showUpdateDialog, type PushTarget, type UpdateTarget } from "./remoteUi";
import { comparePathsWithRevision, showDirectoryWorkingDiff } from "./comparePaths";
import { showCloneDialog } from "./clone";
import { createRepository } from "./createRepository";
import {
showManageRemotes,
showMergeDialog,
@@ -246,6 +247,15 @@ export function registerVcsActions(): () => void {
keyWhen: IN_COMMIT_WINDOW,
run: () => useCommit.setState((s) => ({ historyTick: s.historyTick + 1 })),
},
{
id: "vcs.createRepository",
title: "Create Git Repository…",
category: "Git",
icon: "branch",
when: "projectOpen && projectLocal",
keywords: ["init", "git", "enable version control"],
run: () => createRepository(),
},
{
id: "vcs.clone",
title: "Get from Version Control…",
+26
View File
@@ -0,0 +1,26 @@
/** 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();
}
+1 -1
View File
@@ -266,7 +266,7 @@ export function statusOf(path: string): FileStatus | undefined {
}
/** Repositories found below a project that is not itself under git (scanned in the background). */
async function discoverRoots() {
export async function discoverRoots() {
const root = useVcs.getState().root;
if (!root || !isTauri()) return;
const roots = await call(commands.vcsRoots()).catch(() => []);
+5 -1
View File
@@ -1510,5 +1510,9 @@
"{name} (group)": "{name} (group)",
"Servers in group": "Servers in group",
"Upload to… on this group uploads the files to each of its servers in turn.": "Upload to… on this group uploads the files to each of its servers in turn.",
"Server Group": "Server Group"
"Server Group": "Server Group",
"Create Git Repository…": "Create Git Repository…",
"Select Directory for Git Init": "Select Directory for Git Init",
"Couldn't create Git repository": "Couldn't create Git repository",
"Created Git repository in {dir}": "Created Git repository in {dir}"
}
+5 -1
View File
@@ -7911,5 +7911,9 @@
"{name} (group)": "{name}(分组)",
"Servers in group": "组内服务器",
"Upload to… on this group uploads the files to each of its servers in turn.": "对此分组执行“上传到…”时,会依次上传到组内的每台服务器。",
"Server Group": "服务器分组"
"Server Group": "服务器分组",
"Create Git Repository…": "创建 Git 仓库…",
"Select Directory for Git Init": "选择要执行 Git Init 的目录",
"Couldn't create Git repository": "无法创建 Git 仓库",
"Created Git repository in {dir}": "已在 {dir} 创建 Git 仓库"
}
+1 -1
View File
@@ -95,7 +95,7 @@ function ProjectButton() {
);
}
const VCS_FALLBACK_ACTIONS = ["vcs.clone", "vcs.localHistory", "vcs.showLog"];
const VCS_FALLBACK_ACTIONS = ["vcs.createRepository", "vcs.clone", "vcs.localHistory", "vcs.showLog"];
/** "Version Control ▾" shown while no VCS widget is contributed (project without a repository). */
function VcsFallback() {