{"record":{"id":"33a8d31a1bdc21fb","repo":"gitbutlerapp/gitbutler","slug":"alternative-hunks-algorithms-still-didn-t-produce","errorCode":null,"errorMessage":"Alternative hunks algorithms still didn't produce properly ordered hunks or saw duplicate inputs: {hunks_to_commit:?}","messagePattern":"Alternative hunks algorithms still didn't produce properly ordered hunks or saw duplicate inputs: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/but-core/src/tree/mod.rs","lineNumber":479,"sourceCode":"                            new_lines,\n                        })\n                    } else if new_lines == 0 {\n                        Ok(HunkHeader {\n                            old_start,\n                            old_lines,\n                            new_start: 0,\n                            new_lines: 0,\n                        })\n                    } else {\n                        bail!(\"Unexpected hunk with neither newlines or oldlines being 0\");\n                    }\n                },\n            )\n            .collect::<Result<_, _>>()?;\n        let (hunks_to_commit, rejected) =\n            to_additive_hunks_fallback(hunks, worktree_hunks, worktree_hunks_no_context);\n        if !in_order(&hunks_to_commit) {\n            bail!(\n                \"Alternative hunks algorithms still didn't produce properly ordered hunks or saw duplicate inputs: {hunks_to_commit:?}\"\n            );\n        }\n        (hunks_to_commit, rejected)\n    } else {\n        (hunks_to_commit, rejected)\n    };\n    Ok(res)\n}\n\n/// This algorithm is better when the basic one fails, but both have their merit.\n/// Right now this is a brute-force one or the other approach, but we could also apply them selectively.\n/// Note that what we really want to simulate is what the UI shows. But since the UI also doesn't really know hunks,\n/// we have to fiddle it together here, at least we know the hunks themselves.\n///\n/// Note that this algorithm is kind of the opposite of what people would expect if it's run where `to_additive_hunks()` works.\n/// But here we are… just making this work.\n#[expect(clippy::indexing_slicing)]","sourceCodeStart":461,"sourceCodeEnd":497,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but-core/src/tree/mod.rs#L461-L497","documentation":"After the primary hunk algorithm produced out-of-order results, GitButler re-normalizes each hunk and reruns `to_additive_hunks_fallback`, then re-checks ordering with `in_order()`. If the fallback's output is still not strictly increasing (or it saw duplicate inputs), this bail fires with the offending hunk list. It marks an internal limitation of the hunk-to-commit translation, not user misconfiguration.","triggerScenarios":"Hunk selections whose worktree diff context disagrees with the selection diff (file changed between computing the two), or pathological interleaved selections where both ordering heuristics fail.","commonSituations":"Files being edited concurrently while the user selects hunks in the UI; very large files with many adjacent small hunks; line-ending changes mixed with content changes.","solutions":["Retry the operation after the worktree is quiescent (no concurrent editor/formatter writing the file).","Commit the file in full instead of hunk-by-hunk.","Update GitButler; attach the `tracing` log line ('Using alternative hunk algorithm…') and the hunk list from the error to a bug report."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"match compute_hunks_to_commit(...) {\n    Ok(hunks) => hunks,\n    Err(err) if err.to_string().contains(\"Alternative hunks algorithms\") => {\n        // internal algorithm limitation: degrade gracefully to file-level commit\n        tracing::warn!(\"{err:#}\");\n        commit_whole_file(path)?;\n        Vec::new()\n    }\n    Err(err) => return Err(err),\n}","preventionTips":["Recompute diffs immediately before committing so worktree and selection diffs agree.","Avoid mixing line-ending rewrites with content edits in the same hunk-selection round.","Attach the printed hunk list to a bug report — this error exists to expose algorithm gaps."],"tags":["diff","hunks","internal-algorithm","bug-report"],"backgroundTag":"diff-hunk-processing","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}