{"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":null,"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/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/worktree/mod.rs#L595-L631","documentation":"git_remote_origin_url runs `git remote get-url origin` on the repo root to build a GitHub compare URL. This error is raised when git exits nonzero — normally because the repository has no remote named 'origin' — with git's stderr included in the message.","triggerScenarios":"Calling github_compare_url on a repo where origin was never added, was renamed, or the path is not a git repository.","commonSituations":"Locally cloned repos added as remotes under a different name (e.g. 'upstream'); repos initialized without a remote; bare repos reorganized after cloning; CI checkouts using a remote alias.","solutions":["Add or fix the origin remote: `git remote add origin <url>` or rename the existing remote to origin.","Run `git remote -v` in the repo root to see what remotes exist.","If origin legitimately may be absent, skip compare-URL generation and handle the error instead of failing the whole flow.","Confirm the repo_root path passed in is the actual git checkout."],"exampleFix":"// before\nlet url = github_compare_url(&wt)?; // fails when origin missing\n// after\nmatch github_compare_url(&wt) {\n    Ok(url) => println!(\"{url}\"),\n    Err(_) => eprintln!(\"no origin remote; compare URL unavailable\"),\n}","handlingStrategy":"fallback","validationCode":"fn has_origin(root: &Path) -> bool {\n    Command::new(\"git\").arg(root).args([\"remote\", \"get-url\", \"origin\"])\n        .output().map(|o| o.status.success()).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match github_compare_url(&wt) {\n    Ok(url) => use(url),\n    Err(_) => eprintln!(\"compare URL unavailable: no origin remote\"),\n}","preventionTips":["Ensure origin exists: `git remote add origin <url>`","Name the primary remote 'origin' when cloning","Skip URL generation gracefully when origin is absent"],"tags":["git","remote","configuration"],"backgroundTag":"git-command-failed","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}