{"record":{"id":"a4da82dc5c21c93e","repo":"affaan-m/ECC","slug":"base-branch-is-not-checked-out-in-repo-root-cu","errorCode":null,"errorMessage":"Base branch {} is not checked out in repo root (currently {})","messagePattern":"Base branch (.+?) is not checked out in repo root \\(currently (.+?)\\)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"ecc2/src/worktree/mod.rs","lineNumber":874,"sourceCode":"}\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\",\n            repo_root.display()\n        );\n    }\n\n    let output = Command::new(\"git\")\n        .arg(\"-C\")\n        .arg(&repo_root)\n        .args([\"merge\", \"--no-edit\", &worktree.branch])\n        .output()","sourceCodeStart":856,"sourceCodeEnd":892,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/worktree/mod.rs#L856-L892","documentation":"merge_into_base merges the worktree branch into its base branch, which must be checked out in the repository root worktree. When the root's current branch differs from worktree.base_branch, the library bails rather than merging into a non-checked-out (or wrong) branch.","triggerScenarios":"Calling merge_into_base when the repo root has a different branch checked out than the worktree's declared base — e.g. someone switched the root to another feature branch, or the base branch field is stale after a retarget.","commonSituations":"User ran `git checkout other-branch` in the root directory earlier; base branch renamed; automation expects the root always on main but a previous operation left it elsewhere.","solutions":["Check out the base branch in the repo root: `git -C <root> checkout <base_branch>`.","Verify with `git -C <root> branch --show-current` before retrying.","If the root worktree is blocked (e.g. another worktree already holds the base), find and adjust which worktree checks out the base.","Ensure worktree.base_branch is correct if the branch was retargeted."],"exampleFix":"// before\nmerge_into_base(&wt)?; // fails: root on wrong branch\n// after\nlet root = base_checkout_path(&wt)?;\nCommand::new(\"git\").arg(\"-C\").arg(&root).args([\"checkout\", &wt.base_branch]).status()?;\nmerge_into_base(&wt)?;","handlingStrategy":"validation","validationCode":"let root = base_checkout_path(&wt)?;\nlet cur = String::from_utf8(Command::new(\"git\").arg(&root).args([\"branch\",\"--show-current\"]).output()?.stdout)?.trim().to_string();\nif cur != wt.base_branch {\n    Command::new(\"git\").arg(&root).arg(\"checkout\").arg(&wt.base_branch).status()?;\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = merge_into_base(&wt) {\n    if e.to_string().contains(\"not checked out\") {\n        // check out the base branch in root, then retry\n    } else { return Err(e); }\n}","preventionTips":["Keep the repo root checked out on the base branch by convention","Verify current branch before automated merges","Avoid manual checkouts in the root; use worktrees for side work"],"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"}