3 test_description
='add -i basic tests'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 .
"$TEST_DIRECTORY"/lib-terminal.sh
10 if test_have_prereq
!PERL
12 skip_all
='skipping add -i (scripted) tests, perl not available'
19 sed -e '/^index/s/[0-9a-f]*[1-9a-f][0-9a-f]*\.\./1234567../' \
20 -e '/^index/s/\.\.[0-9a-f]*[1-9a-f][0-9a-f]*/..9abcdef/' \
21 -e '/^index/s/ 00*\.\./ 0000000../' \
22 -e '/^index/s/\.\.00*$/..0000000/' \
23 -e '/^index/s/\.\.00* /..0000000 /' \
26 test_cmp
"$1.filtered" "$2.filtered"
29 # This function uses a trick to manipulate the interactive add to use color:
30 # the `want_color()` function special-cases the situation where a pager was
31 # spawned and Git now wants to output colored text: to detect that situation,
32 # the environment variable `GIT_PAGER_IN_USE` is set. However, color is
33 # suppressed despite that environment variable if the `TERM` variable
34 # indicates a dumb terminal, so we set that variable, too.
37 # The first element of $@ may be a shell function, as a result POSIX
38 # does not guarantee that "one-shot assignment" will not persist after
39 # the function call. Thus, we prevent these variables from escaping
40 # this function's context with this subshell.
42 GIT_PAGER_IN_USE
=true
&&
44 export GIT_PAGER_IN_USE TERM
&&
49 test_expect_success
'warn about add.interactive.useBuiltin' '
50 cat >expect <<-\EOF &&
51 warning: the add.interactive.useBuiltin setting has been removed!
52 See its entry in '\''git help config'\'' for details.
56 for v in = =true =false
58 git -c "add.interactive.useBuiltin$v" add -p >out 2>actual &&
59 test_must_be_empty out &&
60 test_cmp expect actual || return 1
64 test_expect_success
'setup (initial)' '
70 test_expect_success
'status works (initial)' '
71 git add -i </dev/null >output &&
72 grep "+1/-0 *+2/-0 file" output
75 test_expect_success
'setup expected' '
78 index 0000000..d95f3ad
86 test_expect_success
'diff works (initial)' '
87 test_write_lines d 1 | git add -i >output &&
88 sed -ne "/new file/,/content/p" <output >diff &&
89 diff_cmp expected diff
91 test_expect_success
'revert works (initial)' '
93 test_write_lines r 1 | git add -i &&
94 git ls-files >output &&
98 test_expect_success
'add untracked (multiple)' '
99 test_when_finished "git reset && rm [1-9]" &&
100 touch $(test_seq 9) &&
101 test_write_lines a "2-5 8-" | git add -i -- [1-9] &&
102 test_write_lines 2 3 4 5 8 9 >expected &&
103 git ls-files [1-9] >output &&
104 test_cmp expected output
107 test_expect_success
'setup (commit)' '
108 echo baseline >file &&
110 git commit -m commit &&
111 echo content >>file &&
116 test_expect_success
'status works (commit)' '
117 git add -i </dev/null >output &&
118 grep "+1/-0 *+2/-0 file" output
121 test_expect_success
'update can stage deletions' '
125 test_write_lines u t "" | git add -i &&
126 git ls-files to-delete >output &&
127 test_must_be_empty output
130 test_expect_success
'setup expected' '
131 cat >expected <<-\EOF
132 index 180b47c..b6f2c08 100644
141 test_expect_success
'diff works (commit)' '
142 test_write_lines d 1 | git add -i >output &&
143 sed -ne "/^index/,/content/p" <output >diff &&
144 diff_cmp expected diff
146 test_expect_success
'revert works (commit)' '
148 test_write_lines r 1 | git add -i &&
149 git add -i </dev/null >output &&
150 grep "unchanged *+3/-0 file" output
153 test_expect_success
'setup expected' '
154 cat >expected <<-\EOF
158 test_expect_success
'dummy edit works' '
160 test_write_lines e a | git add -p &&
162 diff_cmp expected diff
165 test_expect_success
'setup patch' '
175 test_expect_success
'setup fake editor' '
176 write_script "fake_editor.sh" <<-\EOF &&
177 mv -f "$1" oldpatch &&
180 test_set_editor "$(pwd)/fake_editor.sh"
183 test_expect_success
'bad edit rejected' '
185 test_write_lines e n d | git add -p >output &&
186 grep "hunk does not apply" output
189 test_expect_success
'setup patch' '
196 test_expect_success
'garbage edit rejected' '
198 test_write_lines e n d | git add -p >output &&
199 grep "hunk does not apply" output
202 test_expect_success
'setup patch' '
212 test_expect_success
'setup expected' '
213 cat >expected <<-\EOF
214 diff --git a/file b/file
215 index b5dd6c9..f910ae9 100644
227 test_expect_success
'real edit works' '
228 test_write_lines e n d | git add -p &&
230 diff_cmp expected output
233 test_expect_success
'setup file' '
234 test_write_lines a "" b "" c >file &&
236 test_write_lines a "" d "" c >file
239 test_expect_success
'setup patch' '
253 test_expect_success
'setup expected' '
255 diff --git a/file b/file
256 index b5dd6c9..f910ae9 100644
269 test_expect_success
'edit can strip spaces from empty context lines' '
270 test_write_lines e n q | git add -p 2>error &&
271 test_must_be_empty error &&
273 diff_cmp expected output
276 test_expect_success
'skip files similarly as commit -a' '
278 echo file >.gitignore &&
279 echo changed >file &&
280 echo y | git add -p file &&
283 git commit -am commit &&
284 git diff >expected &&
285 diff_cmp expected output &&
286 git reset --hard HEAD^
290 test_expect_success FILEMODE
'patch does not affect mode' '
292 echo content >>file &&
294 printf "n\\ny\\n" | git add -p &&
295 git show :file | grep content &&
296 git diff file | grep "new mode"
299 test_expect_success FILEMODE
'stage mode but not hunk' '
301 echo content >>file &&
303 printf "y\\nn\\n" | git add -p &&
304 git diff --cached file | grep "new mode" &&
305 git diff file | grep "+content"
309 test_expect_success FILEMODE
'stage mode and hunk' '
311 echo content >>file &&
313 printf "y\\ny\\n" | git add -p &&
314 git diff --cached file >out &&
315 grep "new mode" out &&
316 grep "+content" out &&
317 git diff file >out &&
318 test_must_be_empty out
321 # end of tests disabled when filemode is not usable
323 test_expect_success
'different prompts for mode change/deleted' '
327 git add --chmod=+x file deleted &&
328 echo changed >file &&
330 test_write_lines n n n |
331 git -c core.filemode=true add -p >actual &&
332 sed -n "s/^\(([0-9/]*) Stage .*?\).*/\1/p" actual >actual.filtered &&
333 cat >expect <<-\EOF &&
334 (1/1) Stage deletion [y,n,q,a,d,?]?
335 (1/2) Stage mode change [y,n,q,a,d,j,J,g,/,?]?
336 (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]?
338 test_cmp expect actual.filtered
341 test_expect_success
'correct message when there is nothing to do' '
344 test_i18ngrep "No changes" err &&
345 printf "\\0123" >binary &&
347 printf "\\0abc" >binary &&
349 test_i18ngrep "Only binary files changed" err
352 test_expect_success
'setup again' '
354 test_chmod +x file &&
355 echo content >>file &&
356 test_write_lines A B C D>file2 &&
360 # Write the patch file with a new line at the top and bottom
361 test_expect_success
'setup patch' '
363 index 180b47c..b6f2c08 100644
371 \ No newline at end of file
372 diff --git a/file2 b/file2
373 index 8422d40..35b930a 100644
387 # Expected output, diff is similar to the patch but w/ diff at the top
388 test_expect_success
'setup expected' '
389 echo diff --git a/file b/file >expected &&
390 sed -e "/^index 180b47c/s/ 100644/ 100755/" \
392 -e /Y/d patch >>expected &&
393 cat >expected-output <<-\EOF
401 \ No newline at end of file
410 \ No newline at end of file
436 # Test splitting the first patch, then adding both
437 test_expect_success
'add first line works' '
438 git commit -am "clear local changes" &&
440 test_write_lines s y y s y n y | git add -p 2>error >raw-output &&
441 sed -n -e "s/^([1-9]\/[1-9]) Stage this hunk[^@]*\(@@ .*\)/\1/" \
442 -e "/^[-+@ \\\\]"/p raw-output >output &&
443 test_must_be_empty error &&
444 git diff --cached >diff &&
445 diff_cmp expected diff &&
446 test_cmp expected-output output
449 test_expect_success
'setup expected' '
450 cat >expected <<-\EOF
451 diff --git a/non-empty b/non-empty
452 deleted file mode 100644
453 index d95f3ad..0000000
461 test_expect_success
'deleting a non-empty file' '
463 echo content >non-empty &&
465 git commit -m non-empty &&
467 echo y | git add -p non-empty &&
468 git diff --cached >diff &&
469 diff_cmp expected diff
472 test_expect_success
'setup expected' '
473 cat >expected <<-\EOF
474 diff --git a/empty b/empty
475 deleted file mode 100644
476 index e69de29..0000000
480 test_expect_success
'deleting an empty file' '
484 git commit -m empty &&
486 echo y | git add -p empty &&
487 git diff --cached >diff &&
488 diff_cmp expected diff
491 test_expect_success
'adding an empty file' '
495 test_commit initial &&
499 git commit -m empty &&
500 git tag added-file &&
501 git reset --hard HEAD^ &&
502 test_path_is_missing empty &&
504 echo y | git checkout -p added-file -- >actual &&
505 test_path_is_file empty &&
506 test_i18ngrep "Apply addition to index and worktree" actual
510 test_expect_success
'split hunk setup' '
512 test_write_lines 10 20 30 40 50 60 >test &&
515 git commit -m test &&
517 test_write_lines 10 15 20 21 22 23 24 30 40 50 60 >test
520 test_expect_success
'goto hunk' '
521 test_when_finished "git reset" &&
522 tr _ " " >expect <<-EOF &&
523 (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]? + 1: -1,2 +1,3 +15
525 go to which hunk? @@ -1,2 +1,3 @@
529 (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]?_
531 test_write_lines s y g 1 | git add -p >actual &&
532 tail -n 7 <actual >actual.trimmed &&
533 test_cmp expect actual.trimmed
536 test_expect_success
'navigate to hunk via regex' '
537 test_when_finished "git reset" &&
538 tr _ " " >expect <<-EOF &&
539 (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]? @@ -1,2 +1,3 @@
543 (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]?_
545 test_write_lines s y /1,2 | git add -p >actual &&
546 tail -n 5 <actual >actual.trimmed &&
547 test_cmp expect actual.trimmed
550 test_expect_success
'split hunk "add -p (edit)"' '
551 # Split, say Edit and do nothing. Then:
553 # 1. Broken version results in a patch that does not apply and
554 # only takes [y/n] (edit again) so the first q is discarded
555 # and then n attempts to discard the edit. Repeat q enough
558 # 2. Correct version applies the (not)edited version, and asks
559 # about the next hunk, against which we say q and program
561 printf "%s\n" s e q n q q |
562 EDITOR=: git add -p &&
567 test_expect_success
'split hunk "add -p (no, yes, edit)"' '
568 test_write_lines 5 10 20 21 30 31 40 50 60 >test &&
570 # test sequence is s(plit), n(o), y(es), e(dit)
571 # q n q q is there to make sure we exit at the end.
572 printf "%s\n" s n y e q n q q |
573 EDITOR=: git add -p 2>error &&
574 test_must_be_empty error &&
579 test_expect_success
'split hunk with incomplete line at end' '
581 printf "missing LF" >>test &&
583 test_write_lines before 10 20 30 40 50 60 70 >test &&
584 git grep --cached missing &&
585 test_write_lines s n y q | git add -p &&
586 test_must_fail git grep --cached missing &&
588 test_must_fail git grep --cached before
591 test_expect_success
'edit, adding lines to the first hunk' '
592 test_write_lines 10 11 20 30 40 50 51 60 >test &&
594 tr _ " " >patch <<-EOF &&
604 # test sequence is s(plit), e(dit), n(o)
605 # q n q q is there to make sure we exit at the end.
606 printf "%s\n" s e n q n q q |
607 EDITOR=./fake_editor.sh git add -p 2>error &&
608 test_must_be_empty error &&
609 git diff --cached >actual &&
613 test_expect_success
'patch mode ignores unmerged entries' '
615 test_commit conflict &&
616 test_commit non-conflict &&
617 git checkout -b side &&
618 test_commit side conflict.t &&
620 test_commit main conflict.t &&
621 test_must_fail git merge side &&
622 echo changed >non-conflict.t &&
623 echo y | git add -p >output &&
624 ! grep a/conflict.t output &&
625 cat >expected <<-\EOF &&
626 * Unmerged path conflict.t
627 diff --git a/non-conflict.t b/non-conflict.t
628 index f766221..5ea2ed4 100644
635 git diff --cached >diff &&
636 diff_cmp expected diff
639 test_expect_success
'index is refreshed after applying patch' '
641 echo content >test &&
642 printf y | git add -p &&
643 git diff-files --exit-code
646 test_expect_success
'diffs can be colorized' '
649 echo content >test &&
651 force_color git add -p >output 2>&1 <y &&
652 git diff-files --exit-code &&
654 # We do not want to depend on the exact coloring scheme
655 # git uses for diffs, so just check that we saw some kind of color.
656 grep "$(printf "\\033")" output
659 test_expect_success
'colors can be overridden' '
661 test_when_finished "git rm -f color-test" &&
662 test_write_lines context old more-context >color-test &&
663 git add color-test &&
664 test_write_lines context new more-context another-one >color-test &&
666 echo trigger an error message >input &&
668 -c color.interactive.error=blue \
669 add -i 2>err.raw <input &&
670 test_decode_color <err.raw >err &&
671 grep "<BLUE>Huh (trigger)?<RESET>" err &&
673 test_write_lines help quit >input &&
675 -c color.interactive.header=red \
676 -c color.interactive.help=green \
677 -c color.interactive.prompt=yellow \
678 add -i >actual.raw <input &&
679 test_decode_color <actual.raw >actual &&
680 cat >expect <<-\EOF &&
681 <RED> staged unstaged path<RESET>
682 1: +3/-0 +2/-1 color-test
684 <RED>*** Commands ***<RESET>
685 1: <YELLOW>s<RESET>tatus 2: <YELLOW>u<RESET>pdate 3: <YELLOW>r<RESET>evert 4: <YELLOW>a<RESET>dd untracked
686 5: <YELLOW>p<RESET>atch 6: <YELLOW>d<RESET>iff 7: <YELLOW>q<RESET>uit 8: <YELLOW>h<RESET>elp
687 <YELLOW>What now<RESET>> <GREEN>status - show paths with changes<RESET>
688 <GREEN>update - add working tree state to the staged set of changes<RESET>
689 <GREEN>revert - revert staged set of changes back to the HEAD version<RESET>
690 <GREEN>patch - pick hunks and update selectively<RESET>
691 <GREEN>diff - view diff between HEAD and index<RESET>
692 <GREEN>add untracked - add contents of untracked files to the staged set of changes<RESET>
693 <RED>*** Commands ***<RESET>
694 1: <YELLOW>s<RESET>tatus 2: <YELLOW>u<RESET>pdate 3: <YELLOW>r<RESET>evert 4: <YELLOW>a<RESET>dd untracked
695 5: <YELLOW>p<RESET>atch 6: <YELLOW>d<RESET>iff 7: <YELLOW>q<RESET>uit 8: <YELLOW>h<RESET>elp
696 <YELLOW>What now<RESET>> Bye.
698 test_cmp expect actual &&
700 : exercise recolor_hunk by editing and then look at the hunk again &&
701 test_write_lines s e K q >input &&
703 -c color.interactive.prompt=yellow \
704 -c color.diff.meta=italic \
705 -c color.diff.frag=magenta \
706 -c color.diff.context=cyan \
707 -c color.diff.old=bold \
708 -c color.diff.new=blue \
709 -c core.editor=touch \
710 add -p >actual.raw <input &&
711 test_decode_color <actual.raw >actual.decoded &&
712 sed "s/index [0-9a-f]*\\.\\.[0-9a-f]* 100644/<INDEX-LINE>/" <actual.decoded >actual &&
713 cat >expect <<-\EOF &&
714 <ITALIC>diff --git a/color-test b/color-test<RESET>
715 <ITALIC><INDEX-LINE><RESET>
716 <ITALIC>--- a/color-test<RESET>
717 <ITALIC>+++ b/color-test<RESET>
718 <MAGENTA>@@ -1,3 +1,4 @@<RESET>
719 <CYAN> context<RESET>
721 <BLUE>+<RESET><BLUE>new<RESET>
722 <CYAN> more-context<RESET>
723 <BLUE>+<RESET><BLUE>another-one<RESET>
724 <YELLOW>(1/1) Stage this hunk [y,n,q,a,d,s,e,?]? <RESET><BOLD>Split into 2 hunks.<RESET>
725 <MAGENTA>@@ -1,3 +1,3 @@<RESET>
726 <CYAN> context<RESET>
728 <BLUE>+<RESET><BLUE>new<RESET>
729 <CYAN> more-context<RESET>
730 <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? <RESET><MAGENTA>@@ -3 +3,2 @@<RESET>
731 <CYAN> more-context<RESET>
732 <BLUE>+<RESET><BLUE>another-one<RESET>
733 <YELLOW>(2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]? <RESET><MAGENTA>@@ -1,3 +1,3 @@<RESET>
734 <CYAN> context<RESET>
737 <CYAN> more-context<RESET>
738 <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? <RESET>
740 test_cmp expect actual
743 test_expect_success
'colorized diffs respect diff.wsErrorHighlight' '
751 force_color git -c diff.wsErrorHighlight=all add -p >output.raw 2>&1 <y &&
752 test_decode_color <output.raw >output &&
756 test_expect_success
'diffFilter filters diff' '
759 echo content >test &&
760 test_config interactive.diffFilter "sed s/^/foo:/" &&
762 force_color git add -p >output 2>&1 <y &&
764 # avoid depending on the exact coloring or content of the prompts,
765 # and just make sure we saw our diff prefixed
766 grep foo:.*content output
769 test_expect_success
'detect bogus diffFilter output' '
772 echo content >test &&
773 test_config interactive.diffFilter "sed 6d" &&
775 force_color test_must_fail git add -p <y >output 2>&1 &&
776 grep "mismatched output" output
779 test_expect_success
'handle iffy colored hunk headers' '
782 echo content >test &&
784 force_color git -c interactive.diffFilter="sed s/.*@@.*/XX/" \
785 add -p >output 2>&1 <n &&
789 test_expect_success
'handle very large filtered diff' '
791 # The specific number here is not important, but it must
792 # be large enough that the output of "git diff --color"
793 # fills up the pipe buffer. 10,000 results in ~200k of
795 test_seq 10000 >test &&
796 test_config interactive.diffFilter cat &&
798 force_color git add -p >output 2>&1 <y &&
799 git diff-files --exit-code -- test
802 test_expect_success
'diff.algorithm is passed to `git diff-files`' '
807 echo changed >file &&
808 test_must_fail git -c diff.algorithm=bogus add -p 2>err &&
809 test_i18ngrep "error: option diff-algorithm accepts " err
812 test_expect_success
'patch-mode via -i prompts for files' '
817 git add -i <<-\EOF &&
826 git diff --cached --name-only >actual &&
827 diff_cmp expect actual
830 test_expect_success
'add -p handles globs' '
835 echo base >subdir/two.c &&
837 git commit -m base &&
839 echo change >one.c &&
840 echo change >subdir/two.c &&
841 git add -p "*.c" <<-\EOF &&
846 cat >expect <<-\EOF &&
850 git diff --cached --name-only >actual &&
851 test_cmp expect actual
854 test_expect_success
'add -p handles relative paths' '
857 echo base >relpath.c &&
859 git commit -m relpath &&
861 echo change >relpath.c &&
863 git -C subdir add -p .. 2>error <<-\EOF &&
867 test_must_be_empty error &&
869 cat >expect <<-\EOF &&
872 git diff --cached --name-only >actual &&
873 test_cmp expect actual
876 test_expect_success
'add -p does not expand argument lists' '
879 echo content >not-changed &&
880 git add not-changed &&
881 git commit -m "add not-changed file" &&
884 GIT_TRACE=$(pwd)/trace.out git add -p . <<-\EOF &&
888 # we know that "file" must be mentioned since we actually
889 # update it, but we want to be sure that our "." pathspec
890 # was not expanded into the argument list of any command.
891 # So look only for "not-changed".
892 ! grep -E "^trace: (built-in|exec|run_command): .*not-changed" trace.out
895 test_expect_success
'hunk-editing handles custom comment char' '
897 echo change >>file &&
898 test_config core.commentChar "\$" &&
899 echo e | GIT_EDITOR=true git add -p &&
903 test_expect_success
'add -p works even with color.ui=always' '
905 echo change >>file &&
906 test_config color.ui always &&
907 echo y | git add -p &&
909 git diff --cached --name-only >actual &&
910 test_cmp expect actual
913 test_expect_success
'setup different kinds of dirty submodules' '
914 test_create_repo for-submodules &&
917 test_commit initial &&
918 test_create_repo dirty-head &&
923 cp -R dirty-head dirty-otherwise &&
924 cp -R dirty-head dirty-both-ways &&
925 git add dirty-head &&
926 git add dirty-otherwise dirty-both-ways &&
927 git commit -m initial &&
930 test_commit updated &&
931 cd ../dirty-both-ways &&
932 test_commit updated &&
933 echo dirty >>initial &&
935 cd ../dirty-otherwise &&
936 echo dirty >>initial &&
939 git -C for-submodules diff-files --name-only >actual &&
940 cat >expected <<-\EOF &&
944 test_cmp expected actual &&
945 git -C for-submodules diff-files --name-only --ignore-submodules=none >actual &&
946 cat >expected <<-\EOF &&
951 test_cmp expected actual &&
952 git -C for-submodules diff-files --name-only --ignore-submodules=dirty >actual &&
953 cat >expected <<-\EOF &&
957 test_cmp expected actual
960 test_expect_success
'status ignores dirty submodules (except HEAD)' '
961 git -C for-submodules add -i </dev/null >output &&
962 grep dirty-head output &&
963 grep dirty-both-ways output &&
964 ! grep dirty-otherwise output
967 test_expect_success
'handle submodules' '
968 echo 123 >>for-submodules/dirty-otherwise/initial.t &&
970 force_color git -C for-submodules add -p dirty-otherwise >output 2>&1 &&
971 grep "No changes" output &&
973 force_color git -C for-submodules add -p dirty-head >output 2>&1 <y &&
974 git -C for-submodules ls-files --stage dirty-head >actual &&
975 rev="$(git -C for-submodules/dirty-head rev-parse HEAD)" &&
979 test_expect_success
'set up pathological context' '
981 test_write_lines a a a a a a a a a a a >a &&
984 test_write_lines c b a a a a a a a b a a a a >a &&
985 test_write_lines a a a a a a a b a a a a >expected-1 &&
986 test_write_lines b a a a a a a a b a a a a >expected-2 &&
987 # check editing can cope with missing header and deleted context lines
988 # as well as changes to other lines
989 test_write_lines +b " a" >patch
992 test_expect_success
'add -p works with pathological context lines' '
996 git cat-file blob :a >actual &&
997 test_cmp expected-1 actual
1000 test_expect_success
'add -p patch editing works with pathological context lines' '
1002 # n q q below is in case edit fails
1003 printf "%s\n" e y n q q |
1005 git cat-file blob :a >actual &&
1006 test_cmp expected-2 actual
1009 test_expect_success
'checkout -p works with pathological context lines' '
1010 test_write_lines a a a a a a >a &&
1012 test_write_lines a b a b a b a b a b a >a &&
1013 test_write_lines s n n y q | git checkout -p &&
1014 test_write_lines a b a b a a b a b a >expect &&
1018 # This should be called from a subshell as it sets a temporary editor
1020 write_script new-file-editor.sh
<<-\EOF &&
1021 sed /^#/d "$1" >patch &&
1022 sed /^+c/d patch >"$1"
1024 test_set_editor "$(pwd)/new-file-editor.sh" &&
1025 test_write_lines a b c d e f >new-file &&
1026 test_write_lines a b d e f >new-file-expect &&
1027 test_write_lines "@@ -0,0 +1,6 @@" +a +b +c +d +e +f >patch-expect
1030 test_expect_success 'add -N followed by add -p patch editing' '
1034 git add -N new-file &&
1035 test_write_lines e n q | git add -p &&
1036 git cat-file blob :new-file >actual &&
1037 test_cmp new-file-expect actual &&
1038 test_cmp patch-expect patch
1042 test_expect_success 'checkout -p patch editing of added file' '
1047 git commit -m "add new file" &&
1049 git commit -m "remove new file" &&
1050 test_write_lines e n q | git checkout -p HEAD^ &&
1051 test_cmp new-file-expect new-file &&
1052 test_cmp patch-expect patch
1056 test_expect_success 'show help from add--helper' '
1058 cat >expect <<-EOF &&
1060 <BOLD>*** Commands ***<RESET>
1061 1: <BOLD;BLUE>s<RESET>tatus 2: <BOLD;BLUE>u<RESET>pdate 3: <BOLD;BLUE>r<RESET>evert 4: <BOLD;BLUE>a<RESET>dd untracked
1062 5: <BOLD;BLUE>p<RESET>atch 6: <BOLD;BLUE>d<RESET>iff 7: <BOLD;BLUE>q<RESET>uit 8: <BOLD;BLUE>h<RESET>elp
1063 <BOLD;BLUE>What now<RESET>> <BOLD;RED>status - show paths with changes
<RESET
>
1064 <BOLD
;RED
>update
- add working tree state to the staged
set of changes
<RESET
>
1065 <BOLD
;RED
>revert
- revert staged
set of changes back to the HEAD version
<RESET
>
1066 <BOLD
;RED
>patch - pick hunks and update selectively
<RESET
>
1067 <BOLD
;RED
>diff - view
diff between HEAD and index
<RESET
>
1068 <BOLD
;RED
>add untracked
- add contents of untracked files to the staged
set of changes
<RESET
>
1069 <BOLD
>*** Commands
***<RESET
>
1070 1: <BOLD
;BLUE
>s
<RESET
>tatus
2: <BOLD
;BLUE
>u
<RESET
>pdate
3: <BOLD
;BLUE
>r
<RESET
>evert
4: <BOLD
;BLUE
>a
<RESET
>dd untracked
1071 5: <BOLD
;BLUE
>p
<RESET
>atch
6: <BOLD
;BLUE
>d
<RESET
>iff
7: <BOLD
;BLUE
>q
<RESET
>uit
8: <BOLD
;BLUE
>h
<RESET
>elp
1072 <BOLD
;BLUE
>What now
<RESET
>>$SP
1075 test_write_lines h | force_color git add
-i >actual.colored
&&
1076 test_decode_color
<actual.colored
>actual
&&
1077 test_cmp expect actual