{"record":{"id":"cbe750a9421ab6a3","repo":"affaan-m/ECC","slug":"worktree-has-uncommitted-changes-commit-or-dis","errorCode":null,"errorMessage":"Worktree {} has uncommitted changes; commit or discard them before merging","messagePattern":"Worktree (.+?) has uncommitted changes; commit or discard them before merging","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"ecc2/src/worktree/mod.rs","lineNumber":865,"sourceCode":"\npub fn has_uncommitted_changes(worktree: &WorktreeInfo) -> Result<bool> {\n    Ok(!git_status_short(&worktree.path)?.is_empty())\n}\n\npub fn has_staged_changes(worktree: &WorktreeInfo) -> Result<bool> {\n    Ok(git_status_entries(worktree)?\n        .iter()\n        .any(|entry| entry.staged))\n}\n\npub fn merge_into_base(worktree: &WorktreeInfo) -> Result<MergeOutcome> {\n    let readiness = merge_readiness(worktree)?;\n    if readiness.status == MergeReadinessStatus::Conflicted {\n        anyhow::bail!(readiness.summary);\n    }\n\n    if has_uncommitted_changes(worktree)? {\n        anyhow::bail!(\n            \"Worktree {} has uncommitted changes; commit or discard them before merging\",\n            worktree.branch\n        );\n    }\n\n    let repo_root = base_checkout_path(worktree)?;\n    let current_branch = get_current_branch(&repo_root)?;\n    if current_branch != worktree.base_branch {\n        anyhow::bail!(\n            \"Base branch {} is not checked out in repo root (currently {})\",\n            worktree.base_branch,\n            current_branch\n        );\n    }\n\n    if !git_status_short(&repo_root)?.is_empty() {\n        anyhow::bail!(\n            \"Repository root {} has uncommitted changes; commit or stash them before merging\",","sourceCodeStart":847,"sourceCodeEnd":883,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/worktree/mod.rs#L847-L883","documentation":"merge_into_base refuses to run when the worktree has uncommitted changes (detected via has_uncommitted_changes). Merging with a dirty tree could lose or mix uncommitted work, so the library requires a clean worktree first.","triggerScenarios":"Calling merge_into_base while the worktree has modified, staged, or untracked-but-tracked-index changes — e.g. edits made after the last commit in that worktree.","commonSituations":"Developer left WIP edits in the worktree; an editor or formatter auto-modified files; tests wrote artifacts into the worktree directory.","solutions":["Commit the pending changes in the worktree: `git -C <path> add -A && git commit`.","Or stash them: `git -C <path> stash` and retry the merge.","Discard unwanted changes with `git -C <path> restore .` if they are not needed.","Run has_uncommitted_changes / git status in your own code before calling merge_into_base to fail earlier with a better UX.","Add generated artifacts (build outputs) to .gitignore so tooling writes don't dirty the tree."],"exampleFix":"// before\nmerge_into_base(&wt)?; // fails: dirty worktree\n// after\nCommand::new(\"git\").arg(\"-C\").arg(&wt.path).args([\"add\",\"-A\"]).status()?;\nCommand::new(\"git\").arg(\"-C\").arg(&wt.path).args([\"commit\",\"-m\",\"wip\"]).status()?;\nmerge_into_base(&wt)?;","handlingStrategy":"validation","validationCode":"if has_uncommitted_changes(&wt)? {\n    eprintln!(\"commit or stash changes in {} first\", wt.branch);\n    return Ok(());\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = merge_into_base(&wt) {\n    if e.to_string().contains(\"uncommitted changes\") {\n        // prompt user to commit/stash, then retry\n    } else { return Err(e); }\n}","preventionTips":["Commit or stash before switching tasks in a worktree","Add generated artifacts to .gitignore","Run has_uncommitted_changes as a precheck","Automate auto-commit or stash in scripts that drive merges"],"tags":["git","worktree","precondition"],"backgroundTag":"invalid-state-transition","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"}