(sourceRoot: string, baseRef: string)
| 129 | } |
| 130 | |
| 131 | async function resolveBaseCommit(sourceRoot: string, baseRef: string): Promise<string> { |
| 132 | try { |
| 133 | return (await git(["rev-parse", "--verify", `${baseRef}^{commit}`], sourceRoot)).trim(); |
| 134 | } catch (error) { |
| 135 | if (baseRef === "HEAD") { |
| 136 | throw new GitWorktreeError( |
| 137 | "GIT_REPOSITORY_HAS_NO_COMMITS", |
| 138 | "Cannot open workspace in worktree mode because the repository has no commits yet. Create an initial commit first, or use mode=\"checkout\".", |
| 139 | ); |
| 140 | } |
| 141 | |
| 142 | throw new GitWorktreeError( |
| 143 | "GIT_INVALID_BASE_REF", |
| 144 | `Cannot open workspace in worktree mode because baseRef ${JSON.stringify(baseRef)} does not resolve to a commit.`, |
| 145 | ); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | function managedWorktreePath(input: { worktreeRoot: string; repoRoot: string }): string { |
| 150 | const repoName = sanitizePathSegment(basename(input.repoRoot)) || "repo"; |
no test coverage detected