{"record":{"id":"a2d9836602fba129","repo":"nikivdev/code","slug":"not-inside-a-git-repository-a2d983","errorCode":null,"errorMessage":"not inside a git repository","messagePattern":"not inside a git repository","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/push.rs","lineNumber":326,"sourceCode":"pub(crate) fn normalize_git_url(url: &str) -> String {\n    let url = url.trim();\n    let url = if url.starts_with(\"git@github.com:\") {\n        url.replace(\"git@github.com:\", \"github.com/\")\n    } else if url.starts_with(\"https://github.com/\") {\n        url.replace(\"https://github.com/\", \"github.com/\")\n    } else {\n        url.to_string()\n    };\n    url.trim_end_matches(\".git\").to_lowercase()\n}\n\nfn git_root() -> Result<PathBuf> {\n    let output = Command::new(\"git\")\n        .args([\"rev-parse\", \"--show-toplevel\"])\n        .output()\n        .context(\"failed to locate git root\")?;\n    if !output.status.success() {\n        bail!(\"not inside a git repository\");\n    }\n    let path = String::from_utf8_lossy(&output.stdout).trim().to_string();\n    Ok(PathBuf::from(path))\n}\n\nfn current_branch(repo_root: &Path) -> Result<String> {\n    let output = Command::new(\"git\")\n        .args([\"rev-parse\", \"--abbrev-ref\", \"HEAD\"])\n        .current_dir(repo_root)\n        .output()\n        .context(\"failed to read current branch\")?;\n    if !output.status.success() {\n        bail!(\"git rev-parse --abbrev-ref HEAD failed\");\n    }\n    let name = String::from_utf8_lossy(&output.stdout).trim().to_string();\n    if name.is_empty() || name == \"HEAD\" {\n        bail!(\"detached HEAD (checkout a branch first)\");\n    }","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/push.rs#L308-L344","documentation":"Raised by git_root in src/push.rs when `git rev-parse --show-toplevel` exits non-zero, meaning the current working directory is not inside a git working tree. The mirror-push flow needs the repo root to run all subsequent git commands, so it aborts early with this message.","triggerScenarios":"Invoking the push command from a directory outside any git repository, or inside a directory where git cannot determine a toplevel (e.g. .git removed, or a bare/uninitialized directory).","commonSituations":"Running `f push` from $HOME or a random folder instead of the project; the .git directory was deleted; running inside a submodule-style or bare checkout where --show-toplevel fails; typo'd working directory in a script.","solutions":["cd into your git repository root before running the command","Run `git rev-parse --show-toplevel` yourself to confirm git sees a repo at your location","If .git is missing, re-clone or run `git init` as appropriate"],"exampleFix":"// before\n$ cd /tmp && f push\nnot inside a git repository\n// after\n$ cd ~/my-project && f push","handlingStrategy":"validation","validationCode":"let inside = std::process::Command::new(\"git\")\n    .args([\"rev-parse\", \"--show-toplevel\"])\n    .status()\n    .map(|s| s.success())\n    .unwrap_or(false);\nif !inside { eprintln!(\"cd into your git repository before pushing\"); }","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"not inside a git repository\") => {\n        eprintln!(\"run from a repo root\");\n    }\n    Err(e) => return Err(e),\n    Ok(v) => Ok(v),\n}","preventionTips":["Always run the command from the project root","Verify `git rev-parse --show-toplevel` succeeds first","Avoid deleting or moving .git directories"],"tags":["git","working-directory","cli"],"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"}