Compare commits

...

1 Commits

Author SHA1 Message Date
Aiden Cline a3e17c39e3 fix: acp hanging issue 2026-02-04 13:50:07 -06:00
+35 -24
View File
@@ -14,6 +14,27 @@ import { iife } from "@/util/iife"
import { GlobalBus } from "@/bus/global" import { GlobalBus } from "@/bus/global"
import { existsSync } from "fs" import { existsSync } from "fs"
async function runGit(args: string[], cwd: string) {
if (Flag.OPENCODE_CLIENT === "acp") {
const proc = Bun.spawn({
cmd: ["git", ...args],
cwd,
stdout: "pipe",
stderr: "pipe",
})
const [code, stdout] = await Promise.all([proc.exited, new Response(proc.stdout).text()])
if (code !== 0) return undefined
return stdout
}
return $`git ${args}`
.quiet()
.nothrow()
.cwd(cwd)
.text()
.catch(() => undefined)
}
export namespace Project { export namespace Project {
const log = Log.create({ service: "project" }) const log = Log.create({ service: "project" })
export const Info = z export const Info = z
@@ -79,18 +100,15 @@ export namespace Project {
// generate id from root commit // generate id from root commit
if (!id) { if (!id) {
const roots = await $`git rev-list --max-parents=0 --all` const roots = await runGit(["rev-list", "--max-parents=0", "--all"], sandbox)
.quiet() .then((output) => {
.nothrow() if (!output) return undefined
.cwd(sandbox) return output
.text()
.then((x) =>
x
.split("\n") .split("\n")
.filter(Boolean) .filter((line) => line.length > 0)
.map((x) => x.trim()) .map((line) => line.trim())
.toSorted(), .toSorted()
) })
.catch(() => undefined) .catch(() => undefined)
if (!roots) { if (!roots) {
@@ -119,12 +137,8 @@ export namespace Project {
} }
} }
const top = await $`git rev-parse --show-toplevel` const top = await runGit(["rev-parse", "--show-toplevel"], sandbox)
.quiet() .then((output) => (output ? path.resolve(sandbox, output.trim()) : undefined))
.nothrow()
.cwd(sandbox)
.text()
.then((x) => path.resolve(sandbox, x.trim()))
.catch(() => undefined) .catch(() => undefined)
if (!top) { if (!top) {
@@ -138,13 +152,10 @@ export namespace Project {
sandbox = top sandbox = top
const worktree = await $`git rev-parse --git-common-dir` const worktree = await runGit(["rev-parse", "--git-common-dir"], sandbox)
.quiet() .then((output) => {
.nothrow() if (!output) return undefined
.cwd(sandbox) const dirname = path.dirname(output.trim())
.text()
.then((x) => {
const dirname = path.dirname(x.trim())
if (dirname === ".") return sandbox if (dirname === ".") return sandbox
return dirname return dirname
}) })