nikivdev/code · error
git repo root was empty
Error message
git repo root was empty
What it means
Companion check to the repo-root resolution: after a successful `git rev-parse --show-toplevel`, the trimmed stdout is inspected, and if it is empty the library bails. This catches pathological cases where git reports success but prints no path, so a valid PathBuf root cannot be constructed.
Source
Thrown at src/commit.rs:2643
}
fn resolve_commit_with_check_root() -> Result<std::path::PathBuf> {
if !commit_with_check_use_repo_root() {
return std::env::current_dir().context("failed to get current directory");
}
let output = Command::new("git")
.args(["rev-parse", "--show-toplevel"])
.output()
.context("failed to run git rev-parse --show-toplevel")?;
if !output.status.success() {
bail!("failed to resolve git repo root");
}
let root = String::from_utf8_lossy(&output.stdout).trim().to_string();
if root.is_empty() {
bail!("git repo root was empty");
}
Ok(std::path::PathBuf::from(root))
}
const DEFAULT_COMMIT_WITH_CHECK_TIMEOUT_SECS: u64 = 300;
const MAX_COMMIT_WITH_CHECK_TIMEOUT_SECS: u64 = 3600;
const DEFAULT_COMMIT_WITH_CHECK_REVIEW_RETRIES: u32 = 2;
const MAX_COMMIT_WITH_CHECK_REVIEW_RETRIES: u32 = 5;
const DEFAULT_COMMIT_WITH_CHECK_RETRY_BACKOFF_SECS: u64 = 3;
fn commit_with_check_timeout_from_env() -> Option<u64> {
for key in [
"FLOW_COMMIT_WITH_CHECK_TIMEOUT_SECS",
"FLOW_COMMIT_TIMEOUT_SECS",
] {
if let Ok(value) = env::var(key) {
if let Ok(parsed) = value.trim().parse::<u64>() {View on GitHub (pinned to a747e741ae)
Solutions
- Inspect your environment for git wrapper scripts or aliases affecting `rev-parse --show-toplevel`.
- Run the raw command and confirm it prints an absolute path.
- Check GIT_DIR/GIT_WORK_TREE values and remove invalid overrides.
- Retry from a normal shell in the repository root.
Defensive patterns
Strategy: validation
Validate before calling
let out = Command::new("git").args(["rev-parse", "--show-toplevel"]).output()?;
let root = String::from_utf8_lossy(&out.stdout).trim().to_string();
if !out.status.success() || root.is_empty() || !std::path::Path::new(&root).is_dir() {
return Err("git repo root unresolvable or invalid".into());
} Prevention
- Avoid git wrapper scripts that swallow stdout of rev-parse subcommands.
- In tests that stub git, make stubs return a realistic absolute path, not empty output.
- Validate GIT_DIR/GIT_WORK_TREE configurations on developer machines and CI images.
When it happens
Trigger: `git rev-parse --show-toplevel` exits 0 but emits empty stdout — e.g. unusual GIT_DIR/GIT_WORK_TREE configurations, mocked or wrapped git binaries, or output encoding issues.
Common situations: Custom git wrappers/aliases swallowing stdout; exotic sandboxed environments; intercepted Command output in tests with a stubbed git returning empty success.
Related errors
- failed to resolve git repo root
- not inside a git repository
- git status failed with {}
- Not a git repository
- Not a git repository
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/b1b8525fcaaab344.
Report an issue: GitHub.