{"record":{"id":"634f7869c5122f42","repo":"affaan-m/ECC","slug":"git-remote-get-url-origin-failed-stderr","errorCode":null,"errorMessage":"git remote get-url origin failed: {stderr}","messagePattern":"git remote get-url origin failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"ecc2/src/worktree/mod.rs","lineNumber":613,"sourceCode":"        .context(\"Failed to create draft PR with gh\")?;\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        anyhow::bail!(\"gh pr create failed: {stderr}\");\n    }\n\n    Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())\n}\n\nfn git_remote_origin_url(repo_root: &Path) -> Result<String> {\n    let output = Command::new(\"git\")\n        .arg(\"-C\")\n        .arg(repo_root)\n        .args([\"remote\", \"get-url\", \"origin\"])\n        .output()\n        .context(\"Failed to resolve git origin remote\")?;\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        anyhow::bail!(\"git remote get-url origin failed: {stderr}\");\n    }\n\n    Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())\n}\n\nfn github_repo_web_url(origin: &str) -> Option<String> {\n    let trimmed = origin.trim().trim_end_matches(\".git\");\n    if trimmed.is_empty() {\n        return None;\n    }\n\n    if let Some(rest) = trimmed.strip_prefix(\"git@\") {\n        let (host, path) = rest.split_once(':')?;\n        return Some(format!(\"https://{host}/{}\", path.trim_start_matches('/')));\n    }\n\n    if let Some(rest) = trimmed.strip_prefix(\"ssh://\") {\n        return parse_httpish_remote(rest);","sourceCodeStart":595,"sourceCodeEnd":631,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/ecc2/src/worktree/mod.rs#L595-L631","documentation":"git_remote_origin_url runs `git -C <repo_root> remote get-url origin`. A non-zero exit re-throws git's stderr. The function underpins github_compare_url and the GitHub-URL derivation logic; without an `origin` remote those features cannot work.","triggerScenarios":"Calling github_compare_url on a worktree whose repo root has no `origin` remote; the remote was renamed (e.g. to `upstream`); the repo root path passed in is not actually a git repo.","commonSituations":"Local-only repo cloned via file:// with no origin; remote renamed by a fork-and-repoint workflow; repo_root resolved incorrectly (pointed at a subdirectory that is itself a separate repo or no repo).","solutions":["Add an origin remote: `git -C <root> remote add origin <url>`.","If the remote is intentionally named differently, extend git_remote_origin_url or pass the remote name explicitly.","Verify `repo_root` is the actual repository root with `git -C <root> rev-parse --show-toplevel`.","Treat the `None`/Err path in callers (e.g. github_compare_url already returns Ok(None) when the URL is not GitHub-shaped) gracefully."],"exampleFix":"// before\nlet origin = git_remote_origin_url(&repo_root)?;\n\n// after\nlet origin = match git_remote_origin_url(&repo_root) {\n    Ok(url) => url,\n    Err(_) => {\n        // no origin configured; degrade gracefully\n        return Ok(None);\n    }\n};","handlingStrategy":"validation","validationCode":"use std::process::Command;\n\nfn origin_remote_url(repo_root: &Path) -> Option<String> {\n    let out = Command::new(\"git\")\n        .arg(\"-C\").arg(repo_root)\n        .args([\"remote\", \"get-url\", \"origin\"])\n        .output().ok()?;\n    if out.status.success() {\n        Some(String::from_utf8_lossy(&out.stdout).trim().to_string())\n    } else {\n        None\n    }\n}\n\nlet origin = match origin_remote_url(&repo_root) {\n    Some(u) => u,\n    None => return Ok(None), // degrade gracefully when no origin is set\n};","typeGuard":null,"tryCatchPattern":"match git_remote_origin_url(&repo_root) {\n    Ok(url) => Ok(Some(url)),\n    Err(e) if format!(\"{e:#}\").contains(\"No such remote\") => Ok(None),\n    Err(e) => Err(e),\n}","preventionTips":["Ensure `git remote add origin <url>` is part of repo bootstrap.","Confirm the repo root with `git rev-parse --show-toplevel` before resolving remotes.","Make GitHub-URL-dependent features optional: degrade gracefully when origin is absent."],"tags":["git","subprocess","worktree","remote","github"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}