]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'pw/add-p-hunk-splitting-fix' into jch
authorJunio C Hamano <gitster@pobox.com>
Sun, 5 Oct 2025 22:04:15 +0000 (15:04 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 5 Oct 2025 22:04:15 +0000 (15:04 -0700)
Marking a hunk 'selected' in "git add -p" and then splitting made
all the split pieces 'selected'; this has been changed to make them
all 'undecided', which gives better end-user experience.

* pw/add-p-hunk-splitting-fix:
  add-patch: update hunk splitability after editing
  add -p: mark split hunks as undecided

1  2 
add-patch.c
t/t3701-add-interactive.sh

diff --cc add-patch.c
Simple merge
index d9fe289a7ad13a61aa92e3227678cad25ee2dc96,13739a45820241708ecb1c9c13a8ba3287d4e792..b3cc152cc44b14214e47135dc5a4ff445018feb3
                test_must_fail git $cmd --inter-hunk-context 2 2>actual &&
                test_grep -E ".--inter-hunk-context. requires .(--interactive/)?--patch." actual
        '
 +
 +      test_expect_success "$cmd falls back to color.ui" '
 +              git reset --hard patch-base &&
 +              echo working-tree >file &&
 +              test_write_lines y |
 +              force_color git -c color.ui=false $cmd -p >output.raw 2>&1 &&
 +              test_decode_color <output.raw >output &&
 +              test_cmp output.raw output
 +      '
  done
  
+ test_expect_success 'splitting previous hunk marks split hunks as undecided' '
+       test_write_lines a " " b c d e f g h i j k >file &&
+       git add file &&
+       test_write_lines x " " b y d e f g h i j x >file &&
+       test_write_lines n K s n y q | git add -p file &&
+       git cat-file blob :file >actual &&
+       test_write_lines a " " b y d e f g h i j k >expect &&
+       test_cmp expect actual
+ '
+ test_expect_success 'splitting edited hunk' '
+       # Before the first hunk is edited it can be split into two
+       # hunks, after editing it can be split into three hunks.
+       write_script fake-editor.sh <<-\EOF &&
+       sed "s/^ c/-c/" "$1" >"$1.tmp" &&
+       mv "$1.tmp" "$1"
+       EOF
+       test_write_lines a b c d e f g h i j k l m n >file &&
+       git add file &&
+       test_write_lines A b c d E f g h i j k l M n >file &&
+       (
+               test_set_editor "$(pwd)/fake-editor.sh" &&
+               test_write_lines e K s j y n y q | git add -p file
+       ) &&
+       git cat-file blob :file >actual &&
+       test_write_lines a b d e f g h i j k l M n >expect &&
+       test_cmp expect actual
+ '
  test_done