jdx/mise · error
failed to locate Git repository for {}: {}
Error message
failed to locate Git repository for {}: {} What it means
Thrown when the dotfiles/files subsystem cannot determine the Git repository root of a source directory. It runs `git rev-parse --show-toplevel` (or equivalent) in the source and, if Git itself fails, surfaces Git's stderr (or the exit status when stderr is empty) alongside the source path. This library requires a Git repository because the source's tracked-file list and content hashing depend on Git.
Source
Thrown at src/system/files.rs:1905
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 afd2eddd3a)
Solutions
- Initialize or restore the Git repository in the source directory (git init / re-clone).
- Fix the repository corruption or permission problems reported in the stderr included in the message.
- Point the files config at a directory that is actually inside a Git work tree.
- Verify `git rev-parse --show-toplevel` succeeds manually inside the source directory.
Example fix
// before (mise.toml) [[files]] source = "~/dotfiles" // after # cd ~/dotfiles && git init && git add -A && git commit -m init # (or clone: git clone git@github.com:you/dotfiles.git ~/dotfiles)
Defensive patterns
Strategy: validation
Validate before calling
use std::process::Command;
fn ensure_git_repo(source: &std::path::Path) -> anyhow::Result<()> {
let out = Command::new("git")
.arg("rev-parse").arg("--show-toplevel")
.current_dir(source)
.output()?;
if !out.status.success() {
anyhow::bail!(
"source {} is not inside a Git repository: {}",
source.display(),
String::from_utf8_lossy(&out.stderr).trim()
);
}
Ok(())
} Try / catch
match result {
Err(e) if e.to_string().contains("failed to locate Git repository") => {
eprintln!("Source is not a Git repo; run `git init` or fix the repo first: {e}");
}
Err(e) => return Err(e),
Ok(plan) => apply(plan),
} Prevention
- Keep dotfile sources under version control and verify `git rev-parse --show-toplevel` passes before configuring.
- Clone with git (preserving .git) rather than copying directories into CI/sandboxes.
- Check repo permissions so the mise process can read .git.
When it happens
Trigger: Applying or planning dotfiles whose `source` points at a directory that is not inside a Git work tree, or where running `git rev-parse --show-toplevel` fails (corrupt .git, permission error, git not functioning, bare/broken repo).
Common situations: Pointing `[files]` source at a plain (non-Git) directory; a repository with a deleted or corrupted .git directory; running in a sandbox/CI where the source was copied without .git; unreadable repo metadata due to permissions.
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
- failed to list Git-tracked files in {}: {}
- failed rename: {} -> {}: {err}
- {err} dotfiles: rollback failed: {rollback_err}
- {}
- comparing checkpoints requires git
AI-assisted analysis of jdx/mise@afd2eddd3a (2026-09-09).
Data as JSON: /api/errors/e08dca14926ab6a7.
Report an issue: GitHub.