{"record":{"id":"df802947edc7c492","repo":"gitbutlerapp/gitbutler","slug":"in-commit-number-of-sides-is-not-exactly","errorCode":null,"errorMessage":"in commit {}, number of sides ({}) is not exactly one more than number of bases ({})","messagePattern":"in commit (.+?), number of sides \\((.+?)\\) is not exactly one more than number of bases \\((.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-core/src/commit/tree_expression.rs","lineNumber":26,"sourceCode":"\n/// Sum of sides minus sum of bases. All functions enforce the invariant that\n/// the count of sides is exactly one more than the count of bases.\n#[derive(Debug, Clone, PartialEq)]\npub struct TreeExpression {\n    /// Base tree IDs.\n    pub base_tree_ids: Vec<gix::ObjectId>,\n    /// Side tree IDs.\n    pub side_tree_ids: SmallVec<[gix::ObjectId; 1]>,\n}\n\nimpl TryFrom<&crate::Commit<'_>> for TreeExpression {\n    type Error = anyhow::Error;\n\n    fn try_from(commit: &crate::Commit<'_>) -> Result<Self, Self::Error> {\n        let base_tree_ids = commit.base_tree_ids()?;\n        let side_tree_ids = commit.side_tree_ids()?;\n        if base_tree_ids.len() + 1 != side_tree_ids.len() {\n            anyhow::bail!(\n                \"in commit {}, number of sides ({}) is not exactly one more than number of bases ({})\",\n                commit.id.to_hex(),\n                side_tree_ids.len(),\n                base_tree_ids.len()\n            );\n        }\n        Ok(Self {\n            base_tree_ids,\n            side_tree_ids,\n        })\n    }\n}\n\nimpl From<gix::ObjectId> for TreeExpression {\n    fn from(side: gix::ObjectId) -> Self {\n        Self {\n            base_tree_ids: Vec::new(),\n            side_tree_ids: smallvec![side],","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-core/src/commit/tree_expression.rs#L8-L44","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Only apply this conversion to commits known to be virtual merge commits with the expected structure","Log the commit id from the message and inspect its parents/trees with git cat-file to diagnose","Skip or handle non-conforming commits before conversion","Re-derive the commit with the tool version that created it"],"exampleFix":"// before\nlet expr = TreeExpression::try_from(&commit)?;\n// after\nlet expr = match TreeExpression::try_from(&commit) {\n    Ok(e) => e,\n    Err(e) => { eprintln!(\"skipping non-merge-structured commit: {e}\"); continue; }\n};","handlingStrategy":"validation","validationCode":"fn is_valid_merge_shape(commit: &Commit) -> bool {\n    commit.base_tree_ids().map(|b| b.len()).unwrap_or(0) + 1\n        == commit.side_tree_ids().map(|s| s.len()).unwrap_or(0)\n}","typeGuard":null,"tryCatchPattern":"match TreeExpression::try_from(&commit) {\n    Ok(e) => e,\n    Err(e) => { warn!(\"bad merge structure: {e}\"); continue; }\n}","preventionTips":["Only convert commits known to be virtual merge commits","Validate parent counts before conversion","Record tool version with commits that use special tree layouts","Handle the error per-commit rather than failing whole history walks"],"tags":["git","merge","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}