gitbutlerapp/gitbutler · error

in commit , number of sides ( ) is not exactly one more…

Error message

in commit {}, number of sides ({}) is not exactly one more than number of bases ({})

What it means

The TryFrom<&Commit> for a tree-expression type validates that a virtual merge commit's structure is consistent: the number of side trees must be exactly one more than the number of base trees. If base_tree_ids().len() + 1 != side_tree_ids().len(), the commit cannot represent a valid merge expression and parsing bails with the commit id and both counts.

Solutions

  1. Only apply this conversion to commits known to be virtual merge commits with the expected structure
  2. Log the commit id from the message and inspect its parents/trees with git cat-file to diagnose
  3. Skip or handle non-conforming commits before conversion
  4. Re-derive the commit with the tool version that created it

Example fix

// before
let expr = TreeExpression::try_from(&commit)?;
// after
let expr = match TreeExpression::try_from(&commit) {
    Ok(e) => e,
    Err(e) => { eprintln!("skipping non-merge-structured commit: {e}"); continue; }
};
Defensive patterns

Strategy: validation

Validate before calling

fn is_valid_merge_shape(commit: &Commit) -> bool {
    commit.base_tree_ids().map(|b| b.len()).unwrap_or(0) + 1
        == commit.side_tree_ids().map(|s| s.len()).unwrap_or(0)
}

Try / catch

match TreeExpression::try_from(&commit) {
    Ok(e) => e,
    Err(e) => { warn!("bad merge structure: {e}"); continue; }
}

Prevention

When it happens

Trigger: Constructing a TreeExpression from a commit whose octopus/merge structure has an unexpected number of parents' trees — e.g. an ordinary two-parent merge misread, a corrupted commit, or a commit whose base_tree_ids/side_tree_ids derivation returns mismatched sets.

Common situations: Walking history that includes regular merge commits in code expecting virtual-merge commits; repository corruption; mixing commits created by different tool versions with different tree conventions.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at crates/but-core/src/commit/tree_expression.rs:26

/// Sum of sides minus sum of bases. All functions enforce the invariant that
/// the count of sides is exactly one more than the count of bases.
#[derive(Debug, Clone, PartialEq)]
pub struct TreeExpression {
    /// Base tree IDs.
    pub base_tree_ids: Vec<gix::ObjectId>,
    /// Side tree IDs.
    pub side_tree_ids: SmallVec<[gix::ObjectId; 1]>,
}

impl TryFrom<&crate::Commit<'_>> for TreeExpression {
    type Error = anyhow::Error;

    fn try_from(commit: &crate::Commit<'_>) -> Result<Self, Self::Error> {
        let base_tree_ids = commit.base_tree_ids()?;
        let side_tree_ids = commit.side_tree_ids()?;
        if base_tree_ids.len() + 1 != side_tree_ids.len() {
            anyhow::bail!(
                "in commit {}, number of sides ({}) is not exactly one more than number of bases ({})",
                commit.id.to_hex(),
                side_tree_ids.len(),
                base_tree_ids.len()
            );
        }
        Ok(Self {
            base_tree_ids,
            side_tree_ids,
        })
    }
}

impl From<gix::ObjectId> for TreeExpression {
    fn from(side: gix::ObjectId) -> Self {
        Self {
            base_tree_ids: Vec::new(),
            side_tree_ids: smallvec![side],

View on GitHub (pinned to 58e5313667)