switchBranch
uses process
Work on the branch name: the codebase's own moves to it, as tcm switch does (and this browser reads it, as its
own). Not under tcm dev, which serves a session's branch (TCM_BRANCH): that stays on its own.
import { HttpError, setCookie } from "#codebase/tcmts/server"; import { BRANCH_COOKIE, branchingCodebase, runTcm, tcmSaid } from "#codebase/tcmts/studio"; export async function switchBranch(name: string): Promise<string> { const cb = branchingCodebase(); if (process.env.TCM_BRANCH) throw new HttpError( 409, `This studio serves the branch ${process.env.TCM_BRANCH} (TCM_BRANCH), which it stays on: reading another is the branch menu's.`, ); const out = tcmSaid(await runTcm(cb.lay.root, ["switch", name]), "tcm switch"); cb.store.forgetBranch(); setCookie(BRANCH_COOKIE, "", { maxAge: 0, sameSite: "Strict", path: "/" }); return out; }
uses
- tcmts.server.HttpError
- tcmts.server.setCookie
- tcmts.studio.BRANCH_COOKIE
- tcmts.studio.branchingCodebase
- tcmts.studio.runTcm
- tcmts.studio.tcmSaid