feat: add project git init api (#16383)

This commit is contained in:
Shoubhit Dash
2026-03-07 01:09:50 +05:30
committed by GitHub
parent 95385eb652
commit d6e0f47361
6 changed files with 280 additions and 21 deletions

View File

@@ -6,6 +6,7 @@ import { Project } from "../../project/project"
import z from "zod"
import { errors } from "../error"
import { lazy } from "../../util/lazy"
import { InstanceBootstrap } from "../../project/bootstrap"
export const ProjectRoutes = lazy(() =>
new Hono()
@@ -52,6 +53,40 @@ export const ProjectRoutes = lazy(() =>
return c.json(Instance.project)
},
)
.post(
"/git/init",
describeRoute({
summary: "Initialize git repository",
description: "Create a git repository for the current project and return the refreshed project info.",
operationId: "project.initGit",
responses: {
200: {
description: "Project information after git initialization",
content: {
"application/json": {
schema: resolver(Project.Info),
},
},
},
},
}),
async (c) => {
const dir = Instance.directory
const prev = Instance.project
const next = await Project.initGit({
directory: dir,
project: prev,
})
if (next.id === prev.id && next.vcs === prev.vcs && next.worktree === prev.worktree) return c.json(next)
await Instance.reload({
directory: dir,
worktree: dir,
project: next,
init: InstanceBootstrap,
})
return c.json(next)
},
)
.patch(
"/:projectID",
describeRoute({