{"record":{"id":"e08dca14926ab6a7","repo":"jdx/mise","slug":"failed-to-locate-git-repository-for","errorCode":null,"errorMessage":"failed to locate Git repository for {}: {}","messagePattern":"failed to locate Git repository for (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/files.rs","lineNumber":1905,"sourceCode":"    let mut root_command = Command::new(\"git\");\n    root_command\n        .arg(\"-C\")\n        .arg(source)\n        .args([\"-c\", \"safe.directory=*\", \"rev-parse\", \"--show-toplevel\"])\n        .stdout(std::process::Stdio::piped())\n        .stderr(std::process::Stdio::piped());\n    crate::git::sanitize_git_command(&mut root_command);\n    let root_output = root_command.output().wrap_err_with(|| {\n        format!(\n            \"failed to locate Git repository for {}\",\n            source.display_user()\n        )\n    })?;\n    if !root_output.status.success() {\n        let stderr = String::from_utf8_lossy(&root_output.stderr)\n            .trim()\n            .to_string();\n        bail!(\n            \"failed to locate Git repository for {}: {}\",\n            source.display_user(),\n            if stderr.is_empty() {\n                root_output.status.to_string()\n            } else {\n                stderr\n            }\n        );\n    }\n    let root = root_output\n        .stdout\n        .strip_suffix(b\"\\n\")\n        .unwrap_or(&root_output.stdout);\n    let root = root.strip_suffix(b\"\\r\").unwrap_or(root);\n    let safe = format!(\"safe.directory={}\", path_buf_from_git_bytes(root).display());\n    let mut command = Command::new(\"git\");\n    command\n        .arg(\"-C\")","sourceCodeStart":1887,"sourceCodeEnd":1923,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/system/files.rs#L1887-L1923","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before (mise.toml)\n[[files]]\nsource = \"~/dotfiles\"\n\n// after\n# cd ~/dotfiles && git init && git add -A && git commit -m init\n# (or clone: git clone git@github.com:you/dotfiles.git ~/dotfiles)","handlingStrategy":"validation","validationCode":"use std::process::Command;\nfn ensure_git_repo(source: &std::path::Path) -> anyhow::Result<()> {\n    let out = Command::new(\"git\")\n        .arg(\"rev-parse\").arg(\"--show-toplevel\")\n        .current_dir(source)\n        .output()?;\n    if !out.status.success() {\n        anyhow::bail!(\n            \"source {} is not inside a Git repository: {}\",\n            source.display(),\n            String::from_utf8_lossy(&out.stderr).trim()\n        );\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"failed to locate Git repository\") => {\n        eprintln!(\"Source is not a Git repo; run `git init` or fix the repo first: {e}\");\n    }\n    Err(e) => return Err(e),\n    Ok(plan) => apply(plan),\n}","preventionTips":["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."],"tags":["git","dotfiles","filesystem"],"backgroundTag":"git-command-failed","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}