{"record":{"id":"ea3550ee55061d2b","repo":"nikivdev/code","slug":"origin-mismatch-expected-got","errorCode":null,"errorMessage":"{} origin mismatch: expected {}, got {}","messagePattern":"(.+?) origin mismatch: expected (.+?), got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/home.rs","lineNumber":578,"sourceCode":"}\n\nfn ensure_repo(\n    dest: &Path,\n    repo_url: Option<&str>,\n    label: &str,\n    allow_origin_reset: bool,\n) -> Result<()> {\n    if dest.exists() {\n        if !dest.join(\".git\").exists() {\n            bail!(\"{} exists but is not a git repo: {}\", label, dest.display());\n        }\n\n        if let Some(expected) = repo_url {\n            if allow_origin_reset {\n                ensure_origin_url(dest, expected)?;\n            } else if let Ok(actual) = git_capture(dest, &[\"remote\", \"get-url\", \"origin\"]) {\n                if !urls_match(expected, actual.trim()) {\n                    bail!(\n                        \"{} origin mismatch: expected {}, got {}\",\n                        label,\n                        expected,\n                        actual.trim()\n                    );\n                }\n            }\n        }\n\n        update_repo(dest)?;\n        return Ok(());\n    }\n\n    let repo_url = repo_url.ok_or_else(|| anyhow::anyhow!(\"{} repo URL required\", label))?;\n    clone_repo(repo_url, dest)?;\n    Ok(())\n}\n","sourceCodeStart":560,"sourceCodeEnd":596,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/home.rs#L560-L596","documentation":"ensure_repo compares the actual `origin` remote URL of an existing repo against the expected URL. When they differ and origin auto-reset is not enabled (allow_origin_reset == false), it bails with the label, expected, and actual URLs. This prevents the tool from pulling/pushing against the wrong remote.","triggerScenarios":"ensure_repo on an existing repo whose `git remote get-url origin` output does not match the configured repo_url per urls_match(); allow_origin_reset is false so the mismatch is not silently corrected.","commonSituations":"Repo cloned from a fork or HTTPS while config expects SSH (or vice versa); remote was renamed/transferred upstream; user repointed origin to their own mirror; config repo_url changed after the initial clone.","solutions":["Update origin to the expected URL: git -C <dest> remote set-url origin <expected>","Enable allow_origin_reset so ensure_origin_url fixes origin automatically","Re-clone the repo from the expected URL","Align the configured repo_url with the actual origin if the current remote is correct"],"exampleFix":"// before\n$ git -C ~/.config/kar remote get-url origin\nhttps://github.com/old/kar.git\n// after\n$ git -C ~/.config/kar remote set-url origin git@github.com:owner/kar.git","handlingStrategy":"try-catch","validationCode":"let actual = git_capture(dest, &[\"remote\", \"get-url\", \"origin\"])?;\nif !urls_match(expected, actual.trim()) {\n    eprintln!(\"origin mismatch: expected {}, got {}\", expected, actual.trim());\n}","typeGuard":null,"tryCatchPattern":"match ensure_repo(...) {\n    Err(e) if e.to_string().contains(\"origin mismatch\") => {\n        eprintln!(\"fix with: git -C {} remote set-url origin <expected>\", dest.display());\n    }\n    r => r?,\n}","preventionTips":["Clone from the same URL scheme (SSH vs HTTPS) your config expects","Update config repo_url when upstream repos are renamed/transferred","Enable allow_origin_reset if you want the tool to auto-correct origin","Audit `git remote -v` on managed repos after manual git work"],"tags":["git","remote-url","origin-mismatch"],"backgroundTag":"git-origin-mismatch","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}