can1357/oh-my-pi · error · Error

not a repository: {path}

Error message

not a repository: {path}

What it means

The unified pi-vcs Error::NotARepository variant. The library could not find a git repository root or jj workspace at or above the directory a VCS operation started from. It is thrown during repository discovery (walking up parent directories looking for .git / .jj) before any VCS API calls can proceed.

Source

Thrown at crates/pi-vcs/src/error.rs:16

//! Error type shared by the git and jj backends.
//!
//! Failure modes that TypeScript callers previously detected by regexing
//! subprocess stderr (e.g. an empty cherry-pick) are first-class variants here
//! so the TS layer can match on a structured `kind` instead of message text.

use std::path::PathBuf;

/// Crate-wide result alias.
pub type Result<T, E = Error> = std::result::Result<T, E>;

/// Unified error for all VCS operations.
#[derive(Debug, thiserror::Error)]
pub enum Error {
	/// The directory is not inside a git repository / jj workspace.
	#[error("not a repository: {path}")]
	NotARepository {
		/// Directory the lookup started from.
		path: PathBuf,
	},

	/// A named ref (branch, tag, `refs/...`) does not exist.
	#[error("reference not found: {name}")]
	RefNotFound {
		/// The ref name as given by the caller.
		name: String,
	},

	/// A revision/object lookup failed (`rev-parse` style spec, blob path,
	/// tree).
	#[error("object not found: {spec}")]
	ObjectNotFound {
		/// The revision or object spec as given by the caller.
		spec: String,

View on GitHub (pinned to 9690622007)

Solutions

  1. Run `git init` in the target directory (or `jj git init` for a jj workspace).
  2. cd into a directory that is actually inside the repository, or pass the repo root path explicitly.
  3. Verify the .git directory exists and was not deleted/moved (`ls -a .git`).
  4. In code, check for this variant first and surface a friendly 'run git init' message instead of a raw error.

Example fix

// before
let repo = Vcs::open("/tmp/scratch")?; // panics-ish: not a repository
// after
if !git_probe::is_repo("/tmp/scratch") {
    std::process::Command::new("git").args(["init"]).current_dir("/tmp/scratch").status()?;
}
let repo = Vcs::open("/tmp/scratch")?;
Defensive patterns

Strategy: validation

Validate before calling

fn is_vcs_dir(dir: &Path) -> bool {
    let mut cur = Some(dir);
    while let Some(d) = cur {
        if d.join(".git").exists() || d.join(".jj").exists() { return true; }
        cur = d.parent();
    }
    false
}
if !is_vcs_dir(&workdir) { eprintln!("{} is not inside a git/jj repository", workdir.display()); return Ok(()); }

Type guard

fn is_not_a_repository(err: &pi_vcs::Error) -> bool {
    matches!(err, pi_vcs::Error::NotARepository { .. })
}

Try / catch

match repo_result {
    Err(pi_vcs::Error::NotARepository { path }) => {
        eprintln!("{} is not a git/jj repository — run `git init` first", path.display());
    }
    other => other?,
}

Prevention

When it happens

Trigger: Opening a Vcs/repo handle with a path that is outside any git repository or jj workspace: e.g. Vcs::open("/tmp"), or a git/jj command rooted at a scratch directory, home dir, or a fresh empty folder with no `git init`.

Common situations: Running the tool before `git init`, running in a subdirectory that was never inside a repo, a deleted or renamed .git directory, CI checkouts that extracted a tarball without .git, or pointing config at the wrong working directory.

Related errors


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