{"record":{"id":"8b873867a30b39ba","repo":"nikivdev/code","slug":"not-inside-a-git-repository","errorCode":null,"errorMessage":"not inside a git repository","messagePattern":"not inside a git repository","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/commits.rs","lineNumber":544,"sourceCode":"    Ok(())\n}\n\nfn top_hashes(entries: &[TopEntry]) -> HashSet<String> {\n    entries.iter().map(|entry| entry.hash.clone()).collect()\n}\n\nfn top_file_path() -> Result<PathBuf> {\n    let root = repo_root()?;\n    Ok(root.join(TOP_COMMITS_PATH))\n}\n\nfn repo_root() -> Result<PathBuf> {\n    let output = Command::new(\"git\")\n        .args([\"rev-parse\", \"--show-toplevel\"])\n        .output()\n        .context(\"failed to run git rev-parse\")?;\n    if !output.status.success() {\n        bail!(\"not inside a git repository\");\n    }\n    Ok(Path::new(String::from_utf8_lossy(&output.stdout).trim()).to_path_buf())\n}\n","sourceCodeStart":526,"sourceCodeEnd":548,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/commits.rs#L526-L548","documentation":"Thrown by `repo_root()` (used by `top_file_path`) when `git rev-parse --show-toplevel` exits non-zero, which happens when the current working directory is not inside a git repository or work tree. The library needs the repo root to locate its top-entries file, so it cannot proceed.","triggerScenarios":"Invoking any commits/top subcommand from a directory outside a git work tree, inside a bare repository's internals, or in a directory whose .git is corrupt/missing so rev-parse fails.","commonSituations":"Running the tool in $HOME or a temp dir, running in a submodule-less bare clone, .git directory deleted or corrupted, or GIT_DIR pointing somewhere invalid in the environment.","solutions":["`cd` into a directory inside a git repository (one containing a valid .git)","Run `git rev-parse --show-toplevel` yourself to confirm git sees the repo","If .git is broken, restore it (`git init` if appropriate, or re-clone)","Check that GIT_DIR/GIT_WORK_TREE env vars are not misdirecting git"],"exampleFix":"// before (shell)\n~/scratch $ tool commits top\n// not inside a git repository\n// after (shell)\n~/scratch $ cd ~/projects/myrepo\n~/projects/myrepo $ tool commits top","handlingStrategy":"validation","validationCode":"// check before invoking any commits subcommand\nlet out = Command::new(\"git\")\n    .args([\"rev-parse\", \"--show-toplevel\"])\n    .output()?;\nif !out.status.success() {\n    eprintln!(\"current directory is not a git repository; cd into a repo first\");\n    std::process::exit(1);\n}","typeGuard":"fn inside_git_repo() -> bool {\n    Command::new(\"git\")\n        .args([\"rev-parse\", \"--is-inside-work-tree\"])\n        .output()\n        .map(|o| o.status.success())\n        .unwrap_or(false)\n}","tryCatchPattern":"match run_top_command() {\n    Err(e) if e.to_string() == \"not inside a git repository\" => {\n        eprintln!(\"Run this from inside a git repository (cwd: {:?})\", std::env::current_dir()?);\n        std::process::exit(1);\n    }\n    other => other?,\n}","preventionTips":["Check `git rev-parse --is-inside-work-tree` before running repo-scoped tools","Avoid running the tool in $HOME or scratch directories","Verify GIT_DIR/GIT_WORK_TREE env overrides are intentional","Re-clone or `git init` if .git is missing/corrupt"],"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"}