Merge branch 'pw/add-p-recount' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 29 Jul 2019 19:38:22 +0000 (12:38 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 29 Jul 2019 19:38:22 +0000 (12:38 -0700)
"git checkout -p" needs to selectively apply a patch in reverse,
which did not work well.

* pw/add-p-recount:
add -p: fix checkout -p with pathological context

git-add--interactive.perl
t/t3701-add-interactive.sh
index 20eb81cc92f947d872b31a179d43d97772ff25e4..da5b4ec4bc50e4e3adaba0f25820262b6a7436a0 100755 (executable)
@@ -972,7 +972,11 @@ sub coalesce_overlapping_hunks {
                        next;
                }
                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);
                }
index 65dfbc033a027df1a590cbfaf75ae47f4ed9c547..69991a3168f354b8bfefcd396a968e653bb352bd 100755 (executable)
@@ -639,4 +639,12 @@ test_expect_success 'add -p patch editing works with pathological context lines'
        test_cmp expected-2 actual
 '
 
+test_expect_success 'checkout -p works with pathological context lines' '
+       test_write_lines a a a a a a >a &&
+       git add a &&
+       test_write_lines a b a b a b a b a b a > a&&
+       test_write_lines s n n y q | git checkout -p &&
+       test_write_lines a b a b a a b a b a >expect &&
+       test_cmp expect a
+'
 test_done