( name: string, )
| 4928 | * Callers should check hasWorktreeCreateHook() before calling this. |
| 4929 | */ |
| 4930 | export async function executeWorktreeCreateHook( |
| 4931 | name: string, |
| 4932 | ): Promise<{ worktreePath: string }> { |
| 4933 | const hookInput = { |
| 4934 | ...createBaseHookInput(undefined), |
| 4935 | hook_event_name: 'WorktreeCreate' as const, |
| 4936 | name, |
| 4937 | } |
| 4938 | |
| 4939 | const results = await executeHooksOutsideREPL({ |
| 4940 | hookInput, |
| 4941 | timeoutMs: TOOL_HOOK_EXECUTION_TIMEOUT_MS, |
| 4942 | }) |
| 4943 | |
| 4944 | // Find the first successful result with non-empty output |
| 4945 | const successfulResult = results.find( |
| 4946 | r => r.succeeded && r.output.trim().length > 0, |
| 4947 | ) |
| 4948 | |
| 4949 | if (!successfulResult) { |
| 4950 | const failedOutputs = results |
| 4951 | .filter(r => !r.succeeded) |
| 4952 | .map(r => `${r.command}: ${r.output.trim() || 'no output'}`) |
| 4953 | throw new Error( |
| 4954 | `WorktreeCreate hook failed: ${failedOutputs.join('; ') || 'no successful output'}`, |
| 4955 | ) |
| 4956 | } |
| 4957 | |
| 4958 | const worktreePath = successfulResult.output.trim() |
| 4959 | return { worktreePath } |
| 4960 | } |
| 4961 | |
| 4962 | /** |
| 4963 | * Execute WorktreeRemove hooks if configured. |
no test coverage detected