Skip to content

Commit bd132f2

Browse files
authored
refactor(core): skip redundant worktree lookup (#39692)
1 parent dcb0df4 commit bd132f2

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

packages/core/src/project.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,13 @@ const layer = Layer.effect(
246246
if (repo) {
247247
const previous = yield* cached(repo.commonDirectory)
248248
const id = (yield* remote(repo)) ?? previous ?? (yield* root(repo))
249-
const canonical = yield* git.worktree
250-
.list(repo)
251-
.pipe(
252-
Effect.map((items) => items.find((item) => item.kind === "main")?.directory ?? repo.worktree),
253-
Effect.catch(() => Effect.succeed(repo.worktree)),
254-
)
249+
const canonical =
250+
repo.gitDirectory === repo.commonDirectory
251+
? repo.worktree
252+
: yield* git.worktree.list(repo).pipe(
253+
Effect.map((items) => items.find((item) => item.kind === "main")?.directory ?? repo.worktree),
254+
Effect.catch(() => Effect.succeed(repo.worktree)),
255+
)
255256
return yield* persist({
256257
previous,
257258
id: id ?? ID.global,

packages/core/test/project.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ describe("Project.resolve", () => {
143143

144144
expect(result.id).toBe(Project.ID.make(yield* Effect.promise(() => rootCommit(tmp.path))))
145145
expect(result.directory).toBe(yield* real(tmp.path))
146+
expect(result.canonical).toBe(result.directory)
146147
expect(result.previous).toBeUndefined()
147148
expect(result.vcs?.type).toBe("git")
148149
}),

0 commit comments

Comments
 (0)