]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'rs/add-patch-options-fix' into seen
authorJunio C Hamano <gitster@pobox.com>
Sun, 5 Oct 2025 22:04:29 +0000 (15:04 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 5 Oct 2025 22:04:29 +0000 (15:04 -0700)
* rs/add-patch-options-fix:
  add-patch: reset "permitted" at loop start
  add-patch: let options k and K roll over like j and J
  add-patch: let options y, n, j, and e roll over to next undecided
  add-patch: document that option J rolls over
  add-patch: improve help for options j, J, k, and K

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

diff --cc add-patch.c
Simple merge
index b3cc152cc44b14214e47135dc5a4ff445018feb3,8c24a76e5909389724dac09e4167f24fe2a550f4..bd14c953446a819c5746d12aa28a9ea3afe192de
        '
  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_expect_success 'options J, K roll over' '
+       test_write_lines a b c d e f g h i >file &&
+       git add file &&
+       test_write_lines X b c d e f g h X >file &&
+       test_write_lines J J K q | git add -p >out &&
+       test_write_lines 1 2 1 2 >expect &&
+       sed -n -e "s-/.*--" -e "s/^(//p" <out >actual &&
+       test_cmp expect actual
+ '
+ test_expect_success 'options y, n, j, k, e roll over to next undecided (1)' '
+       test_write_lines a b c d e f g h i j k l m n o p q >file &&
+       git add file &&
+       test_write_lines X b c d e f g h X j k l m n o p X >file &&
+       test_set_editor : &&
+       test_write_lines g3 y g3 n g3 j g3 e k q | git add -p >out &&
+       test_write_lines 1  3 1  3 1  3 1  3 1 2 >expect &&
+       sed -n -e "s-/.*--" -e "s/^(//p" <out >actual &&
+       test_cmp expect actual
+ '
+ test_expect_success 'options y, n, j, k, e roll over to next undecided (2)' '
+       test_write_lines a b c d e f g h i j k l m n o p q >file &&
+       git add file &&
+       test_write_lines X b c d e f g h X j k l m n o p X >file &&
+       test_set_editor : &&
+       test_write_lines y g3 y g3 n g3 j g3 e g1 k q | git add -p >out &&
+       test_write_lines 1 2  3 2  3 2  3 2  3 2  1 2 >expect &&
+       sed -n -e "s-/.*--" -e "s/^(//p" <out >actual &&
+       test_cmp expect actual
+ '
+ test_expect_success 'invalid option s is rejected' '
+       test_write_lines a b c d e f g h i j k >file &&
+       git add file &&
+       test_write_lines X b X d e f g h i j X >file &&
+       test_write_lines j s q | git add -p >out &&
+       sed -ne "s/ @@.*//" -e "s/ \$//" -e "/^(/p" <out >actual &&
+       cat >expect <<-EOF &&
+       (1/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,s,e,p,?]?
+       (2/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]? Sorry, cannot split this hunk
+       (2/2) Stage this hunk [y,n,q,a,d,k,K,j,J,g,/,e,p,?]?
+       EOF
+       test_cmp expect actual
+ '
  test_done