{"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":871,"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":853,"sourceCodeEnd":889,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/system/history/sync/apply.rs#L853-L889","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Run `git -C <root> status` manually to see the underlying git error and fix it (e.g. `git config --global --add safe.directory <root>`).","Remove a stale `.git/index.lock` if present.","Ensure the configured root is actually a git work tree, or remove it from the roots list."],"exampleFix":"// before\ngit -C ~/project status   # fails: dubious ownership\n// after\ngit config --global --add safe.directory /home/me/project","handlingStrategy":"try-catch","validationCode":"git -C \"$ROOT\" rev-parse --is-inside-work-tree || echo \"root is not a git repo\"","typeGuard":null,"tryCatchPattern":"match staged_paths(repo, &roots) {\n    Err(e) if e.to_string().starts_with(\"cannot check staged changes in\") => {\n        // parse root + stderr from the message and fix the repo\n    }\n    other => other?,\n}","preventionTips":["Verify each configured root is a valid git work tree","Add repos to safe.directory when ownership differs","Clean stale .git/index.lock files after crashes"],"tags":["git","subprocess","repository","sync"],"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-14T00:17:10.932Z"}