fix(worktree): accept the strategy's returned directory (#47997)

This commit is contained in:
James Long
2026-09-08 12:45:57 -04:00
committed by GitHub
parent 375bf4908f
commit 4432956490
3 changed files with 8 additions and 4 deletions
-2
View File
@@ -254,8 +254,6 @@ const layer = Layer.effect(
})
.pipe(Effect.mapError((error) => operationError(selected.id, "create", error)))
const result = { directory: yield* canonical(fs, created.directory) }
if (result.directory !== (yield* canonical(fs, worktreeDirectory)))
return yield* new InvalidDirectoryError({ directory: result.directory })
yield* changed(
yield* ops.create({
directory: result.directory,
+2
View File
@@ -1,5 +1,6 @@
export interface WorktreeCreateInput {
readonly sourceDirectory: string
/** Suggested destination after naming and collision handling. Strategies may return a different directory. */
readonly directory: string
/** Starting ref, not the name of a new branch. Reject unsupported refs rather than ignoring them. */
readonly branch?: string
@@ -11,6 +12,7 @@ export interface WorktreeRemoveInput {
}
export interface WorktreeResult {
/** Actual directory created by the strategy, used for inventory and startup commands. */
readonly directory: string
}
@@ -1025,8 +1025,12 @@ force confirmation without depending on Core or Git errors.
#### Reference
Implementations receive the final destination after naming and collision handling. Return that directory from `create`;
`list` must report only directories the strategy owns, plus any repository roots. Core owns inventory and startup commands.
Implementations receive a suggested destination after naming and collision handling. Return the actual directory from
`create`; it may differ when a backend requires its own layout. OpenCode resolves the returned path and uses it for
inventory, startup commands, and the API result. The returned directory must exist.
Strategies choosing another destination handle naming collisions there. OpenCode still creates the suggested parent
directory before calling the strategy. `list` must report only directories the strategy owns, plus any repository roots.
```ts
interface WorktreeDefinition {