jdx/mise · error

git -C failed

Error message

git -C {} {} failed: {}

What it means

The repos subsystem's `git_output` helper runs `git -C <path> <args>` and captures output. If git exits non-zero, the error wraps the path, the shell-quoted arguments, and git's trimmed stderr. This is the standard wrapper failure for all read-only git queries (status, current ref, sha, local refs) used by repos status/update.

Solutions

  1. Read the quoted git command and stderr in the message to see git's own explanation.
  2. Run the exact quoted `git -C <path> <args>` command by hand to reproduce and debug.
  3. If a pinned ref is missing, verify it exists (`git ls-remote origin <ref>`) and fix the ref in your repos config.
  4. Repair or re-clone a corrupt repo; check .git permissions.

Example fix

// config pinning a nonexistent tag
[[repos]]
path = "~/code/myrepo"
ref = "v9.9.9"
// after: fix the ref to an existing tag
[[repos]]
path = "~/code/myrepo"
ref = "v1.2.0"
Defensive patterns

Strategy: try-catch

Validate before calling

# Verify the repo is a valid git repo and pinned refs exist before running repos commands
git -C "$repo" rev-parse --is-inside-work-tree || echo "not a git repo"
git -C "$repo" cat-file -e "$ref" 2>/dev/null || echo "ref missing: $ref"

Try / catch

match result {
    Err(e) if e.to_string().contains("git -C") => {
        eprintln!("git query failed: {e:#}; check the quoted command and stderr");
    }
    r => r?,
}

Prevention

When it happens

Trigger: Any repos command calling status_one, is_git_repo, is_clean, current_ref, current_sha, or local_ref_sha where git exits non-zero — e.g. querying a ref/sha that doesn't exist, a corrupt repo, or a path that is no longer a git repo mid-operation.

Common situations: Pinned ref/tag deleted from origin and locally; git objects corrupted; repo directory replaced by a non-git folder; permission problems on .git.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


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

Appendix: source

Thrown at src/system/repos.rs:728

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 533346cc37)