(path: string, allowedRoots: string[])
| 91 | } |
| 92 | |
| 93 | async function resolveGitRoot(path: string, allowedRoots: string[]): Promise<string> { |
| 94 | try { |
| 95 | const output = await git(["rev-parse", "--show-toplevel"], path); |
| 96 | return await assertGitRootAllowed(output.trim(), allowedRoots); |
| 97 | } catch (error) { |
| 98 | if (isGitUnavailable(error)) { |
| 99 | throw new GitWorktreeError( |
| 100 | "GIT_NOT_AVAILABLE", |
| 101 | "Cannot open workspace in worktree mode because Git is not available on this machine.", |
| 102 | ); |
| 103 | } |
| 104 | |
| 105 | throw new GitWorktreeError( |
| 106 | "GIT_REPOSITORY_NOT_FOUND", |
| 107 | `Cannot open workspace in worktree mode because this path is not inside a Git repository: ${path}. Use mode=\"checkout\" to work directly in this directory, or initialize Git and create an initial commit first.`, |
| 108 | ); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | async function assertGitRootAllowed(gitRoot: string, allowedRoots: string[]): Promise<string> { |
| 113 | try { |
no test coverage detected