can1357/oh-my-pi · error · ToolError

Current git repository is unavailable.

Error message

Current git repository is unavailable.

What it means

requireGitRepoRoot resolves the enclosing git repository root via vcs.git(cwd)?.info().repoRoot and throws this ToolError when null — i.e. the working directory is not inside a git repository (or the vcs wrapper failed). PR checkout needs a repo root to anchor worktree paths.

Source

Thrown at packages/coding-agent/src/tools/gh-pr-checkout.ts:68

		.toLowerCase()
		.replace(/[^a-z0-9]+/g, "-")
		.replace(/^-+/g, "")
		.replace(/-+$/g, "");
	return sanitized.length > 0 ? `fork-${sanitized}` : "fork";
}

/** Maximum disambiguation suffixes we try before giving up on a worktree path. */
export const WORKTREE_PATH_MAX_SUFFIX = 100;

export function toLocalBranchRef(value: string): string {
	return `refs/heads/${value}`;
}

export async function requireGitRepoRoot(cwd: string, signal?: AbortSignal): Promise<string> {
	signal?.throwIfAborted();
	const repoRoot = vcs.git(cwd)?.info().repoRoot;
	if (!repoRoot) {
		throw new ToolError("Current git repository is unavailable.");
	}

	return repoRoot;
}

export async function requirePrimaryGitRepoRoot(cwd: string, signal?: AbortSignal): Promise<string> {
	signal?.throwIfAborted();
	const primaryRepoRoot = vcs.git(cwd)?.primaryRoot();
	if (!primaryRepoRoot) {
		throw new ToolError("Current git repository is unavailable.");
	}

	return primaryRepoRoot;
}

/**
 * Resolve a worktree path that is free of conflicts.
 *

View on GitHub (pinned to 9690622007)

Solutions

  1. Run the PR checkout from inside a git repository.
  2. Run `git init` if the project should be a repo, or `git clone` it first.
  3. Confirm `git rev-parse --show-toplevel` succeeds in the target cwd.

Example fix

// before
await checkoutPullRequest({ cwd: "/tmp/not-a-repo", pr: 12 });
// after
cwd = "/home/user/project"; // a git repo
await checkoutPullRequest({ cwd, pr: 12 });
Defensive patterns

Strategy: validation

Validate before calling

import { $ } from "bun";
const root = await $`git rev-parse --show-toplevel`.cwd(cwd).quiet().nothrow();
if (root.exitCode !== 0) {
  throw new Error(`${cwd} is not a git repository`);
}

Try / catch

try {
  const repoRoot = await repoRoot(cwd);
} catch (err) {
  if (err instanceof ToolError && err.message.includes("git repository is unavailable")) {
    // clone/init the repo or relocate cwd before retrying
  } else throw err;
}

Prevention

When it happens

Trigger: Calling repoRoot() (backed by requireGitRepoRoot) from a directory outside any git work tree, or where git info cannot report a repoRoot (bare path, git unavailable, aborted signal).

Common situations: Agent launched in a temp/home directory; project not yet git-initialized; git binary missing or broken so info() fails silently to null.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/b7d97a362f6cd184. Report an issue: GitHub.