Skip to content

Commit f26fc54

Browse files
committed
Merge branch 'pw/add-p-recount' into jch
"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
2 parents 8406830 + 2bd69b9 commit f26fc54

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

git-add--interactive.perl

+5-1
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,11 @@ sub coalesce_overlapping_hunks {
972972
next;
973973
}
974974
if ($ofs_delta) {
975-
$n_ofs += $ofs_delta;
975+
if ($patch_mode_flavour{IS_REVERSE}) {
976+
$o_ofs -= $ofs_delta;
977+
} else {
978+
$n_ofs += $ofs_delta;
979+
}
976980
$_->{TEXT}->[0] = format_hunk_header($o_ofs, $o_cnt,
977981
$n_ofs, $n_cnt);
978982
}

t/t3701-add-interactive.sh

+8
Original file line numberDiff line numberDiff line change
@@ -639,4 +639,12 @@ test_expect_success 'add -p patch editing works with pathological context lines'
639639
test_cmp expected-2 actual
640640
'
641641

642+
test_expect_success 'checkout -p works with pathological context lines' '
643+
test_write_lines a a a a a a >a &&
644+
git add a &&
645+
test_write_lines a b a b a b a b a b a > a&&
646+
test_write_lines s n n y q | git checkout -p &&
647+
test_write_lines a b a b a a b a b a >expect &&
648+
test_cmp expect a
649+
'
642650
test_done

0 commit comments

Comments
 (0)