jdx/mise · error

cannot check staged changes in {}: {}

Error message

cannot check staged changes in {}: {}

What it means

staged_paths runs git in each configured root; when that git invocation exits non-zero the stderr is surfaced verbatim. This wraps any git failure (not a repo, permission problem, corrupted index, dubious ownership) with a uniform message naming the root.

Source

Thrown at src/system/history/sync/apply.rs:871

            .arg("-C")
            .arg(&root)
            .args([
                "-c",
                "core.fsmonitor=false",
                "diff",
                "--cached",
                "--name-only",
                "-z",
                "--no-renames",
                "--no-ext-diff",
                "--no-textconv",
                "--",
            ])
            .env("GIT_OPTIONAL_LOCKS", "0")
            .stdin(std::process::Stdio::null())
            .output()?;
        if !output.status.success() {
            bail!(
                "cannot check staged changes in {}: {}",
                display_path(&root),
                String::from_utf8_lossy(&output.stderr).trim()
            );
        }
        for name in output
            .stdout
            .split(|byte| *byte == 0)
            .filter(|name| !name.is_empty())
        {
            #[cfg(unix)]
            let relative = {
                use std::os::unix::ffi::OsStrExt;
                PathBuf::from(std::ffi::OsStr::from_bytes(name))
            };
            #[cfg(not(unix))]
            let relative = PathBuf::from(std::str::from_utf8(name)?);
            staged.insert(normalize_target(&root.join(relative)));

View on GitHub (pinned to afd2eddd3a)

Solutions

  1. Run `git -C <root> status` manually to see the underlying git error and fix it (e.g. `git config --global --add safe.directory <root>`).
  2. Remove a stale `.git/index.lock` if present.
  3. Ensure the configured root is actually a git work tree, or remove it from the roots list.

Example fix

// before
git -C ~/project status   # fails: dubious ownership
// after
git config --global --add safe.directory /home/me/project
Defensive patterns

Strategy: try-catch

Validate before calling

git -C "$ROOT" rev-parse --is-inside-work-tree || echo "root is not a git repo"

Try / catch

match staged_paths(repo, &roots) {
    Err(e) if e.to_string().starts_with("cannot check staged changes in") => {
        // parse root + stderr from the message and fix the repo
    }
    other => other?,
}

Prevention

When it happens

Trigger: `git -C <root> diff --staged --name-only -z --` exits non-zero: root is not a git repository, .git is unreadable, index.lock is stale, or git's safe.directory check rejects the repo.

Common situations: Root configured outside any git repo; repo owned by another user triggering 'dubious ownership'; leftover index.lock after a crash; running in a sandbox where the .git dir is read-only-denied.

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@afd2eddd3a (2026-09-09). Data as JSON: /api/errors/9b2cb46d243e0d3d. Report an issue: GitHub.