Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/opencode/src/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ export const layer: Layer.Layer<
const common = resolveGitPath(sandbox, commonDir.text.trim())
const bareCheck = yield* git(["config", "--bool", "core.bare"], { cwd: sandbox })
const isBareRepo = bareCheck.code === 0 && bareCheck.text.trim() === "true"
const worktree = common === sandbox ? sandbox : isBareRepo ? common : pathSvc.dirname(common)

if (id == null) {
id = yield* readCachedProjectId(common)
Expand Down Expand Up @@ -272,6 +271,7 @@ export const layer: Layer.Layer<
}
}
sandbox = resolveGitPath(sandbox, topLevel.text.trim())
const worktree = common === sandbox ? sandbox : isBareRepo ? sandbox : pathSvc.dirname(common)

return { id, sandbox, worktree, vcs: "git" as const }
})
Expand Down
9 changes: 6 additions & 3 deletions packages/opencode/test/project/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ describe("Project.addSandbox and Project.removeSandbox", () => {
})

describe("Project.fromDirectory with bare repos", () => {
test("worktree from bare repo should cache in bare repo, not parent", async () => {
test("worktree from bare repo should use checked out worktree and cache in bare repo", async () => {
await using tmp = await tmpdir({ git: true })

const parentDir = path.dirname(tmp.path)
Expand All @@ -533,7 +533,8 @@ describe("Project.fromDirectory with bare repos", () => {
const { project } = await run((svc) => svc.fromDirectory(worktreePath))

expect(project.id).not.toBe(ProjectID.global)
expect(project.worktree).toBe(barePath)
expect(project.worktree).toBe(worktreePath)
expect(project.sandboxes).not.toContain(worktreePath)

const correctCache = path.join(barePath, "opencode")
const wrongCache = path.join(parentDir, ".git", "opencode")
Expand Down Expand Up @@ -565,6 +566,8 @@ describe("Project.fromDirectory with bare repos", () => {
const { project: projB } = await run((svc) => svc.fromDirectory(worktreeB))

expect(projA.id).not.toBe(projB.id)
expect(projA.worktree).toBe(worktreeA)
expect(projB.worktree).toBe(worktreeB)

const cacheA = path.join(bareA, "opencode")
const cacheB = path.join(bareB, "opencode")
Expand Down Expand Up @@ -592,7 +595,7 @@ describe("Project.fromDirectory with bare repos", () => {
const { project } = await run((svc) => svc.fromDirectory(worktreePath))

expect(project.id).not.toBe(ProjectID.global)
expect(project.worktree).toBe(barePath)
expect(project.worktree).toBe(worktreePath)

const correctCache = path.join(barePath, "opencode")
expect(await Bun.file(correctCache).exists()).toBe(true)
Expand Down
Loading