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 primary = yield* canonical(ctx.worktree)
|
||||||
|
const primaryName = pathSvc.basename(primary).toLowerCase()
|
||||||
return yield* Effect.forEach(parseWorktreeList(result.text), (entry) =>
|
return yield* Effect.forEach(parseWorktreeList(result.text), (entry) =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
if (!entry.path) return undefined
|
if (!entry.path) return undefined
|
||||||
const directory = yield* canonical(entry.path)
|
const directory = yield* canonical(entry.path)
|
||||||
if (directory === primary) return undefined
|
if (directory === primary) return undefined
|
||||||
|
const name = pathSvc.basename(directory).toLowerCase()
|
||||||
return {
|
return {
|
||||||
name: pathSvc.basename(directory),
|
name: name === primaryName ? pathSvc.basename(pathSvc.dirname(directory)) : name,
|
||||||
directory,
|
directory,
|
||||||
...(entry.branch ? { branch: entry.branch.replace(/^refs\/heads\//, "") } : {}),
|
...(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", () => {
|
describe("remove edge cases", () => {
|
||||||
it.live("remove non-existent directory succeeds silently", () =>
|
it.live("remove non-existent directory succeeds silently", () =>
|
||||||
provideTmpdirInstance(
|
provideTmpdirInstance(
|
||||||
|
|||||||
Reference in New Issue
Block a user