{"record":{"id":"fc27d22626f3a3e2","repo":"gitbutlerapp/gitbutler","slug":"unexpected-hunk-with-neither-newlines-or-oldlines","errorCode":null,"errorMessage":"Unexpected hunk with neither newlines or oldlines being 0","messagePattern":"Unexpected hunk with neither newlines or oldlines being 0","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-core/src/tree/mod.rs","lineNumber":490,"sourceCode":"                     new_start,\n                     new_lines,\n                 }| {\n                    if old_lines == 0 {\n                        Ok(HunkHeader {\n                            old_start: 0,\n                            old_lines: 0,\n                            new_start,\n                            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","sourceCodeStart":472,"sourceCodeEnd":508,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-core/src/tree/mod.rs#L472-L508","documentation":"to_additive_hunks converts diff hunks into additive hunks (pure additions). A hunk must be either an insertion (old_lines == 0) or a deletion (new_lines == 0); a hunk with both old and new lines nonzero (a modification) or with zero lines on both sides cannot be classified, so it bails.","triggerScenarios":"Calling to_additive_hunks (from apply_worktree_changes) with a diff hunk that has both old_start/old_lines and new_start/new_lines set, or a hunk with neither — i.e. a non-additive (modified) hunk reaching the additive-only path.","commonSituations":"Committing only selected lines when the selection includes modified (not just added) lines; diff-parsing upstream producing hunks the classifier does not expect; empty/context-only hunks slipping through.","solutions":["Route modified (both old and new lines nonzero) hunks through the normal hunk application path instead of the additive one","Fall back to to_additive_hunks_fallback semantics or reject the selection with a user-facing message that only added lines can be committed additively","Verify the upstream diff generation so zero-line hunks are filtered before conversion"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"if hunk.old_lines != 0 && hunk.new_lines != 0 {\n    return Err(anyhow!(\"selection includes modified lines; only additions can be committed additively\"));\n}","typeGuard":"fn is_pure_insertion(h: &Hunk) -> bool { h.old_lines == 0 && h.new_lines > 0 }\nfn is_pure_deletion(h: &Hunk) -> bool { h.new_lines == 0 && h.old_lines > 0 }","tryCatchPattern":null,"preventionTips":["Filter zero-line and context-only hunks before additive conversion","Send modification hunks to the standard apply path, not the additive one","Add unit tests covering insertion/deletion/modification hunk shapes"],"tags":["rust","git","diff","hunks"],"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"}