jdx/mise · error · eyre::Report

git -C {} {} failed: {}

Error message

git -C {} {} failed: {}

What it means

git_output runs a git query (`status --porcelain`, `rev-parse`, `ls-remote`, `config --get remote.origin.url`) with `-c safe.directory=<path> -c core.autocrlf=false` and captures the output; a non-zero exit bails with the repo path, the joined git arguments, and git's trimmed stderr. It surfaces from is_clean during status computation and from `rev-parse --abbrev-ref HEAD` in the unpinned-update path (e.g. a repo whose HEAD is unborn); many other call sites swallow this error via `.ok()` / `unwrap_or`.

Source

Thrown at src/system/repos.rs:725

fn pull_ref_for(git_ref: &str) -> &str {
    git_ref.strip_prefix("refs/heads/").unwrap_or(git_ref)
}

fn git_output(path: &Path, args: &[&str]) -> Result<String> {
    let safe = format!("safe.directory={}", path.display());
    let output = Command::new("git")
        .arg("-C")
        .arg(path)
        .arg("-c")
        .arg(safe)
        .arg("-c")
        .arg("core.autocrlf=false")
        .args(args)
        .output()
        .map_err(|err| eyre!("git failed: {err:#}"))?;
    if !output.status.success() {
        bail!(
            "git -C {} {} failed: {}",
            path.display(),
            shell_words::join(args),
            String::from_utf8_lossy(&output.stderr).trim()
        );
    }
    Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
}

fn git_success(path: &Path, args: &[&str]) -> Result<bool> {
    let safe = format!("safe.directory={}", path.display());
    let status = Command::new("git")
        .arg("-C")
        .arg(path)
        .arg("-c")
        .arg(safe)
        .arg("-c")
        .arg("core.autocrlf=false")

View on GitHub (pinned to 9dcfcaa0dc)

Solutions

  1. Run the exact command from the message to see the raw error: `git -C <path> -c safe.directory=<path> <args>`
  2. For network/auth failures, verify `git -C <repo> fetch origin` works interactively in the same environment
  3. For corrupt repositories, run `git -C <repo> fsck` and repair, or delete the directory so bootstrap re-clones
  4. For an unborn-HEAD repo, make an initial commit or remove the directory

Example fix

# before: manual empty init at the target path
$ git init ~/src/x && mise bootstrap   # git -C ~/src/x rev-parse --abbrev-ref HEAD failed: ...

# after: let bootstrap own the clone
$ rm -rf ~/src/x
$ mise bootstrap
Defensive patterns

Strategy: try-catch

Validate before calling

fn git_query_ok(path: &Path, args: &[&str]) -> bool {
    std::process::Command::new("git")
        .arg("-C").arg(path)
        .args(args)
        .output()
        .map(|o| o.status.success())
        .unwrap_or(false)
}
// a repo is safely manageable when these all succeed:
// ["status", "--porcelain=v1"], ["rev-parse", "--abbrev-ref", "HEAD"], ["rev-parse", "HEAD"]

Type guard

fn repo_has_commits(path: &Path) -> bool {
    git_query_ok(path, &["rev-parse", "--verify", "HEAD"])
}

Try / catch

match repos::status(&requests) {
    Ok(statuses) => { /* proceed with preflight/apply */ }
    Err(report) => {
        let msg = format!("{report:#}");
        if msg.starts_with("git -C ") && msg.contains(" failed: ") {
            // msg embeds path, git args, and git's stderr —
            // reproduce manually and branch on the stderr content
            // (auth vs network vs corrupt repo have different fixes)
        }
    }
}

Prevention

When it happens

Trigger: `git status --porcelain=v1` failing on a corrupt index; `rev-parse --abbrev-ref HEAD` failing in a manually `git init`-ed repo with zero commits sitting at the target path; `ls-remote origin` failing from network or credential errors during ref-currency checks that do propagate.

Common situations: Expired credentials, missing SSH agent, or no network when bootstrap contacts origin; interrupted git operations leaving a corrupt index; an empty skeleton repo created by hand where bootstrap expected a clone.

Related errors


AI-assisted analysis of jdx/mise@9dcfcaa0dc (2026-08-17). Data as JSON: /api/errors/1b27d8bce6c7b094. Report an issue: GitHub.