chore: cleanup

This commit is contained in:
adamelmore
2026-01-25 13:19:23 -06:00
committed by Adam
parent 94ce289dd9
commit 407f34fed5

View File

@@ -244,6 +244,46 @@ export namespace Worktree {
return $`bash -lc ${cmd}`.nothrow().cwd(directory) return $`bash -lc ${cmd}`.nothrow().cwd(directory)
} }
type StartKind = "project" | "worktree"
async function runStartScript(directory: string, cmd: string, kind: StartKind) {
const text = cmd.trim()
if (!text) return true
const ran = await runStartCommand(directory, text)
if (ran.exitCode === 0) return true
log.error("worktree start command failed", {
kind,
directory,
message: errorText(ran),
})
return false
}
async function runStartScripts(directory: string, input: { projectID: string; extra?: string }) {
const project = await Storage.read<Project.Info>(["project", input.projectID]).catch(() => undefined)
const startup = project?.commands?.start?.trim() ?? ""
const ok = await runStartScript(directory, startup, "project")
if (!ok) return false
const extra = input.extra ?? ""
await runStartScript(directory, extra, "worktree")
return true
}
function queueStartScripts(directory: string, input: { projectID: string; extra?: string }) {
setTimeout(() => {
const start = async () => {
await runStartScripts(directory, input)
}
void start().catch((error) => {
log.error("worktree start task failed", { directory, error })
})
}, 0)
}
export const create = fn(CreateInput.optional(), async (input) => { export const create = fn(CreateInput.optional(), async (input) => {
if (Instance.project.vcs !== "git") { if (Instance.project.vcs !== "git") {
throw new NotGitError({ message: "Worktrees are only supported for git projects" }) throw new NotGitError({ message: "Worktrees are only supported for git projects" })
@@ -318,27 +358,7 @@ export namespace Worktree {
}, },
}) })
const project = await Storage.read<Project.Info>(["project", projectID]).catch(() => undefined) await runStartScripts(info.directory, { projectID, extra })
const startup = project?.commands?.start?.trim() ?? ""
const run = async (cmd: string, kind: "project" | "worktree") => {
const ran = await runStartCommand(info.directory, cmd)
if (ran.exitCode === 0) return true
log.error("worktree start command failed", {
kind,
directory: info.directory,
message: errorText(ran),
})
return false
}
if (startup) {
const ok = await run(startup, "project")
if (!ok) return
}
if (extra) {
await run(extra, "worktree")
}
} }
void start().catch((error) => { void start().catch((error) => {
@@ -522,26 +542,7 @@ export namespace Worktree {
} }
const projectID = Instance.project.id const projectID = Instance.project.id
setTimeout(() => { queueStartScripts(worktreePath, { projectID })
const start = async () => {
const project = await Storage.read<Project.Info>(["project", projectID]).catch(() => undefined)
const startup = project?.commands?.start?.trim() ?? ""
if (!startup) return
const ran = await runStartCommand(worktreePath, startup)
if (ran.exitCode === 0) return
log.error("worktree start command failed", {
kind: "project",
directory: worktreePath,
message: errorText(ran),
})
}
void start().catch((error) => {
log.error("worktree start task failed", { directory: worktreePath, error })
})
}, 0)
return true return true
}) })