gitbutlerapp/gitbutler · error
Unexpected hunk with neither newlines or oldlines being 0
Error message
Unexpected hunk with neither newlines or oldlines being 0
What it means
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.
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
Defensive patterns
Strategy: type-guard
Validate before calling
if hunk.old_lines != 0 && hunk.new_lines != 0 {
return Err(anyhow!("selection includes modified lines; only additions can be committed additively"));
} Type guard
fn is_pure_insertion(h: &Hunk) -> bool { h.old_lines == 0 && h.new_lines > 0 }
fn is_pure_deletion(h: &Hunk) -> bool { h.new_lines == 0 && h.old_lines > 0 } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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
- Couldn't obtain diff for worktree changes.
- Deletions or additions aren't well-defined for hunk-based…
- Alternative hunks algorithms still didn't produce properly…
- another pre-commit hook is already using the repository…
- askpass broker must be initialized
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/fc27d22626f3a3e2.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-core/src/tree/mod.rs:490
new_start,
new_lines,
}| {
if old_lines == 0 {
Ok(HunkHeader {
old_start: 0,
old_lines: 0,
new_start,
new_lines,
})
} else if new_lines == 0 {
Ok(HunkHeader {
old_start,
old_lines,
new_start: 0,
new_lines: 0,
})
} else {
bail!("Unexpected hunk with neither newlines or oldlines being 0");
}
},
)
.collect::<Result<_, _>>()?;
let (hunks_to_commit, rejected) =
to_additive_hunks_fallback(hunks, worktree_hunks, worktree_hunks_no_context);
if !in_order(&hunks_to_commit) {
bail!(
"Alternative hunks algorithms still didn't produce properly ordered hunks or saw duplicate inputs: {hunks_to_commit:?}"
);
}
(hunks_to_commit, rejected)
} else {
(hunks_to_commit, rejected)
};
Ok(res)
}
View on GitHub (pinned to 58e5313667)