{"record":{"id":"72010a6fc2659aa2","repo":"nikivdev/code","slug":"not-a-git-repository-72010a","errorCode":null,"errorMessage":"Not a git repository","messagePattern":"Not a git repository","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/commit.rs","lineNumber":6556,"sourceCode":"        issues,\n        summary,\n        future_tasks,\n        timed_out: false,\n        quality,\n    })\n}\n\nfn ensure_git_repo() -> Result<()> {\n    let _ = vcs::ensure_jj_repo()?;\n    let output = Command::new(\"git\")\n        .args([\"rev-parse\", \"--git-dir\"])\n        .stdout(Stdio::null())\n        .stderr(Stdio::null())\n        .status()\n        .context(\"failed to run git\")?;\n\n    if !output.success() {\n        bail!(\"Not a git repository\");\n    }\n    Ok(())\n}\n\nfn git_root_or_cwd() -> std::path::PathBuf {\n    match git_capture(&[\"rev-parse\", \"--show-toplevel\"]) {\n        Ok(root) => std::path::PathBuf::from(root.trim()),\n        Err(_) => std::env::current_dir().unwrap_or_default(),\n    }\n}\n\nfn warn_if_commit_invoked_from_subdir(repo_root: &Path) {\n    let Ok(cwd) = std::env::current_dir() else {\n        return;\n    };\n    let cwd_norm = cwd.canonicalize().unwrap_or(cwd.clone());\n    let root_norm = repo_root\n        .canonicalize()","sourceCodeStart":6538,"sourceCodeEnd":6574,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/commit.rs#L6538-L6574","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)"],"exampleFix":"// before (shell)\nf commit -m \"msg\"   # run in ~/projects/plain-dir\n// after (shell)\ncd ~/projects/my-repo && f commit -m \"msg\"","handlingStrategy":"validation","validationCode":"use std::process::Command;\nfn in_git_repo() -> bool {\n    Command::new(\"git\")\n        .args([\"rev-parse\", \"--is-inside-work-tree\"])\n        .output()\n        .map(|o| o.status.success()\n            && String::from_utf8_lossy(&o.stdout).trim() == \"true\")\n        .unwrap_or(false)\n}\nif !in_git_repo() { eprintln!(\"not a git repo; cd into your project first\"); }","typeGuard":null,"tryCatchPattern":"if let Err(e) = tool.commit(msg) {\n    if e.to_string().contains(\"Not a git repository\") {\n        eprintln!(\"cd into your git repo root and retry: {}\", e);\n    } else { return Err(e.into()); }\n}","preventionTips":["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"],"tags":["git","environment","precondition"],"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"}