nikivdev/code · error
Not a git repository
Error message
Not a git repository
What it means
ensure_git_repo() runs a git command (e.g. `git rev-parse`) with stdout/stderr suppressed and checks the exit status. If git exits non-zero, the tool concludes the current directory is not inside a git repository and throws this error. It is a precondition guard before any commit-related operation.
Source
Thrown at src/commit.rs:6556
issues,
summary,
future_tasks,
timed_out: false,
quality,
})
}
fn ensure_git_repo() -> Result<()> {
let _ = vcs::ensure_jj_repo()?;
let output = Command::new("git")
.args(["rev-parse", "--git-dir"])
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
.context("failed to run git")?;
if !output.success() {
bail!("Not a git repository");
}
Ok(())
}
fn git_root_or_cwd() -> std::path::PathBuf {
match git_capture(&["rev-parse", "--show-toplevel"]) {
Ok(root) => std::path::PathBuf::from(root.trim()),
Err(_) => std::env::current_dir().unwrap_or_default(),
}
}
fn warn_if_commit_invoked_from_subdir(repo_root: &Path) {
let Ok(cwd) = std::env::current_dir() else {
return;
};
let cwd_norm = cwd.canonicalize().unwrap_or(cwd.clone());
let root_norm = repo_root
.canonicalize()View on GitHub (pinned to a747e741ae)
Solutions
- cd into your project root (or a directory inside the git repo) and re-run
- Run `git rev-parse --show-toplevel` yourself to confirm the repo is detectable
- Run `git init` if the directory was never a repository
- Check GIT_DIR/GIT_WORK_TREE env vars are not pointing elsewhere
- Verify `git --version` works (git installed and on PATH)
Example fix
// before (shell) f commit -m "msg" # run in ~/projects/plain-dir // after (shell) cd ~/projects/my-repo && f commit -m "msg"
Defensive patterns
Strategy: validation
Validate before calling
use std::process::Command;
fn in_git_repo() -> bool {
Command::new("git")
.args(["rev-parse", "--is-inside-work-tree"])
.output()
.map(|o| o.status.success()
&& String::from_utf8_lossy(&o.stdout).trim() == "true")
.unwrap_or(false)
}
if !in_git_repo() { eprintln!("not a git repo; cd into your project first"); } Try / catch
if let Err(e) = tool.commit(msg) {
if e.to_string().contains("Not a git repository") {
eprintln!("cd into your git repo root and retry: {}", e);
} else { return Err(e.into()); }
} Prevention
- Always run the tool from inside a git working tree
- Verify with `git rev-parse --is-inside-work-tree` before automation
- Avoid unsetting GIT_DIR/GIT_WORK_TREE unexpectedly
- Ensure git is installed and on PATH
When it happens
Trigger: Running any `f commit` subcommand (or open_latest_queue_review, etc.) from a directory where `git` cannot resolve a repository — outside a repo, in a bare/corrupted repo, or when the `git` binary itself fails.
Common situations: Running the tool in a non-git project directory, running from a subdirectory whose repo was deleted, GIT_DIR misconfiguration, a corrupted .git directory, or git not being on PATH producing a command-level failure surfaced as this error.
Related errors
- failed to resolve git repo root
- git repo root was empty
- not inside a git repository
- Not a git repository
- not inside a git repository
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/72010a6fc2659aa2.
Report an issue: GitHub.