{"record":{"id":"9b2cb46d243e0d3d","repo":"jdx/mise","slug":"cannot-check-staged-changes-in","errorCode":null,"errorMessage":"cannot check staged changes in {}: {}","messagePattern":"cannot check staged changes in (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/history/sync/apply.rs","lineNumber":1025,"sourceCode":"            .arg(\"-C\")\n            .arg(&root)\n            .args([\n                \"-c\",\n                \"core.fsmonitor=false\",\n                \"diff\",\n                \"--cached\",\n                \"--name-only\",\n                \"-z\",\n                \"--no-renames\",\n                \"--no-ext-diff\",\n                \"--no-textconv\",\n                \"--\",\n            ])\n            .env(\"GIT_OPTIONAL_LOCKS\", \"0\")\n            .stdin(std::process::Stdio::null())\n            .output()?;\n        if !output.status.success() {\n            bail!(\n                \"cannot check staged changes in {}: {}\",\n                display_path(&root),\n                String::from_utf8_lossy(&output.stderr).trim()\n            );\n        }\n        for name in output\n            .stdout\n            .split(|byte| *byte == 0)\n            .filter(|name| !name.is_empty())\n        {\n            #[cfg(unix)]\n            let relative = {\n                use std::os::unix::ffi::OsStrExt;\n                PathBuf::from(std::ffi::OsStr::from_bytes(name))\n            };\n            #[cfg(not(unix))]\n            let relative = PathBuf::from(std::str::from_utf8(name)?);\n            staged.insert(normalize_target(&root.join(relative)));","sourceCodeStart":1007,"sourceCodeEnd":1043,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/history/sync/apply.rs#L1007-L1043","documentation":"staged_paths runs `git diff --name-only --cached --` (with GIT_OPTIONAL_LOCKS=0) inside each relevant root to enumerate staged changes. If that git invocation exits non-zero, mise bails with this error including the root path and git's trimmed stderr. It surfaces underlying git failures (corrupt repo, permission problems, dubious ownership) that would otherwise be hidden.","triggerScenarios":"During `mise dot sync` pull, the per-root `git diff --cached` subprocess returns a non-zero status; the git stderr text is embedded in the message. Common causes: the directory is a broken/partial git repo, `safe.directory` dubious-ownership refusal, or filesystem permission errors running git.","commonSituations":"A dotfiles directory that was copied from another user/machine triggering git's 'dubious ownership' check; a corrupted .git directory in the work root; read-only mounts that prevent git from running.","solutions":["Read the embedded git stderr in the message and fix that specific git error.","For 'dubious ownership' errors, run `git config --global --add safe.directory <root>` for the reported path.","Repair or remove the broken .git directory in the affected root, then retry the sync.","Check permissions on the directory and ensure the user running mise can execute git there."],"exampleFix":"// before\n$ mise dot sync\nerror: cannot check staged changes in ~/.config: fatal: detected dubious ownership in repository at '/home/user/.config'\n// after\n$ git config --global --add safe.directory /home/user/.config\n$ mise dot sync","handlingStrategy":"try-catch","validationCode":"# pre-flight the exact git call mise makes\ngit -C \"$ROOT\" diff --name-only --cached -- >/dev/null || echo \"git fails in $ROOT: $?\"","typeGuard":null,"tryCatchPattern":"match run_sync() {\n  Err(e) if e.starts_with(\"cannot check staged changes in\") => {\n    // parse embedded git stderr, fix repo (safe.directory, permissions), retry\n  }\n  other => other,\n}","preventionTips":["Add safe.directory entries for cross-user dotfiles roots.","Keep work roots as valid git repositories (don't half-delete .git).","Verify git works in each sync root before automating syncs."],"tags":["git","subprocess","sync","permissions"],"backgroundTag":"git-command-failed","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}