{"record":{"id":"844de9ad51c7fc84","repo":"nikivdev/code","slug":"is-not-inside-a-git-repository","errorCode":null,"errorMessage":"{} is not inside a git repository","messagePattern":"(.+?) is not inside a git repository","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/pr_preview.rs","lineNumber":1344,"sourceCode":"\n    let head_sha = git_rev_parse(repo_root, head_ref)?;\n    Ok(ResolvedBase {\n        requested: requested.to_string(),\n        resolved: head_ref.to_string(),\n        merge_base: head_sha,\n        compare_label: compare_head_label.to_string(),\n        fallback_used: true,\n    })\n}\n\nfn resolve_git_repo_root(start: &Path) -> Result<PathBuf> {\n    let output = Command::new(\"git\")\n        .current_dir(start)\n        .args([\"rev-parse\", \"--show-toplevel\"])\n        .output()\n        .with_context(|| format!(\"failed to run git rev-parse in {}\", start.display()))?;\n    if !output.status.success() {\n        bail!(\"{} is not inside a git repository\", start.display());\n    }\n    Ok(PathBuf::from(\n        String::from_utf8_lossy(&output.stdout).trim(),\n    ))\n}\n\nfn resolve_preview_context(start: &Path) -> Result<PreviewContext> {\n    if let Ok(repo_root) = resolve_git_repo_root(start) {\n        let head_label = detect_head_label(&repo_root)?;\n        return Ok(PreviewContext {\n            repo_root: repo_root.clone(),\n            review_root: repo_root,\n            head_ref: \"HEAD\".to_string(),\n            head_label,\n            compare_head_label: \"HEAD\".to_string(),\n            work_tree_root: None,\n        });\n    }","sourceCodeStart":1326,"sourceCodeEnd":1362,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/pr_preview.rs#L1326-L1362","documentation":"When resolving the repository root, the tool runs `git rev-parse --show-toplevel` from the starting directory. If git exits non-zero, the directory is not inside a git work tree, and this error names the offending path.","triggerScenarios":"Running `f pr preview` (with --path or from the cwd) pointing at a directory that is not part of any git repository, or a corrupt .git dir causing rev-parse to fail.","commonSituations":"Wrong --path pointing at a scratch/exported directory; running from a bare checkout's parent; .git directory deleted or corrupted; running outside any repo.","solutions":["Run the command from inside a git repository or pass --path pointing at one","Verify the target has a valid .git directory (`git -C <dir> rev-parse --show-toplevel`)","Re-clone the repository if .git is corrupted"],"exampleFix":"// before\nf pr preview --path /tmp/scratch   # not a git repo\n// after\ncd ~/repos/api && f pr preview    # inside a git repo","handlingStrategy":"validation","validationCode":"let out = std::process::Command::new(\"git\")\n    .current_dir(path)\n    .args([\"rev-parse\", \"--show-toplevel\"])\n    .output()?;\nif !out.status.success() {\n    anyhow::bail!(\"{} is not a git repo; fix --path\", path.display());\n}","typeGuard":"fn is_git_repo(dir: &Path) -> bool {\n    std::process::Command::new(\"git\")\n        .current_dir(dir)\n        .args([\"rev-parse\", \"--show-toplevel\"])\n        .output()\n        .map(|o| o.status.success())\n        .unwrap_or(false)\n}","tryCatchPattern":"if let Err(e) = run_pr_preview(cmd) {\n    if e.to_string().ends_with(\"is not inside a git repository\") {\n        eprintln!(\"Point --path at a valid git work tree\");\n    }\n}","preventionTips":["Verify the target directory is a git work tree before invoking","Don't pass scratch/export directories via --path","Check .git exists and is not corrupted"],"tags":["git","cli","pr","filesystem"],"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"}