mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
23 lines
780 B
TypeScript
23 lines
780 B
TypeScript
import type { LocationGetOutput, OpenCodeClient } from "@opencode/client/promise"
|
|
import type { Data } from "@opencode/client/solid"
|
|
|
|
export async function createWorktree(input: {
|
|
api: Pick<OpenCodeClient, "location" | "worktree">
|
|
data: Pick<Data, "location">
|
|
directory: string
|
|
project?: LocationGetOutput["project"]
|
|
branch?: string
|
|
}) {
|
|
const project = input.project ?? (await input.api.location.get({ location: { directory: input.directory } })).project
|
|
|
|
const created = await input.api.worktree.create({
|
|
projectID: project.id,
|
|
from: project.canonical,
|
|
branch: input.branch,
|
|
})
|
|
|
|
// Populate the client cache before the destination session mounts.
|
|
await input.data.location.syncInfo({ directory: created.directory })
|
|
|
|
return created.directory
|
|
}
|