jdx/mise · error

failed to locate Git repository for

Error message

failed to locate Git repository for {}: {}

What it means

When resolving a dotfile source that lives inside a Git repository, mise runs `git rev-parse --show-toplevel` (or similar) in the source directory. If the command cannot be run or the repo root cannot be located, it bails with this message including the target source path and git's stderr (or the exit status when stderr is empty).

Solutions

  1. Clone or restore the dotfiles Git repository so the source is inside a valid work tree.
  2. Install or repair `git` and ensure it is on PATH.
  3. Update the entry's `source` to a path inside the actual repository.

Example fix

# before: source deleted
dotfiles/  # missing
# after
git clone git@github.com:user/dotfiles.git ~/dotfiles  # entry source = ~/dotfiles/...
Defensive patterns

Strategy: validation

Validate before calling

let out = std::process::Command::new("git")
    .args(["rev-parse", "--show-toplevel"])
    .current_dir(source)
    .output()?;
if !out.status.success() {
    return Err("source is not inside a Git repository or git is unavailable".into());
}

Try / catch

match dotfiles_apply() {
    Err(e) if e.to_string().contains("failed to locate Git repository") => {
        eprintln!("clone the dotfiles repo or install git: {e}");
    }
    other => other?,
}

Prevention

When it happens

Trigger: A tracked/git-managed dotfile source points inside a directory that is not a Git work tree, or the `git` binary is unavailable/fails, during source resolution for a track-mode or git-aware entry.

Common situations: Dotfiles directory not yet cloned on a new machine; the source path was moved outside the repo; `git` not installed or not on PATH; a corrupted .git directory.

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

Appendix: source

Thrown at src/system/files.rs:2141

    let mut root_command = Command::new("git");
    root_command
        .arg("-C")
        .arg(source)
        .args(["-c", "safe.directory=*", "rev-parse", "--show-toplevel"])
        .stdout(std::process::Stdio::piped())
        .stderr(std::process::Stdio::piped());
    crate::git::sanitize_git_command(&mut root_command);
    let root_output = root_command.output().wrap_err_with(|| {
        format!(
            "failed to locate Git repository for {}",
            source.display_user()
        )
    })?;
    if !root_output.status.success() {
        let stderr = String::from_utf8_lossy(&root_output.stderr)
            .trim()
            .to_string();
        bail!(
            "failed to locate Git repository for {}: {}",
            source.display_user(),
            if stderr.is_empty() {
                root_output.status.to_string()
            } else {
                stderr
            }
        );
    }
    let root = root_output
        .stdout
        .strip_suffix(b"\n")
        .unwrap_or(&root_output.stdout);
    let root = root.strip_suffix(b"\r").unwrap_or(root);
    let safe = format!("safe.directory={}", path_buf_from_git_bytes(root).display());
    let mut command = Command::new("git");
    command
        .arg("-C")

View on GitHub (pinned to 533346cc37)