{"record":{"id":"57645d14a995a4c8","repo":"nikivdev/code","slug":"git-failed-57645d","errorCode":null,"errorMessage":"git {} failed","messagePattern":"git (.+?) failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/push.rs","lineNumber":355,"sourceCode":"        .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    }\n    Ok(name)\n}\n\npub(crate) fn git_capture_in(repo_root: &Path, args: &[&str]) -> Result<String> {\n    let output = Command::new(\"git\")\n        .args(args)\n        .current_dir(repo_root)\n        .output()\n        .with_context(|| format!(\"failed to run git {}\", args.join(\" \")))?;\n    if !output.status.success() {\n        bail!(\"git {} failed\", args.join(\" \"));\n    }\n    Ok(String::from_utf8_lossy(&output.stdout).to_string())\n}\n\npub(crate) fn git_run_in(repo_root: &Path, args: &[&str]) -> Result<()> {\n    git_run_in_with_env(repo_root, args, &[])\n}\n\npub(crate) fn git_run_in_with_env(\n    repo_root: &Path,\n    args: &[&str],\n    envs: &[(&str, &str)],\n) -> Result<()> {\n    let status = Command::new(\"git\")\n        .args(args)\n        .current_dir(repo_root)\n        .envs(envs.iter().copied())\n        .stdin(Stdio::inherit())","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/push.rs#L337-L373","documentation":"Raised by git_capture_in in src/push.rs when a git command whose stdout the tool captures (e.g. `git remote get-url ...`) exits with a non-zero status. The message includes the full git argument list so the failing subcommand is identifiable; stderr is not shown, only the failure indicator.","triggerScenarios":"Any captured git invocation fails — most commonly `git remote get-url <remote>` for a remote that does not exist (handled elsewhere as Ok), but also `git ls-remote`/similar failing due to network/auth, invalid args, or a bad repo state under repo_root.","commonSituations":"Typo'd remote or branch names; pushing to a repo the user cannot access (auth failure); network offline; running from a worktree path that no longer exists.","solutions":["Read the error text to identify the exact failing git subcommand and re-run it manually in the repo to see stderr details","Fix the underlying issue (create the missing remote/branch, fix credentials, check network)","Ensure the command is run from a valid repository root"],"exampleFix":"// before: branch does not exist\nbail!(\"git ls-remote ... failed\")\n// after: verify the ref exists first\nlet out = git_capture_in(root, &[\"rev-parse\", \"--verify\", branch])?;","handlingStrategy":"try-catch","validationCode":"// ensure refs/remotes exist before capture\nlet ok = std::process::Command::new(\"git\")\n    .args([\"rev-parse\", \"--verify\", ref_name])\n    .output()?\n    .status.success();\nif !ok { eprintln!(\"ref {ref_name} does not exist\"); }","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().starts_with(\"git \") && e.to_string().ends_with(\" failed\") => {\n        // rerun the same args manually with stderr visible to get the cause\n    }\n    Err(e) => return Err(e),\n    Ok(v) => Ok(v),\n}","preventionTips":["Run captured git commands manually first to inspect stderr","Verify remote/branch names exist before invoking the tool","Check network/auth when the captured command talks to a remote"],"tags":["git","subprocess","exit-code"],"backgroundTag":"git-command-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}