Skip to content

Commit ca49756

Browse files
committed
apply --allow-overlap: fix a corner case
Yes, yes, this is supposed to be only a band-aid option for `git add -p` not Doing The Right Thing. But as long as we carry the `--allow-overlap` option, we might just as well get it right. This fixes the case where one hunk inserts a line before the first one, and a hunk whose context overlaps with the first one's appends a line at the end. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 988f9e8 commit ca49756

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

apply.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2680,6 +2680,16 @@ static int find_pos(struct apply_state *state,
26802680
unsigned long backwards, forwards, current;
26812681
int backwards_lno, forwards_lno, current_lno;
26822682

2683+
/*
2684+
* When running with --allow-overlap, it is possible that a hunk is
2685+
* seen that pretends to start at the beginning (but no longer does),
2686+
* and that *still* needs to match the end. So trust `match_end` more
2687+
* than `match_beginning`.
2688+
*/
2689+
if (state->allow_overlap && match_beginning && match_end &&
2690+
img->nr - preimage->nr != 0)
2691+
match_beginning = 0;
2692+
26832693
/*
26842694
* If match_beginning or match_end is specified, there is no
26852695
* point starting from a wrong line that will never match and

0 commit comments

Comments
 (0)