mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-18 02:22:32 +00:00
feat(core): be smarter about generating a worktree name (#26368)
This commit is contained in:
@@ -361,13 +361,15 @@ export const layer: Layer.Layer<
|
||||
}
|
||||
|
||||
const primary = yield* canonical(ctx.worktree)
|
||||
const primaryName = pathSvc.basename(primary).toLowerCase()
|
||||
return yield* Effect.forEach(parseWorktreeList(result.text), (entry) =>
|
||||
Effect.gen(function* () {
|
||||
if (!entry.path) return undefined
|
||||
const directory = yield* canonical(entry.path)
|
||||
if (directory === primary) return undefined
|
||||
const name = pathSvc.basename(directory).toLowerCase()
|
||||
return {
|
||||
name: pathSvc.basename(directory),
|
||||
name: name === primaryName ? pathSvc.basename(pathSvc.dirname(directory)) : name,
|
||||
directory,
|
||||
...(entry.branch ? { branch: entry.branch.replace(/^refs\/heads\//, "") } : {}),
|
||||
}
|
||||
|
||||
@@ -200,6 +200,35 @@ describe("Worktree", () => {
|
||||
)
|
||||
})
|
||||
|
||||
describe("list", () => {
|
||||
it.live("uses parent folder name when worktree basename matches the primary worktree", () =>
|
||||
provideTmpdirInstance(
|
||||
(dir) =>
|
||||
Effect.gen(function* () {
|
||||
const svc = yield* Worktree.Service
|
||||
const parent = path.join(path.dirname(dir), `${path.basename(dir)}-parent`)
|
||||
const target = path.join(parent, path.basename(dir))
|
||||
const branch = `same-basename-list-${Date.now()}`
|
||||
|
||||
yield* Effect.promise(() => fs.mkdir(parent, { recursive: true }))
|
||||
yield* Effect.promise(() => $`git worktree add -b ${branch} ${target}`.cwd(dir).quiet())
|
||||
|
||||
const list = yield* svc.list()
|
||||
const directory = yield* Effect.promise(() => fs.realpath(target).catch(() => target))
|
||||
|
||||
expect(list).toContainEqual({
|
||||
name: path.basename(parent),
|
||||
branch,
|
||||
directory: directory.toLowerCase(),
|
||||
})
|
||||
|
||||
yield* svc.remove({ directory: target })
|
||||
}),
|
||||
{ git: true },
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
describe("remove edge cases", () => {
|
||||
it.live("remove non-existent directory succeeds silently", () =>
|
||||
provideTmpdirInstance(
|
||||
|
||||
Reference in New Issue
Block a user