{"record":{"id":"b1b8525fcaaab344","repo":"nikivdev/code","slug":"git-repo-root-was-empty","errorCode":null,"errorMessage":"git repo root was empty","messagePattern":"git repo root was empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/commit.rs","lineNumber":2643,"sourceCode":"}\n\nfn resolve_commit_with_check_root() -> Result<std::path::PathBuf> {\n    if !commit_with_check_use_repo_root() {\n        return std::env::current_dir().context(\"failed to get current directory\");\n    }\n\n    let output = Command::new(\"git\")\n        .args([\"rev-parse\", \"--show-toplevel\"])\n        .output()\n        .context(\"failed to run git rev-parse --show-toplevel\")?;\n\n    if !output.status.success() {\n        bail!(\"failed to resolve git repo root\");\n    }\n\n    let root = String::from_utf8_lossy(&output.stdout).trim().to_string();\n    if root.is_empty() {\n        bail!(\"git repo root was empty\");\n    }\n\n    Ok(std::path::PathBuf::from(root))\n}\n\nconst DEFAULT_COMMIT_WITH_CHECK_TIMEOUT_SECS: u64 = 300;\nconst MAX_COMMIT_WITH_CHECK_TIMEOUT_SECS: u64 = 3600;\nconst DEFAULT_COMMIT_WITH_CHECK_REVIEW_RETRIES: u32 = 2;\nconst MAX_COMMIT_WITH_CHECK_REVIEW_RETRIES: u32 = 5;\nconst DEFAULT_COMMIT_WITH_CHECK_RETRY_BACKOFF_SECS: u64 = 3;\n\nfn commit_with_check_timeout_from_env() -> Option<u64> {\n    for key in [\n        \"FLOW_COMMIT_WITH_CHECK_TIMEOUT_SECS\",\n        \"FLOW_COMMIT_TIMEOUT_SECS\",\n    ] {\n        if let Ok(value) = env::var(key) {\n            if let Ok(parsed) = value.trim().parse::<u64>() {","sourceCodeStart":2625,"sourceCodeEnd":2661,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/commit.rs#L2625-L2661","documentation":"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.","triggerScenarios":"`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.","commonSituations":"Custom git wrappers/aliases swallowing stdout; exotic sandboxed environments; intercepted Command output in tests with a stubbed git returning empty success.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let out = Command::new(\"git\").args([\"rev-parse\", \"--show-toplevel\"]).output()?;\nlet root = String::from_utf8_lossy(&out.stdout).trim().to_string();\nif !out.status.success() || root.is_empty() || !std::path::Path::new(&root).is_dir() {\n    return Err(\"git repo root unresolvable or invalid\".into());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["git","repository","environment"],"backgroundTag":"not-a-git-repository","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}