can1357/oh-my-pi · error · Error

Not a git repository: ${cwd}

Error message

Not a git repository: ${cwd}

What it means

showGitOverlay opens the git TUI overlay and first resolves the repository root via vcs.git(cwd). If git is unavailable or the directory is not inside a git work tree (repoRoot is null), it throws with the offending cwd. The overlay requires a real git repository to enumerate status/branches.

Source

Thrown at packages/coding-agent/src/cli/git-tui/index.ts:806

	}
}

/** Options for {@link runGitTui}. */
export interface GitTuiOptions {
	cwd?: string;
	/** Pin the view to one commit (any rev-parse-able revision). */
	revision?: string;
}

/**
 * Mount the git TUI as a fullscreen overlay on an existing TUI (the `/git`
 * slash command). Resolves when the user closes it; the caller restores focus.
 */
export async function showGitOverlay(ui: TUI, options: GitTuiOptions = {}): Promise<void> {
	const cwd = options.cwd ?? process.cwd();
	const repo = vcs.git(cwd);
	const root = repo?.info().repoRoot ?? null;
	if (!root) throw new Error(`Not a git repository: ${cwd}`);
	let pinnedSha: string | undefined;
	if (options.revision) {
		pinnedSha = (await repo?.resolveRef(options.revision)) ?? undefined;
		if (!pinnedSha) throw new Error(`Cannot resolve revision: ${options.revision}`);
	}
	const component = new GitTuiComponent(ui, root, pinnedSha);
	const overlay = ui.showOverlay(component, {
		anchor: "top-left",
		width: "100%",
		maxHeight: "100%",
		margin: 0,
		fullscreen: true,
		mouseTracking: true,
	});
	ui.setFocus(component);
	ui.requestRender();
	try {
		await component.run();

View on GitHub (pinned to 9690622007)

Solutions

  1. cd into (or pass options.cwd of) a directory inside a git repository.
  2. Initialize a repository with `git init` if one is intended.
  3. Check GIT_DIR/GIT_WORK_TREE env overrides that may break root resolution.

Example fix

// before
await showGitOverlay(ui, { cwd: "/tmp" });
// after
const cwd = "/home/me/project"; // inside a git repo
await showGitOverlay(ui, { cwd });
Defensive patterns

Strategy: validation

Validate before calling

import { $ } from "bun";
const inside = await $`git -C ${cwd} rev-parse --show-toplevel`.quiet().nothrow();
if (inside.exitCode !== 0) throw new Error(`Not a git repo: ${cwd}`);

Try / catch

try {
  await showGitOverlay(ui, { cwd });
} catch (e) {
  if (e instanceof Error && e.message.startsWith("Not a git repository")) {
    console.error("Open the git TUI from inside a git repository.");
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling showGitOverlay (or the git TUI command) with options.cwd set to (or the process started in) a directory outside any git work tree, or in a bare/worktree configuration where repoRoot cannot be resolved.

Common situations: Running the git overlay from $HOME or /tmp, inside a plain directory that was never `git init`ed, or with GIT_DIR pointing somewhere invalid.

Related errors


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