2026-03-04 02:35:38 +00:00
|
|
|
import z from "zod"
|
2026-02-27 20:36:39 +00:00
|
|
|
import { Worktree } from "@/worktree"
|
2026-03-04 02:35:38 +00:00
|
|
|
import { type Adaptor, WorkspaceInfo } from "../types"
|
2026-02-27 20:36:39 +00:00
|
|
|
|
2026-03-04 02:35:38 +00:00
|
|
|
const Config = WorkspaceInfo.extend({
|
|
|
|
|
name: WorkspaceInfo.shape.name.unwrap(),
|
|
|
|
|
branch: WorkspaceInfo.shape.branch.unwrap(),
|
|
|
|
|
directory: WorkspaceInfo.shape.directory.unwrap(),
|
|
|
|
|
})
|
2026-02-27 20:36:39 +00:00
|
|
|
|
2026-03-04 02:35:38 +00:00
|
|
|
type Config = z.infer<typeof Config>
|
|
|
|
|
|
|
|
|
|
export const WorktreeAdaptor: Adaptor = {
|
|
|
|
|
async configure(info) {
|
|
|
|
|
const worktree = await Worktree.makeWorktreeInfo(info.name ?? undefined)
|
2026-02-27 20:36:39 +00:00
|
|
|
return {
|
2026-03-04 02:35:38 +00:00
|
|
|
...info,
|
|
|
|
|
name: worktree.name,
|
|
|
|
|
branch: worktree.branch,
|
|
|
|
|
directory: worktree.directory,
|
2026-02-27 20:36:39 +00:00
|
|
|
}
|
|
|
|
|
},
|
2026-03-04 02:35:38 +00:00
|
|
|
async create(info) {
|
|
|
|
|
const config = Config.parse(info)
|
2026-03-25 00:26:21 +00:00
|
|
|
await Worktree.createFromInfo({
|
2026-03-04 02:35:38 +00:00
|
|
|
name: config.name,
|
|
|
|
|
directory: config.directory,
|
|
|
|
|
branch: config.branch,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
async remove(info) {
|
|
|
|
|
const config = Config.parse(info)
|
2026-02-27 20:36:39 +00:00
|
|
|
await Worktree.remove({ directory: config.directory })
|
|
|
|
|
},
|
2026-04-07 03:19:55 +00:00
|
|
|
target(info) {
|
|
|
|
|
const config = Config.parse(info)
|
|
|
|
|
return {
|
|
|
|
|
type: "local",
|
|
|
|
|
directory: config.directory,
|
|
|
|
|
}
|
2026-02-27 20:36:39 +00:00
|
|
|
},
|
|
|
|
|
}
|