()
| 109 | * (which must never reset a shared tree; use {@link ensureWorktree}). `name` is the |
| 110 | * kild worktree name (the branch is derived as `kild/<name>`); `base` is the |
| 111 | * start-point ref (default: current HEAD). */ |
| 112 | export async function createWorktree(repo: string, name: string, base?: string): Promise<Worktree> { |
| 113 | assertSafeBranch(name); |
| 114 | const wtPath = worktreePath(name); |
| 115 | const ref = worktreeRef(name); |
| 116 | // Best-effort pre-clean of a same-named worktree before the force re-create. |
| 117 | // Force is intentional here ("new worktree" is destructive-by-request). |
| 118 | await execFile('git', ['-C', repo, 'worktree', 'remove', '--force', wtPath]).catch(() => {}); |
| 119 | const add = ['-C', repo, 'worktree', 'add', '-B', ref, wtPath, ...(base ? [base] : [])]; |
| 120 | await execFile('git', add); |
| 121 | return { branch: ref, path: wtPath, name }; |
| 122 | } |
| 123 |
no test coverage detected