summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-07-09 22:25:37 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-07-09 22:25:37 (GMT)
commit1b074e15d0f976be2bc14f9528874a841c055213 (patch)
treea71a012782c2c47ec352f6ab64423a8a91a7f5b4
parent5cb7c73589059b557f0d690ed6bcfde46ef2d234 (diff)
parent2bd69b9024c8c7c1b77060e3ed996c74b4775b01 (diff)
downloadgit-1b074e15d0f976be2bc14f9528874a841c055213.zip
git-1b074e15d0f976be2bc14f9528874a841c055213.tar.gz
git-1b074e15d0f976be2bc14f9528874a841c055213.tar.bz2
Merge branch 'pw/add-p-recount'
"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
-rwxr-xr-xgit-add--interactive.perl6
-rwxr-xr-xt/t3701-add-interactive.sh8
2 files changed, 13 insertions, 1 deletions
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 20eb81c..da5b4ec 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -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);
}
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index 65dfbc0..69991a3 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -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