{"record":{"id":"a6091ab4ebc802f8","repo":"affaan-m/ECC","slug":"git-restore-failed-for-stderr","errorCode":null,"errorMessage":"git restore failed for {}: {stderr}","messagePattern":"git restore failed for (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ecc2/src/worktree/mod.rs","lineNumber":353,"sourceCode":"        } else {\n            fs::remove_file(&target)\n                .with_context(|| format!(\"Failed to remove {}\", target.display()))?;\n        }\n        return Ok(());\n    }\n\n    let output = Command::new(\"git\")\n        .arg(\"-C\")\n        .arg(&worktree.path)\n        .args([\"restore\", \"--source=HEAD\", \"--staged\", \"--worktree\", \"--\"])\n        .arg(&entry.path)\n        .output()\n        .with_context(|| format!(\"Failed to reset {}\", entry.path))?;\n    if output.status.success() {\n        Ok(())\n    } else {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        anyhow::bail!(\"git restore failed for {}: {stderr}\", entry.path);\n    }\n}\n\npub fn git_status_patch_view(\n    worktree: &WorktreeInfo,\n    entry: &GitStatusEntry,\n) -> Result<Option<GitStatusPatchView>> {\n    if entry.untracked {\n        return Ok(None);\n    }\n\n    let staged_patch =\n        git_diff_patch_text_for_paths(&worktree.path, &[\"--cached\"], &[entry.path.clone()])?;\n    let unstaged_patch = git_diff_patch_text_for_paths(&worktree.path, &[], &[entry.path.clone()])?;\n\n    let mut sections = Vec::new();\n    let mut hunks = Vec::new();\n","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/worktree/mod.rs#L335-L371","documentation":"Thrown by reset_path when `git restore` used to discard unstaged changes for a status entry exits non-zero. The function wraps the git CLI and forwards its stderr in the message. It signals that discarding the file's working-tree changes failed at the git level.","triggerScenarios":"Calling reset_path(worktree, entry) when `git restore -- <path>` fails: file is untracked (restore only works on tracked files), path no longer exists, checkout conflicts with sparse-checkout settings, or the repo lacks a HEAD.","commonSituations":"Discarding changes on an untracked file (should be deleted instead of restored); file deleted from disk but still in the index; running inside a shallow or empty clone where HEAD is unborn; sparse-checkout entries excluded from the cone.","solutions":["Inspect the stderr in the message for git's specific failure reason.","Skip reset_path for untracked entries (entry.untracked == true); delete the file or use remove_path semantics instead.","Confirm the file still exists and is tracked: `git ls-files --error-unmatch <path>` before restoring.","Check sparse-checkout configuration if stderr mentions excluded paths."],"exampleFix":"// before: reset regardless of state\nreset_path(&worktree, &entry)?;\n\n// after: only reset tracked files\nif !entry.untracked {\n    reset_path(&worktree, &entry)?;\n}","handlingStrategy":"validation","validationCode":"fn can_reset(worktree: &WorktreeInfo, entry: &GitStatusEntry) -> bool {\n    !entry.untracked\n        && worktree.path.join(&entry.path).exists()\n        && worktree.path.join(\".git\").exists()\n}","typeGuard":"fn is_tracked_modified(entry: &GitStatusEntry) -> bool { !entry.untracked && entry.unstaged }","tryCatchPattern":"match reset_path(&worktree, &entry) {\n    Ok(()) => refresh_status(),\n    Err(e) => show_dialog(\"Discard failed\", &format!(\"{e:#}\")),\n}","preventionTips":["Guard on entry.untracked: untracked files must be deleted, not restored.","Confirm the path still exists on disk before discarding.","Refresh status entries right before destructive operations to avoid stale data."],"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"}