Skip to content

Commit 5983a2f

Browse files
committed
feat(daemon): add POST /git/checkout-branch endpoint
Adds a new git endpoint that creates and checks out a local branch from the current working state, enabling the open-pull-request workflow without publishing directly to main. Made-with: Cursor
1 parent b45a2ae commit 5983a2f

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

daemon/git.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,15 @@ export interface RebaseAPI {
315315
};
316316
}
317317

318+
export interface CheckoutBranchAPI {
319+
body: {
320+
branchName: string;
321+
};
322+
response: {
323+
branch: string;
324+
};
325+
}
326+
318327
const abortRebase = async () => {
319328
await git.rebase({ "--abort": null });
320329
throw new Error(
@@ -751,6 +760,18 @@ interface Options {
751760
site: string;
752761
}
753762

763+
export const checkoutBranch: Handler = async (c) => {
764+
const { branchName } = (await c.req.json()) as CheckoutBranchAPI["body"];
765+
766+
if (!branchName || !/^[a-zA-Z0-9_\-./]+$/.test(branchName)) {
767+
return new Response("Invalid branch name", { status: 400 });
768+
}
769+
770+
await git.checkoutLocalBranch(branchName);
771+
772+
return Response.json({ branch: branchName });
773+
};
774+
754775
export const createGitAPIS = (options: Options) => {
755776
const app = new Hono();
756777

@@ -761,6 +782,7 @@ export const createGitAPIS = (options: Options) => {
761782
app.post("/publish", publish(options));
762783
app.post("/discard", discard);
763784
app.post("/rebase", rebase);
785+
app.post("/checkout-branch", checkoutBranch);
764786

765787
return app;
766788
};

daemon/mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type {
1717
} from "./fs/common.ts";
1818
export type {
1919
CheckoutAPI,
20+
CheckoutBranchAPI,
2021
GitDiffAPI,
2122
GitLogAPI,
2223
GitStatusAPI,

0 commit comments

Comments
 (0)