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

[PATCH 1/7] t3701: add a test for advanced split-hunk editing

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Dec 6, 2019, 13:08 UTC
Message-ID
<acfa1614afe1dfdf4bd63057824b3f033691c41d.1575637705.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.172.git.1575637705.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

In this developer's workflows, it often happens that a hunk needs to be edited in a way that adds lines, and sometimes even reduces the number of context lines.

Let's add a regression test for this.

Note that just like the preceding test case, the new test case is *not* handled gracefully by the current `git add -p`. It will be handled correctly by the upcoming built-in `git add -p`, though.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 t/t3701-add-interactive.sh | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index d4f9386621..4da99e27af 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -403,6 +403,28 @@ test_expect_failure 'split hunk "add -p (no, yes, edit)"' '
 	! grep "^+31" actual
 '
 
+test_expect_failure 'edit, adding lines to the first hunk' '
+	test_write_lines 10 11 20 30 40 50 51 60 >test &&
+	git reset &&
+	tr _ " " >patch <<-EOF &&
+	@@ -1,5 +1,6 @@
+	_10
+	+11
+	+12
+	_20
+	+21
+	+22
+	_30
+	EOF
+	# test sequence is s(plit), e(dit), n(o)
+	# q n q q is there to make sure we exit at the end.
+	printf "%s\n" s e n   q n q q |
+	EDITOR=./fake_editor.sh git add -p 2>error &&
+	test_must_be_empty error &&
+	git diff --cached >actual &&
+	grep "^+22" actual
+'
+
 test_expect_success 'patch mode ignores unmerged entries' '
 	git reset --hard &&
 	test_commit conflict &&
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadgetNext: Johannes Schindelin via GitGitGadget
Message 2 of 15 in “add -i: close some regression test gaps”
  1. 0/7 add -i: close some regression test gapsJohannes Schindelin via GitGitGadget, Dec 6, 2019
  2. 1/7 t3701: add a test for advanced split-hunk editingJohannes Schindelin via GitGitGadget, Dec 6, 2019
  3. 2/7 t3701: avoid depending on the TTY prerequisiteJohannes Schindelin via GitGitGadget, Dec 6, 2019
  4. SZEDER GáborDec 16, 2019
  5. Jeff KingDec 17, 2019
  6. 3/7 t3701: add a test for the different `add -p` promptsJohannes Schindelin via GitGitGadget, Dec 6, 2019
  7. 5/7 t3701: verify that the diff.algorithm config setting is handledJohannes Schindelin via GitGitGadget, Dec 6, 2019
  8. 4/7 t3701: verify the shown messages when nothing can be addedJohannes Schindelin via GitGitGadget, Dec 6, 2019
  9. 7/7 apply --allow-overlap: fix a corner caseJohannes Schindelin via GitGitGadget, Dec 6, 2019
  10. Junio C HamanoDec 6, 2019
  11. Johannes SchindelinDec 6, 2019
  12. Junio C HamanoDec 6, 2019
  13. Johannes SchindelinDec 6, 2019
  14. 6/7 git add -p: use non-zero exit code when the diff generation failedJohannes Schindelin via GitGitGadget, Dec 6, 2019
  15. Junio C HamanoDec 6, 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.