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

builtin add interactive regression

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Dec 9, 2021, 19:36 UTC
Message-ID
<20211209193625.GA3294@szeder.dev>
Hi,

This morning 'git add --patch' told me "Sorry, cannot split this hunk" even though that hunk in question was definitely splittable. Then I spent my lunch break trying to reproduce the issue, and it turned out to be a regression in the builtin add interactive (I have 'add.interactive.useBuiltin=true' in my config). The following test demonstrates this issue:

  ---  >8  ---
#!/bin/sh

test_description='test' . ./test-lib.sh

test_expect_success 'builtin interactive add cannot split hunk?!' '
	printf "%s\n" 1 2 >file &&
	echo a >zzzz &&
	git add file zzzz &&
	git commit -m initial &&
	cat >file <<-\EOF &&
	1
	add a line
	2
	add a line at the end (this is important!)
	EOF
	echo "modify one more file (this, too, is important!)" >zzzz &&
	git diff file &&
	git -c add.interactive.useBuiltin=false add -u -p >expect &&
	git -c add.interactive.useBuiltin=true add -u -p >actual &&
	# Uh-oh, "s" (for splitting the hunk) is missing!
	test_cmp expect actual
'
test_done
  ---  8<  ---
This fails with:
  + git -c add.interactive.useBuiltin=false add -u -p
  + git -c add.interactive.useBuiltin=true add -u -p
  + test_cmp expect actual
  --- expect	2021-12-09 19:21:23.354461170 +0000
  +++ actual	2021-12-09 19:21:23.358461215 +0000
  @@ -7,7 +7,7 @@
   +add a line
    2
   +add a line at the end (this is important!)
  -(1/1) Stage this hunk [y,n,q,a,d,s,e,?]? 
  +(1/1) Stage this hunk [y,n,q,a,d,e,?]? 
   diff --git a/zzzz b/zzzz
   index 7898192..84e1b35 100644
   --- a/zzzz
  error: last command exited with $?=1
  not ok 1 - builtin interactive add cannot split hunk?!

So the builtin add interactive doesn't even offer the 's - split the current hunk into smaller hunks' option, but my finger memory pressed 's' anyway, and then it told me that "Sorry..." message. The scripted version can split the hunk just fine.

Next: Phillip Wood
Message 1 of 3 in “builtin add interactive regression”
  1. SZEDER GáborDec 9, 2021
  2. Phillip WoodDec 10, 2021
  3. Phillip WoodDec 20, 2021

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.