{"record":{"id":"05b96d23a270d04f","repo":"affaan-m/ECC","slug":"git-reset-failed-for-path-stderr","errorCode":null,"errorMessage":"git reset failed for {path}: {stderr}","messagePattern":"git reset failed for (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ecc2/src/worktree/mod.rs","lineNumber":320,"sourceCode":"    } else {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        anyhow::bail!(\"git add failed for {path}: {stderr}\");\n    }\n}\n\npub fn unstage_path(worktree: &WorktreeInfo, path: &str) -> Result<()> {\n    let output = Command::new(\"git\")\n        .arg(\"-C\")\n        .arg(&worktree.path)\n        .args([\"reset\", \"HEAD\", \"--\"])\n        .arg(path)\n        .output()\n        .with_context(|| format!(\"Failed to unstage {}\", path))?;\n    if output.status.success() {\n        Ok(())\n    } else {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        anyhow::bail!(\"git reset failed for {path}: {stderr}\");\n    }\n}\n\npub fn reset_path(worktree: &WorktreeInfo, entry: &GitStatusEntry) -> Result<()> {\n    if entry.untracked {\n        let target = worktree.path.join(&entry.path);\n        if !target.exists() {\n            return Ok(());\n        }\n        let metadata = fs::symlink_metadata(&target)\n            .with_context(|| format!(\"Failed to inspect untracked path {}\", target.display()))?;\n        if metadata.is_dir() {\n            fs::remove_dir_all(&target)\n                .with_context(|| format!(\"Failed to remove {}\", target.display()))?;\n        } else {\n            fs::remove_file(&target)\n                .with_context(|| format!(\"Failed to remove {}\", target.display()))?;\n        }","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/worktree/mod.rs#L302-L338","documentation":"Thrown by unstage_path in ecc2/src/worktree/mod.rs when the underlying `git reset` command used to unstage a file exits with a non-zero status. The library shells out to git, captures stderr, and surfaces it verbatim so the caller can see the git-level cause. It is a wrapper around any git CLI failure during the unstage operation.","triggerScenarios":"Calling unstage_path(worktree, entry) for a path where `git reset -- <path>` fails: path not tracked in HEAD (e.g. resetting an untracked file in a repo with no prior commits), path is outside the repo, pathspec ambiguity, or git repository corruption.","commonSituations":"Trying to unstage a file that was never committed in a brand-new repository with no HEAD; typo'd or non-ASCII path handling; running in a bare repo or a directory that is not a git worktree; permissions issues on .git/index.","solutions":["Read the stderr appended to the message; it contains git's actual diagnostic (e.g. 'fatal: pathspec ... did not match any files').","Check that the repo has at least one commit (HEAD exists) before unstaging files in a fresh repository; use `git rm --cached` semantics otherwise.","Verify the entry path matches a file actually reported by git status and that the working directory is inside the worktree.","Ensure the git index is writable and not locked (check for .git/index.lock leftovers)."],"exampleFix":"// before: unstage blindly\nunstage_path(&worktree, &entry)?;\n\n// after: guard against empty HEAD / untracked file\nif repo_has_head(&worktree) && !entry.untracked {\n    unstage_path(&worktree, &entry)?;\n}","handlingStrategy":"try-catch","validationCode":"fn can_unstage(worktree: &WorktreeInfo, entry: &GitStatusEntry) -> bool {\n    !entry.untracked && std::path::Path::new(&worktree.path).join(\".git\").exists()\n}","typeGuard":"fn is_unstaged_entry(entry: &GitStatusEntry) -> bool { !entry.untracked && entry.unstaged }","tryCatchPattern":"match unstage_path(&worktree, &entry) {\n    Ok(()) => refresh_status(),\n    Err(e) => eprintln!(\"unstage failed: {e:#}\"), // stderr from git included\n}","preventionTips":["Only pass entries taken directly from git status output, never arbitrary paths.","Skip untracked entries — they cannot be unstaged via `git reset` in a repo without HEAD.","Check for a stale .git/index.lock before index operations."],"tags":["git","worktree","command-failed"],"backgroundTag":"git-command-failed","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}