(cwd: string)
| 31 | } |
| 32 | |
| 33 | export async function getGitEligibility(cwd: string): Promise<GitEligibility> { |
| 34 | try { |
| 35 | await git(cwd, ["rev-parse", "--is-inside-work-tree"]); |
| 36 | } catch { |
| 37 | return { |
| 38 | ok: false, |
| 39 | reason: "not_git", |
| 40 | message: "workspace is not inside a git repository", |
| 41 | }; |
| 42 | } |
| 43 | |
| 44 | const gitRoot = (await git(cwd, ["rev-parse", "--show-toplevel"])).stdout.trim(); |
| 45 | try { |
| 46 | await git(gitRoot, ["rev-parse", "--verify", "--quiet", "HEAD^{commit}"]); |
| 47 | } catch { |
| 48 | return { |
| 49 | ok: false, |
| 50 | gitRoot, |
| 51 | reason: "no_head", |
| 52 | message: "repository has no HEAD commit", |
| 53 | }; |
| 54 | } |
| 55 | |
| 56 | return { ok: true, gitRoot }; |
| 57 | } |
| 58 | |
| 59 | export function safeWorkspaceRefSegment(workspaceId: string): string { |
| 60 | const safe = workspaceId.replace(/[^A-Za-z0-9._-]/g, "-"); |
no test coverage detected