git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] add -p: coalesce hunks before testing applicability

From
JSJochen Sprickerhof <git@jochen.sprickerhof.de>
Date
Aug 28, 2018, 08:58 UTC
Message-ID
<20180828085858.3933-1-git@jochen.sprickerhof.de>

When a hunk was split before being edited manually, it does not apply anymore cleanly. Apply coalesce_overlapping_hunks() first to make it work. Enable test for it as well.

Signed-off-by: Jochen Sprickerhof <git@jochen.sprickerhof.de>
---
 git-add--interactive.perl  | 8 ++++----
 t/t3701-add-interactive.sh | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 36f38ced9..c9f434e4a 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1195,10 +1195,10 @@ sub edit_hunk_loop {
 		# delta from the original unedited hunk.
 		$hunk->{OFS_DELTA} and
 				$newhunk->{OFS_DELTA} += $hunk->{OFS_DELTA};
-		if (diff_applies($head,
-				 @{$hunks}[0..$ix-1],
-				 $newhunk,
-				 @{$hunks}[$ix+1..$#{$hunks}])) {
+		my @hunk = @{$hunks};
+		splice (@hunk, $ix, 1, $newhunk);
+		@hunk = coalesce_overlapping_hunks(@hunk);
+		if (diff_applies($head, @hunk)) {
 			$newhunk->{DISPLAY} = [color_diff(@{$newtext})];
 			return $newhunk;
 		}
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index b170fb02b..b04806ad7 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -348,7 +348,7 @@ test_expect_success 'split hunk "add -p (edit)"' '
 	! grep "^+15" actual
 '
 
-test_expect_failure 'split hunk "add -p (no, yes, edit)"' '
+test_expect_success 'split hunk "add -p (no, yes, edit)"' '
 	test_write_lines 5 10 20 21 30 31 40 50 60 >test &&
 	git reset &&
 	# test sequence is s(plit), n(o), y(es), e(dit)
-- 
2.18.0
Next: Junio C Hamano
Message 1 of 12 in “add -p: coalesce hunks before testing applicability”
  1. add -p: coalesce hunks before testing applicabilityJochen Sprickerhof, Aug 28, 2018
  2. Junio C HamanoAug 28, 2018
  3. Phillip WoodAug 30, 2018
  4. Junio C HamanoAug 30, 2018
  5. Jochen SprickerhofSep 3, 2018
  6. Phillip WoodSep 13, 2018
  7. Jochen SprickerhofSep 23, 2018
  8. Johannes SchindelinMar 22, 2019
  9. Phillip WoodJun 2, 2019
  10. Johannes SchindelinJun 3, 2019
  11. Phillip WoodJun 3, 2019
  12. Johannes SchindelinJun 4, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.