FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(core): be smarter about generating a worktree name (#26368) · argszero/opencode@9b7b6cb · GitHub

Commit 9b7b6cb

Browse files
authored
feat(core): be smarter about generating a worktree name (anomalyco#26368)
1 parent cc68afb commit 9b7b6cb

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

‎packages/opencode/src/worktree/index.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,15 @@ export const layer: Layer.Layer<
361361
}
362362

363363
const primary = yield* canonical(ctx.worktree)
364+
const primaryName = pathSvc.basename(primary).toLowerCase()
364365
return yield* Effect.forEach(parseWorktreeList(result.text), (entry) =>
365366
Effect.gen(function* () {
366367
if (!entry.path) return undefined
367368
const directory = yield* canonical(entry.path)
368369
if (directory === primary) return undefined
370+
const name = pathSvc.basename(directory).toLowerCase()
369371
return {
370-
name: pathSvc.basename(directory),
372+
name: name === primaryName ? pathSvc.basename(pathSvc.dirname(directory)) : name,
371373
directory,
372374
...(entry.branch ? { branch: entry.branch.replace(/^refs\/heads\//, "") } : {}),
373375
}

‎packages/opencode/test/project/worktree.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,35 @@ describe("Worktree", () => {
200200
)
201201
})
202202

203+
describe("list", () => {
204+
it.live("uses parent folder name when worktree basename matches the primary worktree", () =>
205+
provideTmpdirInstance(
206+
(dir) =>
207+
Effect.gen(function* () {
208+
const svc = yield* Worktree.Service
209+
const parent = path.join(path.dirname(dir), `${path.basename(dir)}-parent`)
210+
const target = path.join(parent, path.basename(dir))
211+
const branch = `same-basename-list-${Date.now()}`
212+
213+
yield* Effect.promise(() => fs.mkdir(parent, { recursive: true }))
214+
yield* Effect.promise(() => $`git worktree add -b ${branch} ${target}`.cwd(dir).quiet())
215+
216+
const list = yield* svc.list()
217+
const directory = yield* Effect.promise(() => fs.realpath(target).catch(() => target))
218+
219+
expect(list).toContainEqual({
220+
name: path.basename(parent),
221+
branch,
222+
directory: directory.toLowerCase(),
223+
})
224+
225+
yield* svc.remove({ directory: target })
226+
}),
227+
{ git: true },
228+
),
229+
)
230+
})
231+
203232
describe("remove edge cases", () => {
204233
it.live("remove non-existent directory succeeds silently", () =>
205234
provideTmpdirInstance(

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL