jdx/mise · error

git diff failed ( )

Error message

git diff failed ({}): {}

What it means

Same `git diff` exit-status contract as the sibling error, but this variant also appends git's trimmed stderr, giving the actual git error message. It fires when `git diff --exit-code` terminates with a status other than 0/1, so the failure reason from git is surfaced to the caller.

Solutions

  1. Read the stderr in the message: it names the git failure (missing object, bad revision, lock) and fix that specific cause.
  2. Remove a stale `index.lock` in the history store if git reports lock contention and no other run is active.
  3. Run `git fsck` in the history store to detect and assess corruption; re-capture snapshots if objects are lost.
  4. Avoid running multiple mise history operations concurrently.
Defensive patterns

Strategy: try-catch

Validate before calling

# verify the referenced objects exist before diffing
git -C "$(mise history store-path)" cat-file -t <from-tree> && \
git -C "$(mise history store-path)" cat-file -t <to-tree>

Try / catch

// Rust
match diff_snapshots(a, b) {
    Ok(d) => show(d),
    Err(e) => {
        let msg = e.to_string();
        if let Some(stderr) = msg.strip_prefix("git diff failed (") {
            eprintln!("git reported: {stderr}"); // act on the concrete git error
        }
    }
}

Prevention

When it happens

Trigger: `git diff` exits with an unexpected code (commonly 128) and the handler at shadow.rs:1172 formats `git diff failed ({}): {}` with git's stderr — e.g. unknown revision, bad object, lock-file contention, or malformed arguments.

Common situations: Diffing snapshots whose objects were garbage-collected or pruned, concurrent mise runs fighting over the history repo's lock, or a corrupted history store after a crash or disk-full event.

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/9c8224aae6188976. Report an issue: GitHub.

Appendix: source

Thrown at src/system/history/shadow.rs:1172

                    output: vec![],
                    changed: true,
                }),
                _ => bail!("git diff failed ({status})"),
            };
        }
        let output = self.git.output_unchecked(call)?;
        match output.status.code() {
            Some(0) => Ok(DiffResult {
                output: output.stdout,
                changed: false,
            }),
            Some(1) => Ok(DiffResult {
                output: output.stdout,
                changed: true,
            }),
            _ => {
                let stderr = String::from_utf8_lossy(&output.stderr);
                bail!("git diff failed ({}): {}", output.status, stderr.trim())
            }
        }
    }

    /// Decrypt only for this requested comparison. Git's no-index diff sees
    /// private temporary files, never plaintext objects in the repository.
    fn decrypted_diff(&self, a: &str, b: &str, opts: &DiffOpts) -> Result<DiffResult> {
        use std::io::Write;
        let mut paths = BTreeSet::new();
        for (tree, prefix) in [
            (a, opts.paths.as_ref().map(|p| p.0.as_str())),
            (b, opts.paths.as_ref().map(|p| p.1.as_str())),
        ] {
            for entry in self.ls_tree(tree)? {
                if entry.path.starts_with(".mise-history/") {
                    continue;
                }
                if let Some(prefix) = prefix {

View on GitHub (pinned to 533346cc37)