nikivdev/code · error

{} origin mismatch: expected {}, got {}

Error message

{} origin mismatch: expected {}, got {}

What it means

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.

Source

Thrown at src/home.rs:578

}

fn ensure_repo(
    dest: &Path,
    repo_url: Option<&str>,
    label: &str,
    allow_origin_reset: bool,
) -> Result<()> {
    if dest.exists() {
        if !dest.join(".git").exists() {
            bail!("{} exists but is not a git repo: {}", label, dest.display());
        }

        if let Some(expected) = repo_url {
            if allow_origin_reset {
                ensure_origin_url(dest, expected)?;
            } else if let Ok(actual) = git_capture(dest, &["remote", "get-url", "origin"]) {
                if !urls_match(expected, actual.trim()) {
                    bail!(
                        "{} origin mismatch: expected {}, got {}",
                        label,
                        expected,
                        actual.trim()
                    );
                }
            }
        }

        update_repo(dest)?;
        return Ok(());
    }

    let repo_url = repo_url.ok_or_else(|| anyhow::anyhow!("{} repo URL required", label))?;
    clone_repo(repo_url, dest)?;
    Ok(())
}

View on GitHub (pinned to a747e741ae)

Solutions

  1. Update origin to the expected URL: git -C <dest> remote set-url origin <expected>
  2. Enable allow_origin_reset so ensure_origin_url fixes origin automatically
  3. Re-clone the repo from the expected URL
  4. Align the configured repo_url with the actual origin if the current remote is correct

Example fix

// before
$ git -C ~/.config/kar remote get-url origin
https://github.com/old/kar.git
// after
$ git -C ~/.config/kar remote set-url origin git@github.com:owner/kar.git
Defensive patterns

Strategy: try-catch

Validate before calling

let actual = git_capture(dest, &["remote", "get-url", "origin"])?;
if !urls_match(expected, actual.trim()) {
    eprintln!("origin mismatch: expected {}, got {}", expected, actual.trim());
}

Try / catch

match ensure_repo(...) {
    Err(e) if e.to_string().contains("origin mismatch") => {
        eprintln!("fix with: git -C {} remote set-url origin <expected>", dest.display());
    }
    r => r?,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/ea3550ee55061d2b. Report an issue: GitHub.