{"record":{"id":"48b3b4530ab2940f","repo":"affaan-m/ECC","slug":"no-staged-changes-to-commit","errorCode":null,"errorMessage":"no staged changes to commit","messagePattern":"no staged changes to commit","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ecc2/src/worktree/mod.rs","lineNumber":461,"sourceCode":"                );\n            }\n            git_apply_patch(\n                &worktree.path,\n                &[\"-R\", \"--index\"],\n                &hunk.patch,\n                \"reset selected staged hunk\",\n            )\n        }\n    }\n}\n\npub fn commit_staged(worktree: &WorktreeInfo, message: &str) -> Result<String> {\n    let message = message.trim();\n    if message.is_empty() {\n        anyhow::bail!(\"commit message cannot be empty\");\n    }\n    if !has_staged_changes(worktree)? {\n        anyhow::bail!(\"no staged changes to commit\");\n    }\n\n    let output = Command::new(\"git\")\n        .arg(\"-C\")\n        .arg(&worktree.path)\n        .args([\"commit\", \"-m\", message])\n        .output()\n        .context(\"Failed to create commit\")?;\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        anyhow::bail!(\"git commit failed: {stderr}\");\n    }\n\n    let rev_parse = Command::new(\"git\")\n        .arg(\"-C\")\n        .arg(&worktree.path)\n        .args([\"rev-parse\", \"--short\", \"HEAD\"])\n        .output()","sourceCodeStart":443,"sourceCodeEnd":479,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/worktree/mod.rs#L443-L479","documentation":"commit_staged checks has_staged_changes before running `git commit` and refuses to proceed when the index matches HEAD, because committing would produce an empty commit. The library surfaces a dedicated error instead of letting git fail with its own 'nothing to commit' message.","triggerScenarios":"Calling commit_staged when nothing has been added to the index: no prior stage_path/stage_hunk calls, all changes previously unstaged or reset, or the worktree is clean.","commonSituations":"User hits commit before staging anything; stale UI state where staged files were unstaged by another process (e.g. a second window or external git command); race where another commit consumed the staged changes.","solutions":["Stage changes first via stage_path or stage_hunk, then commit.","Refresh the status view before committing so the UI reflects the real index state.","Guard the commit action: only enable when the staged section of the status view is non-empty."],"exampleFix":"// before\ncommit_staged(&worktree, msg)?;\n\n// after\nif !has_staged_changes(&worktree)? {\n    // inform user: nothing staged\n    return Ok(String::new());\n}\ncommit_staged(&worktree, msg)?;","handlingStrategy":"validation","validationCode":"if !has_staged_changes(&worktree)? {\n    return Err(anyhow!(\"nothing staged; stage changes before committing\"));\n}","typeGuard":"None","tryCatchPattern":"match commit_staged(&worktree, &msg) {\n    Ok(hash) => println!(\"committed {hash}\"),\n    Err(e) if e.to_string().contains(\"no staged changes\") => {\n        show_info(\"Stage some changes first\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Refresh the status view before offering commit so the UI reflects the true index.","Enable the commit action only when the staged section is non-empty.","Avoid concurrent git tooling on the same worktree that could change index state mid-flow."],"tags":["git","empty-state","precondition"],"backgroundTag":"empty-result-set","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"}