( name: string, )
| 5094 | * Callers should check hasWorktreeCreateHook() before calling this. |
| 5095 | */ |
| 5096 | export async function executeWorktreeCreateHook( |
| 5097 | name: string, |
| 5098 | ): Promise<{ worktreePath: string }> { |
| 5099 | const hookInput = { |
| 5100 | ...createBaseHookInput(undefined), |
| 5101 | hook_event_name: 'WorktreeCreate' as const, |
| 5102 | name, |
| 5103 | } |
| 5104 | |
| 5105 | const results = await executeHooksOutsideREPL({ |
| 5106 | hookInput, |
| 5107 | timeoutMs: TOOL_HOOK_EXECUTION_TIMEOUT_MS, |
| 5108 | }) |
| 5109 | |
| 5110 | // Find the first successful result with non-empty output |
| 5111 | const successfulResult = results.find( |
| 5112 | r => r.succeeded && r.output.trim().length > 0, |
| 5113 | ) |
| 5114 | |
| 5115 | if (!successfulResult) { |
| 5116 | const failedOutputs = results |
| 5117 | .filter(r => !r.succeeded) |
| 5118 | .map(r => `${r.command}: ${r.output.trim() || 'no output'}`) |
| 5119 | throw new Error( |
| 5120 | `WorktreeCreate hook failed: ${failedOutputs.join('; ') || 'no successful output'}`, |
| 5121 | ) |
| 5122 | } |
| 5123 | |
| 5124 | const worktreePath = successfulResult.output.trim() |
| 5125 | return { worktreePath } |
| 5126 | } |
| 5127 | |
| 5128 | /** |
| 5129 | * Execute WorktreeRemove hooks if configured. |
no test coverage detected