However, git won't split the hunk any further, a
And that is an issue as well when you use the config diff.suppressBlankEmpty (A boolean to inhibit the standard behavior of printing a space before each empty output line. Defaults to false. Introduced in Git v1.6.1-rc1, Q3 2008, initially as diff.suppress-blank-empty):
"git add -p"(man) by users with diff.suppressBlankEmpty set to true failed to parse the patch that represents an unmodified empty line with an empty line (not a line with a single space on it), which has been corrected with Git 2.47 (Q4 2024), batch 1.
See commit 60cf761, commit 39bdd84 (20 Jul 2024) by Phillip Wood (phillipwood).
(Merged by Junio C Hamano -- gitster -- in commit d71121c, 31 Jul 2024)
add-patch: handle splitting hunks with diff.suppressBlankEmpty
Reported-by: Ilya Tumaykin
Helped-by: Jeff King
Signed-off-by: Phillip Wood
When "add -p" parses diffs, it looks for context lines starting with a single space.
But when diff.suppressBlankEmpty is in effect, an empty context line will omit the space, giving us a true empty line.
This confuses the parser, which is unable to split based on such a line.
It's tempting to say that we should just make sure that we generate a diff without that option.
However, although we do not parse hunks that the user has manually edited with parse_diff() we do allow the user to split such hunks.
As POSIX calls the decision of whether to print the space here "implementation-defined" we need to handle edited hunks where empty context lines omit the space.
So let's handle both cases: a context line either starts with a space or consists of a totally empty line by normalizing the first character to a space when we parse them.
Normalizing the first character rather than changing the code to check for a space or newline will hopefully future proof against introducing similar bugs if the code is changed.
While this is considered as a bug now fixed, check if a git -c diff.suppressBlankEmpty=true add -p would not increase the granularity in your case, with a Git older than 2.47.