]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t3701: add a test for advanced split-hunk editing
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Fri, 6 Dec 2019 13:08:19 +0000 (13:08 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 6 Dec 2019 16:57:33 +0000 (08:57 -0800)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t3701-add-interactive.sh

index d4f9386621b468ae805febf7382268ed8bf53d8d..4da99e27afcf980cd9cde7c86afd88ef2c1d46ba 100755 (executable)
@@ -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 &&