1
0
mirror of https://github.com/git/git.git synced 2024-09-16 21:01:42 +02:00

Merge branch 'jk/add-patch-with-suppress-blank-empty' into next

When the diff.suppressBlankEmpty configuration variable is set,
"git add -p" failed to process a patch with an unmodified empty
line, which has been corrected.

* jk/add-patch-with-suppress-blank-empty:
  add-patch: handle splitting hunks with diff.suppressBlankEmpty
This commit is contained in:
Junio C Hamano 2024-07-11 13:55:02 -07:00
commit cec8ebb668
2 changed files with 36 additions and 4 deletions

View File

@ -588,7 +588,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
(int)(eol - (plain->buf + file_diff->head.start)),
plain->buf + file_diff->head.start);
if ((marker == '-' || marker == '+') && *p == ' ')
if ((marker == '-' || marker == '+') && (*p == ' ' || *p == '\n'))
hunk->splittable_into++;
if (marker && *p != '\\')
marker = *p;
@ -964,7 +964,7 @@ static int split_hunk(struct add_p_state *s, struct file_diff *file_diff,
* Is this the first context line after a chain of +/- lines?
* Then record the start of the next split hunk.
*/
if ((marker == '-' || marker == '+') && ch == ' ') {
if ((marker == '-' || marker == '+') && (ch == ' ' || ch == '\n')) {
first = 0;
hunk[1].start = current;
if (colored)
@ -979,14 +979,14 @@ static int split_hunk(struct add_p_state *s, struct file_diff *file_diff,
* Then just increment the appropriate counter and continue
* with the next line.
*/
if (marker != ' ' || (ch != '-' && ch != '+')) {
if ((marker != ' ' && marker != '\n') || (ch != '-' && ch != '+')) {
next_hunk_line:
/* Comment lines are attached to the previous line */
if (ch == '\\')
ch = marker ? marker : ' ';
/* current hunk not done yet */
if (ch == ' ')
if (ch == ' ' || ch == '\n')
context_line_count++;
else if (ch == '-')
header->old_count++;

View File

@ -1164,4 +1164,36 @@ test_expect_success 'reset -p with unmerged files' '
test_must_be_empty staged
'
test_expect_success 'splitting handles diff.suppressBlankEmpty' '
test_when_finished "git reset --hard" &&
cat >file <<-\EOF &&
1
2
3
4
EOF
git add file &&
cat >file <<-\EOF &&
one
two
three
four
EOF
test_write_lines s n y |
git -c diff.suppressBlankEmpty=true add -p &&
git cat-file blob :file >actual &&
cat >expect <<-\EOF &&
1
2
three
four
EOF
test_cmp expect actual
'
test_done