gitbutlerapp/gitbutler · error

Squash step must have at least two commits

Error message

Squash step must have at least two commits

What it means

prepare_squash_step_for_editor only supports squashing two or more commits; a squash step with fewer than two commit IDs is rejected before any editor selectors are built. A single commit has nothing to squash into, so the operation is meaningless.

Solutions

  1. Ensure the squash step contains at least two commit IDs before building it, or downgrade a single commit to a plain pick step
  2. Filter out squash steps with <2 commits during plan preparation
  3. If the intent was to reword a single commit, use the commit/pick path instead of squash

Example fix

// before
steps.push(Step::Squash(vec![commit_id]));
// after
if commits.len() >= 2 {
    steps.push(Step::Squash(commits));
} else {
    steps.push(Step::Pick(commits[0]));
}
Defensive patterns

Strategy: validation

Validate before calling

fn can_squash(commit_ids: &[gix::ObjectId]) -> bool {
    commit_ids.len() >= 2
}

Try / catch

match result {
    Err(e) if e.to_string().contains("Squash step must have at least two commits") => {
        // fall back to a plain pick of the single commit
        pick_single_commit(commit_ids[0])?;
        Ok(())
    }
    other => other,
}

Prevention

When it happens

Trigger: Constructing a PreparedIntegrationStep::Pick/squash step whose commit_ids slice has 0 or 1 entries and passing it through prepare_squash_step_for_editor.

Common situations: Upstream integration logic collapsing a branch that resolved to a single commit, or plan construction filtering commits down to one and still emitting a squash step.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/6dd9fbacbf04327b. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-workspace/src/branch/integrate_branch_upstream/plan.rs:257

            bail_precondition!(
                "Integration plan is invalid: prepared commit {commit_id} appears more than once"
            );
        }
        prepared.push(step);
    }

    Ok(prepared)
}

/// Precompute the squash payload from the current editor/repository state,
/// before later integration graph mutations can rewire step-graph ancestry.
fn prepare_squash_step_for_editor<M: RefMetadata>(
    editor: &Editor<'_, '_, M>,
    commit_ids: &[gix::ObjectId],
    message: Option<&str>,
) -> Result<gix::ObjectId> {
    if commit_ids.len() < 2 {
        bail!("Squash step must have at least two commits");
    }

    let maybe_selectors = commit_ids
        .iter()
        .map(|commit_id| editor.try_select_commit(*commit_id))
        .collect::<Vec<_>>();
    let ordered_commit_ids = if maybe_selectors.iter().all(Option::is_some) {
        let ordered_selectors = editor.order_commit_selectors_by_parentage(
            maybe_selectors
                .into_iter()
                .map(|selector| selector.expect("checked all selectors are present"))
                .collect::<Vec<_>>(),
        )?;
        ordered_selectors
            .iter()
            .map(|selector| {
                editor
                    .find_selectable_commit(*selector)

View on GitHub (pinned to 58e5313667)