affaan-m/ECC · error · anyhow::Error

Base branch is not checked out in repo root (currently )

Error message

Base branch {} is not checked out in repo root (currently {})

What it means

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.

Solutions

  1. Check out the base branch in the repo root: `git -C <root> checkout <base_branch>`.
  2. Verify with `git -C <root> branch --show-current` before retrying.
  3. If the root worktree is blocked (e.g. another worktree already holds the base), find and adjust which worktree checks out the base.
  4. Ensure worktree.base_branch is correct if the branch was retargeted.

Example fix

// before
merge_into_base(&wt)?; // fails: root on wrong branch
// after
let root = base_checkout_path(&wt)?;
Command::new("git").arg("-C").arg(&root).args(["checkout", &wt.base_branch]).status()?;
merge_into_base(&wt)?;
Defensive patterns

Strategy: validation

Validate before calling

let root = base_checkout_path(&wt)?;
let cur = String::from_utf8(Command::new("git").arg(&root).args(["branch","--show-current"]).output()?.stdout)?.trim().to_string();
if cur != wt.base_branch {
    Command::new("git").arg(&root).arg("checkout").arg(&wt.base_branch).status()?;
}

Try / catch

if let Err(e) = merge_into_base(&wt) {
    if e.to_string().contains("not checked out") {
        // check out the base branch in root, then retry
    } else { return Err(e); }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/a4da82dc5c21c93e. Report an issue: GitHub.

Appendix: source

Thrown at ecc2/src/worktree/mod.rs:874

}

pub fn merge_into_base(worktree: &WorktreeInfo) -> Result<MergeOutcome> {
    let readiness = merge_readiness(worktree)?;
    if readiness.status == MergeReadinessStatus::Conflicted {
        anyhow::bail!(readiness.summary);
    }

    if has_uncommitted_changes(worktree)? {
        anyhow::bail!(
            "Worktree {} has uncommitted changes; commit or discard them before merging",
            worktree.branch
        );
    }

    let repo_root = base_checkout_path(worktree)?;
    let current_branch = get_current_branch(&repo_root)?;
    if current_branch != worktree.base_branch {
        anyhow::bail!(
            "Base branch {} is not checked out in repo root (currently {})",
            worktree.base_branch,
            current_branch
        );
    }

    if !git_status_short(&repo_root)?.is_empty() {
        anyhow::bail!(
            "Repository root {} has uncommitted changes; commit or stash them before merging",
            repo_root.display()
        );
    }

    let output = Command::new("git")
        .arg("-C")
        .arg(&repo_root)
        .args(["merge", "--no-edit", &worktree.branch])
        .output()

View on GitHub (pinned to 8321021c54)