Skip to content

Commit d4704b0

Browse files
jsprickegitster
authored andcommitted
add -p: coalesce hunks before testing applicability
When a hunk was split before being edited manually, it does not apply anymore cleanly. Apply coalesce_overlapping_hunks() first to make it work. Enable test for it as well. Signed-off-by: Jochen Sprickerhof <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fc54c1a commit d4704b0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

git-add--interactive.perl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,10 +1188,10 @@ sub edit_hunk_loop {
11881188
# delta from the original unedited hunk.
11891189
$hunk->{OFS_DELTA} and
11901190
$newhunk->{OFS_DELTA} += $hunk->{OFS_DELTA};
1191-
if (diff_applies($head,
1192-
@{$hunks}[0..$ix-1],
1193-
$newhunk,
1194-
@{$hunks}[$ix+1..$#{$hunks}])) {
1191+
my @hunk = @{$hunks};
1192+
splice (@hunk, $ix, 1, $newhunk);
1193+
@hunk = coalesce_overlapping_hunks(@hunk);
1194+
if (diff_applies($head, @hunk)) {
11951195
$newhunk->{DISPLAY} = [color_diff(@{$newtext})];
11961196
return $newhunk;
11971197
}

t/t3701-add-interactive.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ test_expect_success 'split hunk "add -p (edit)"' '
348348
! grep "^+15" actual
349349
'
350350

351-
test_expect_failure 'split hunk "add -p (no, yes, edit)"' '
351+
test_expect_success 'split hunk "add -p (no, yes, edit)"' '
352352
test_write_lines 5 10 20 21 30 31 40 50 60 >test &&
353353
git reset &&
354354
# test sequence is s(plit), n(o), y(es), e(dit)

0 commit comments

Comments
 (0)