path: root/git-add--interactive.perl
diff options
authorPhillip Wood <>2019-06-12 09:25:27 (GMT)
committerJunio C Hamano <>2019-06-13 17:00:30 (GMT)
commit2bd69b9024c8c7c1b77060e3ed996c74b4775b01 (patch)
tree7934b95217df177127b0167fd5912530403bfa0f /git-add--interactive.perl
parentf4d35a6b49621348c73222e7017a434551799308 (diff)
add -p: fix checkout -p with pathological context
Commit fecc6f3a68 ("add -p: adjust offsets of subsequent hunks when one is skipped", 2018-03-01) fixed adding hunks in the correct place when a previous hunk has been skipped. However it did not address patches that are applied in reverse. In that case we need to adjust the pre-image offset so that when apply reverses the patch the post-image offset is adjusted correctly. We subtract rather than add the delta as the patch is reversed (the easiest way to think about it is to consider a hunk of deletions that is skipped - in that case we want to reduce offset so we need to subtract). Signed-off-by: Phillip Wood <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'git-add--interactive.perl')
1 files changed, 5 insertions, 1 deletions
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 8361ef4..85d0dc1 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -957,7 +957,11 @@ sub coalesce_overlapping_hunks {
if ($ofs_delta) {
- $n_ofs += $ofs_delta;
+ if ($patch_mode_flavour{IS_REVERSE}) {
+ $o_ofs -= $ofs_delta;
+ } else {
+ $n_ofs += $ofs_delta;
+ }
$_->{TEXT}->[0] = format_hunk_header($o_ofs, $o_cnt,
$n_ofs, $n_cnt);