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
13 sed -e '/^index/s/[0-9a-f]*[1-9a-f][0-9a-f]*\.\./1234567../' \
14 -e '/^index/s/\.\.[0-9a-f]*[1-9a-f][0-9a-f]*/..9abcdef/' \
15 -e '/^index/s/ 00*\.\./ 0000000../' \
16 -e '/^index/s/\.\.00*$/..0000000/' \
17 -e '/^index/s/\.\.00* /..0000000 /' \
20 test_cmp
"$1.filtered" "$2.filtered"
23 # This function uses a trick to manipulate the interactive add to use color:
24 # the `want_color()` function special-cases the situation where a pager was
25 # spawned and Git now wants to output colored text: to detect that situation,
26 # the environment variable `GIT_PAGER_IN_USE` is set. However, color is
27 # suppressed despite that environment variable if the `TERM` variable
28 # indicates a dumb terminal, so we set that variable, too.
31 # The first element of $@ may be a shell function, as a result POSIX
32 # does not guarantee that "one-shot assignment" will not persist after
33 # the function call. Thus, we prevent these variables from escaping
34 # this function's context with this subshell.
36 GIT_PAGER_IN_USE
=true
&&
38 export GIT_PAGER_IN_USE TERM
&&
43 test_expect_success
'warn about add.interactive.useBuiltin' '
44 cat >expect <<-\EOF &&
45 warning: the add.interactive.useBuiltin setting has been removed!
46 See its entry in '\''git help config'\'' for details.
50 for v in = =true =false
52 git -c "add.interactive.useBuiltin$v" add -p >out 2>actual &&
53 test_must_be_empty out &&
54 test_cmp expect actual || return 1
58 test_expect_success
'setup (initial)' '
64 test_expect_success
'status works (initial)' '
65 git add -i </dev/null >output &&
66 grep "+1/-0 *+2/-0 file" output
69 test_expect_success
'setup expected' '
72 index 0000000..d95f3ad
80 test_expect_success
'diff works (initial)' '
81 test_write_lines d 1 | git add -i >output &&
82 sed -ne "/new file/,/content/p" <output >diff &&
83 diff_cmp expected diff
85 test_expect_success
'revert works (initial)' '
87 test_write_lines r 1 | git add -i &&
88 git ls-files >output &&
92 test_expect_success
'add untracked (multiple)' '
93 test_when_finished "git reset && rm [1-9]" &&
94 touch $(test_seq 9) &&
95 test_write_lines a "2-5 8-" | git add -i -- [1-9] &&
96 test_write_lines 2 3 4 5 8 9 >expected &&
97 git ls-files [1-9] >output &&
98 test_cmp expected output
101 test_expect_success
'setup (commit)' '
102 echo baseline >file &&
104 git commit -m commit &&
105 echo content >>file &&
110 test_expect_success
'status works (commit)' '
111 git add -i </dev/null >output &&
112 grep "+1/-0 *+2/-0 file" output
115 test_expect_success
'update can stage deletions' '
119 test_write_lines u t "" | git add -i &&
120 git ls-files to-delete >output &&
121 test_must_be_empty output
124 test_expect_success
'setup expected' '
125 cat >expected <<-\EOF
126 index 180b47c..b6f2c08 100644
135 test_expect_success
'diff works (commit)' '
136 test_write_lines d 1 | git add -i >output &&
137 sed -ne "/^index/,/content/p" <output >diff &&
138 diff_cmp expected diff
140 test_expect_success
'revert works (commit)' '
142 test_write_lines r 1 | git add -i &&
143 git add -i </dev/null >output &&
144 grep "unchanged *+3/-0 file" output
147 test_expect_success
'setup expected' '
148 cat >expected <<-\EOF
152 test_expect_success
'dummy edit works' '
154 test_write_lines e a | git add -p &&
156 diff_cmp expected diff
159 test_expect_success
'setup patch' '
169 test_expect_success
'setup fake editor' '
170 write_script "fake_editor.sh" <<-\EOF &&
171 mv -f "$1" oldpatch &&
174 test_set_editor "$(pwd)/fake_editor.sh"
177 test_expect_success
'bad edit rejected' '
179 test_write_lines e n d | git add -p >output &&
180 grep "hunk does not apply" output
183 test_expect_success
'setup patch' '
190 test_expect_success
'garbage edit rejected' '
192 test_write_lines e n d | git add -p >output &&
193 grep "hunk does not apply" output
196 test_expect_success
'setup patch' '
206 test_expect_success
'setup expected' '
207 cat >expected <<-\EOF
208 diff --git a/file b/file
209 index b5dd6c9..f910ae9 100644
221 test_expect_success
'real edit works' '
222 test_write_lines e n d | git add -p &&
224 diff_cmp expected output
227 test_expect_success
'setup file' '
228 test_write_lines a "" b "" c >file &&
230 test_write_lines a "" d "" c >file
233 test_expect_success
'setup patch' '
247 test_expect_success
'setup expected' '
249 diff --git a/file b/file
250 index b5dd6c9..f910ae9 100644
263 test_expect_success
'edit can strip spaces from empty context lines' '
264 test_write_lines e n q | git add -p 2>error &&
265 test_must_be_empty error &&
267 diff_cmp expected output
270 test_expect_success
'skip files similarly as commit -a' '
272 echo file >.gitignore &&
273 echo changed >file &&
274 echo y | git add -p file &&
277 git commit -am commit &&
278 git diff >expected &&
279 diff_cmp expected output &&
280 git reset --hard HEAD^
284 test_expect_success FILEMODE
'patch does not affect mode' '
286 echo content >>file &&
288 printf "n\\ny\\n" | git add -p &&
289 git show :file | grep content &&
290 git diff file | grep "new mode"
293 test_expect_success FILEMODE
'stage mode but not hunk' '
295 echo content >>file &&
297 printf "y\\nn\\n" | git add -p &&
298 git diff --cached file | grep "new mode" &&
299 git diff file | grep "+content"
303 test_expect_success FILEMODE
'stage mode and hunk' '
305 echo content >>file &&
307 printf "y\\ny\\n" | git add -p &&
308 git diff --cached file >out &&
309 grep "new mode" out &&
310 grep "+content" out &&
311 git diff file >out &&
312 test_must_be_empty out
315 # end of tests disabled when filemode is not usable
317 test_expect_success
'different prompts for mode change/deleted' '
321 git add --chmod=+x file deleted &&
322 echo changed >file &&
324 test_write_lines n n n |
325 git -c core.filemode=true add -p >actual &&
326 sed -n "s/^\(([0-9/]*) Stage .*?\).*/\1/p" actual >actual.filtered &&
327 cat >expect <<-\EOF &&
328 (1/1) Stage deletion [y,n,q,a,d,?]?
329 (1/2) Stage mode change [y,n,q,a,d,j,J,g,/,?]?
330 (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]?
332 test_cmp expect actual.filtered
335 test_expect_success
'correct message when there is nothing to do' '
338 test_i18ngrep "No changes" err &&
339 printf "\\0123" >binary &&
341 printf "\\0abc" >binary &&
343 test_i18ngrep "Only binary files changed" err
346 test_expect_success
'setup again' '
348 test_chmod +x file &&
349 echo content >>file &&
350 test_write_lines A B C D>file2 &&
354 # Write the patch file with a new line at the top and bottom
355 test_expect_success
'setup patch' '
357 index 180b47c..b6f2c08 100644
365 \ No newline at end of file
366 diff --git a/file2 b/file2
367 index 8422d40..35b930a 100644
381 # Expected output, diff is similar to the patch but w/ diff at the top
382 test_expect_success
'setup expected' '
383 echo diff --git a/file b/file >expected &&
384 sed -e "/^index 180b47c/s/ 100644/ 100755/" \
386 -e /Y/d patch >>expected &&
387 cat >expected-output <<-\EOF
395 \ No newline at end of file
404 \ No newline at end of file
430 # Test splitting the first patch, then adding both
431 test_expect_success
'add first line works' '
432 git commit -am "clear local changes" &&
434 test_write_lines s y y s y n y | git add -p 2>error >raw-output &&
435 sed -n -e "s/^([1-9]\/[1-9]) Stage this hunk[^@]*\(@@ .*\)/\1/" \
436 -e "/^[-+@ \\\\]"/p raw-output >output &&
437 test_must_be_empty error &&
438 git diff --cached >diff &&
439 diff_cmp expected diff &&
440 test_cmp expected-output output
443 test_expect_success
'setup expected' '
444 cat >expected <<-\EOF
445 diff --git a/non-empty b/non-empty
446 deleted file mode 100644
447 index d95f3ad..0000000
455 test_expect_success
'deleting a non-empty file' '
457 echo content >non-empty &&
459 git commit -m non-empty &&
461 echo y | git add -p non-empty &&
462 git diff --cached >diff &&
463 diff_cmp expected diff
466 test_expect_success
'setup expected' '
467 cat >expected <<-\EOF
468 diff --git a/empty b/empty
469 deleted file mode 100644
470 index e69de29..0000000
474 test_expect_success
'deleting an empty file' '
478 git commit -m empty &&
480 echo y | git add -p empty &&
481 git diff --cached >diff &&
482 diff_cmp expected diff
485 test_expect_success
'adding an empty file' '
489 test_commit initial &&
493 git commit -m empty &&
494 git tag added-file &&
495 git reset --hard HEAD^ &&
496 test_path_is_missing empty &&
498 echo y | git checkout -p added-file -- >actual &&
499 test_path_is_file empty &&
500 test_i18ngrep "Apply addition to index and worktree" actual
504 test_expect_success
'split hunk setup' '
506 test_write_lines 10 20 30 40 50 60 >test &&
509 git commit -m test &&
511 test_write_lines 10 15 20 21 22 23 24 30 40 50 60 >test
514 test_expect_success
'goto hunk' '
515 test_when_finished "git reset" &&
516 tr _ " " >expect <<-EOF &&
517 (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]? + 1: -1,2 +1,3 +15
519 go to which hunk? @@ -1,2 +1,3 @@
523 (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]?_
525 test_write_lines s y g 1 | git add -p >actual &&
526 tail -n 7 <actual >actual.trimmed &&
527 test_cmp expect actual.trimmed
530 test_expect_success
'navigate to hunk via regex' '
531 test_when_finished "git reset" &&
532 tr _ " " >expect <<-EOF &&
533 (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]? @@ -1,2 +1,3 @@
537 (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]?_
539 test_write_lines s y /1,2 | git add -p >actual &&
540 tail -n 5 <actual >actual.trimmed &&
541 test_cmp expect actual.trimmed
544 test_expect_success
'split hunk "add -p (edit)"' '
545 # Split, say Edit and do nothing. Then:
547 # 1. Broken version results in a patch that does not apply and
548 # only takes [y/n] (edit again) so the first q is discarded
549 # and then n attempts to discard the edit. Repeat q enough
552 # 2. Correct version applies the (not)edited version, and asks
553 # about the next hunk, against which we say q and program
555 printf "%s\n" s e q n q q |
556 EDITOR=: git add -p &&
561 test_expect_success
'split hunk "add -p (no, yes, edit)"' '
562 test_write_lines 5 10 20 21 30 31 40 50 60 >test &&
564 # test sequence is s(plit), n(o), y(es), e(dit)
565 # q n q q is there to make sure we exit at the end.
566 printf "%s\n" s n y e q n q q |
567 EDITOR=: git add -p 2>error &&
568 test_must_be_empty error &&
573 test_expect_success
'split hunk with incomplete line at end' '
575 printf "missing LF" >>test &&
577 test_write_lines before 10 20 30 40 50 60 70 >test &&
578 git grep --cached missing &&
579 test_write_lines s n y q | git add -p &&
580 test_must_fail git grep --cached missing &&
582 test_must_fail git grep --cached before
585 test_expect_success
'edit, adding lines to the first hunk' '
586 test_write_lines 10 11 20 30 40 50 51 60 >test &&
588 tr _ " " >patch <<-EOF &&
598 # test sequence is s(plit), e(dit), n(o)
599 # q n q q is there to make sure we exit at the end.
600 printf "%s\n" s e n q n q q |
601 EDITOR=./fake_editor.sh git add -p 2>error &&
602 test_must_be_empty error &&
603 git diff --cached >actual &&
607 test_expect_success
'patch mode ignores unmerged entries' '
609 test_commit conflict &&
610 test_commit non-conflict &&
611 git checkout -b side &&
612 test_commit side conflict.t &&
614 test_commit main conflict.t &&
615 test_must_fail git merge side &&
616 echo changed >non-conflict.t &&
617 echo y | git add -p >output &&
618 ! grep a/conflict.t output &&
619 cat >expected <<-\EOF &&
620 * Unmerged path conflict.t
621 diff --git a/non-conflict.t b/non-conflict.t
622 index f766221..5ea2ed4 100644
629 git diff --cached >diff &&
630 diff_cmp expected diff
633 test_expect_success
'index is refreshed after applying patch' '
635 echo content >test &&
636 printf y | git add -p &&
637 git diff-files --exit-code
640 test_expect_success
'diffs can be colorized' '
643 echo content >test &&
645 force_color git add -p >output 2>&1 <y &&
646 git diff-files --exit-code &&
648 # We do not want to depend on the exact coloring scheme
649 # git uses for diffs, so just check that we saw some kind of color.
650 grep "$(printf "\\033")" output
653 test_expect_success
'colors can be overridden' '
655 test_when_finished "git rm -f color-test" &&
656 test_write_lines context old more-context >color-test &&
657 git add color-test &&
658 test_write_lines context new more-context another-one >color-test &&
660 echo trigger an error message >input &&
662 -c color.interactive.error=blue \
663 add -i 2>err.raw <input &&
664 test_decode_color <err.raw >err &&
665 grep "<BLUE>Huh (trigger)?<RESET>" err &&
667 test_write_lines help quit >input &&
669 -c color.interactive.header=red \
670 -c color.interactive.help=green \
671 -c color.interactive.prompt=yellow \
672 add -i >actual.raw <input &&
673 test_decode_color <actual.raw >actual &&
674 cat >expect <<-\EOF &&
675 <RED> staged unstaged path<RESET>
676 1: +3/-0 +2/-1 color-test
678 <RED>*** Commands ***<RESET>
679 1: <YELLOW>s<RESET>tatus 2: <YELLOW>u<RESET>pdate 3: <YELLOW>r<RESET>evert 4: <YELLOW>a<RESET>dd untracked
680 5: <YELLOW>p<RESET>atch 6: <YELLOW>d<RESET>iff 7: <YELLOW>q<RESET>uit 8: <YELLOW>h<RESET>elp
681 <YELLOW>What now<RESET>> <GREEN>status - show paths with changes<RESET>
682 <GREEN>update - add working tree state to the staged set of changes<RESET>
683 <GREEN>revert - revert staged set of changes back to the HEAD version<RESET>
684 <GREEN>patch - pick hunks and update selectively<RESET>
685 <GREEN>diff - view diff between HEAD and index<RESET>
686 <GREEN>add untracked - add contents of untracked files to the staged set of changes<RESET>
687 <RED>*** Commands ***<RESET>
688 1: <YELLOW>s<RESET>tatus 2: <YELLOW>u<RESET>pdate 3: <YELLOW>r<RESET>evert 4: <YELLOW>a<RESET>dd untracked
689 5: <YELLOW>p<RESET>atch 6: <YELLOW>d<RESET>iff 7: <YELLOW>q<RESET>uit 8: <YELLOW>h<RESET>elp
690 <YELLOW>What now<RESET>> Bye.
692 test_cmp expect actual &&
694 : exercise recolor_hunk by editing and then look at the hunk again &&
695 test_write_lines s e K q >input &&
697 -c color.interactive.prompt=yellow \
698 -c color.diff.meta=italic \
699 -c color.diff.frag=magenta \
700 -c color.diff.context=cyan \
701 -c color.diff.old=bold \
702 -c color.diff.new=blue \
703 -c core.editor=touch \
704 add -p >actual.raw <input &&
705 test_decode_color <actual.raw >actual.decoded &&
706 sed "s/index [0-9a-f]*\\.\\.[0-9a-f]* 100644/<INDEX-LINE>/" <actual.decoded >actual &&
707 cat >expect <<-\EOF &&
708 <ITALIC>diff --git a/color-test b/color-test<RESET>
709 <ITALIC><INDEX-LINE><RESET>
710 <ITALIC>--- a/color-test<RESET>
711 <ITALIC>+++ b/color-test<RESET>
712 <MAGENTA>@@ -1,3 +1,4 @@<RESET>
713 <CYAN> context<RESET>
715 <BLUE>+<RESET><BLUE>new<RESET>
716 <CYAN> more-context<RESET>
717 <BLUE>+<RESET><BLUE>another-one<RESET>
718 <YELLOW>(1/1) Stage this hunk [y,n,q,a,d,s,e,?]? <RESET><BOLD>Split into 2 hunks.<RESET>
719 <MAGENTA>@@ -1,3 +1,3 @@<RESET>
720 <CYAN> context<RESET>
722 <BLUE>+<RESET><BLUE>new<RESET>
723 <CYAN> more-context<RESET>
724 <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? <RESET><MAGENTA>@@ -3 +3,2 @@<RESET>
725 <CYAN> more-context<RESET>
726 <BLUE>+<RESET><BLUE>another-one<RESET>
727 <YELLOW>(2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]? <RESET><MAGENTA>@@ -1,3 +1,3 @@<RESET>
728 <CYAN> context<RESET>
731 <CYAN> more-context<RESET>
732 <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? <RESET>
734 test_cmp expect actual
737 test_expect_success
'colorized diffs respect diff.wsErrorHighlight' '
745 force_color git -c diff.wsErrorHighlight=all add -p >output.raw 2>&1 <y &&
746 test_decode_color <output.raw >output &&
750 test_expect_success
'diffFilter filters diff' '
753 echo content >test &&
754 test_config interactive.diffFilter "sed s/^/foo:/" &&
756 force_color git add -p >output 2>&1 <y &&
758 # avoid depending on the exact coloring or content of the prompts,
759 # and just make sure we saw our diff prefixed
760 grep foo:.*content output
763 test_expect_success
'detect bogus diffFilter output' '
766 echo content >test &&
767 test_config interactive.diffFilter "sed 6d" &&
769 force_color test_must_fail git add -p <y >output 2>&1 &&
770 grep "mismatched output" output
773 test_expect_success
'handle iffy colored hunk headers' '
776 echo content >test &&
778 force_color git -c interactive.diffFilter="sed s/.*@@.*/XX/" \
779 add -p >output 2>&1 <n &&
783 test_expect_success
'handle very large filtered diff' '
785 # The specific number here is not important, but it must
786 # be large enough that the output of "git diff --color"
787 # fills up the pipe buffer. 10,000 results in ~200k of
789 test_seq 10000 >test &&
790 test_config interactive.diffFilter cat &&
792 force_color git add -p >output 2>&1 <y &&
793 git diff-files --exit-code -- test
796 test_expect_success
'diff.algorithm is passed to `git diff-files`' '
801 echo changed >file &&
802 test_must_fail git -c diff.algorithm=bogus add -p 2>err &&
803 test_i18ngrep "error: option diff-algorithm accepts " err
806 test_expect_success
'patch-mode via -i prompts for files' '
811 git add -i <<-\EOF &&
820 git diff --cached --name-only >actual &&
821 diff_cmp expect actual
824 test_expect_success
'add -p handles globs' '
829 echo base >subdir/two.c &&
831 git commit -m base &&
833 echo change >one.c &&
834 echo change >subdir/two.c &&
835 git add -p "*.c" <<-\EOF &&
840 cat >expect <<-\EOF &&
844 git diff --cached --name-only >actual &&
845 test_cmp expect actual
848 test_expect_success
'add -p handles relative paths' '
851 echo base >relpath.c &&
853 git commit -m relpath &&
855 echo change >relpath.c &&
857 git -C subdir add -p .. 2>error <<-\EOF &&
861 test_must_be_empty error &&
863 cat >expect <<-\EOF &&
866 git diff --cached --name-only >actual &&
867 test_cmp expect actual
870 test_expect_success
'add -p does not expand argument lists' '
873 echo content >not-changed &&
874 git add not-changed &&
875 git commit -m "add not-changed file" &&
878 GIT_TRACE=$(pwd)/trace.out git add -p . <<-\EOF &&
882 # we know that "file" must be mentioned since we actually
883 # update it, but we want to be sure that our "." pathspec
884 # was not expanded into the argument list of any command.
885 # So look only for "not-changed".
886 ! grep -E "^trace: (built-in|exec|run_command): .*not-changed" trace.out
889 test_expect_success
'hunk-editing handles custom comment char' '
891 echo change >>file &&
892 test_config core.commentChar "\$" &&
893 echo e | GIT_EDITOR=true git add -p &&
897 test_expect_success
'add -p works even with color.ui=always' '
899 echo change >>file &&
900 test_config color.ui always &&
901 echo y | git add -p &&
903 git diff --cached --name-only >actual &&
904 test_cmp expect actual
907 test_expect_success
'setup different kinds of dirty submodules' '
908 test_create_repo for-submodules &&
911 test_commit initial &&
912 test_create_repo dirty-head &&
917 cp -R dirty-head dirty-otherwise &&
918 cp -R dirty-head dirty-both-ways &&
919 git add dirty-head &&
920 git add dirty-otherwise dirty-both-ways &&
921 git commit -m initial &&
924 test_commit updated &&
925 cd ../dirty-both-ways &&
926 test_commit updated &&
927 echo dirty >>initial &&
929 cd ../dirty-otherwise &&
930 echo dirty >>initial &&
933 git -C for-submodules diff-files --name-only >actual &&
934 cat >expected <<-\EOF &&
938 test_cmp expected actual &&
939 git -C for-submodules diff-files --name-only --ignore-submodules=none >actual &&
940 cat >expected <<-\EOF &&
945 test_cmp expected actual &&
946 git -C for-submodules diff-files --name-only --ignore-submodules=dirty >actual &&
947 cat >expected <<-\EOF &&
951 test_cmp expected actual
954 test_expect_success
'status ignores dirty submodules (except HEAD)' '
955 git -C for-submodules add -i </dev/null >output &&
956 grep dirty-head output &&
957 grep dirty-both-ways output &&
958 ! grep dirty-otherwise output
961 test_expect_success
'handle submodules' '
962 echo 123 >>for-submodules/dirty-otherwise/initial.t &&
964 force_color git -C for-submodules add -p dirty-otherwise >output 2>&1 &&
965 grep "No changes" output &&
967 force_color git -C for-submodules add -p dirty-head >output 2>&1 <y &&
968 git -C for-submodules ls-files --stage dirty-head >actual &&
969 rev="$(git -C for-submodules/dirty-head rev-parse HEAD)" &&
973 test_expect_success
'set up pathological context' '
975 test_write_lines a a a a a a a a a a a >a &&
978 test_write_lines c b a a a a a a a b a a a a >a &&
979 test_write_lines a a a a a a a b a a a a >expected-1 &&
980 test_write_lines b a a a a a a a b a a a a >expected-2 &&
981 # check editing can cope with missing header and deleted context lines
982 # as well as changes to other lines
983 test_write_lines +b " a" >patch
986 test_expect_success
'add -p works with pathological context lines' '
990 git cat-file blob :a >actual &&
991 test_cmp expected-1 actual
994 test_expect_success
'add -p patch editing works with pathological context lines' '
996 # n q q below is in case edit fails
997 printf "%s\n" e y n q q |
999 git cat-file blob :a >actual &&
1000 test_cmp expected-2 actual
1003 test_expect_success
'checkout -p works with pathological context lines' '
1004 test_write_lines a a a a a a >a &&
1006 test_write_lines a b a b a b a b a b a >a &&
1007 test_write_lines s n n y q | git checkout -p &&
1008 test_write_lines a b a b a a b a b a >expect &&
1012 # This should be called from a subshell as it sets a temporary editor
1014 write_script new-file-editor.sh
<<-\EOF &&
1015 sed /^#/d "$1" >patch &&
1016 sed /^+c/d patch >"$1"
1018 test_set_editor "$(pwd)/new-file-editor.sh" &&
1019 test_write_lines a b c d e f >new-file &&
1020 test_write_lines a b d e f >new-file-expect &&
1021 test_write_lines "@@ -0,0 +1,6 @@" +a +b +c +d +e +f >patch-expect
1024 test_expect_success 'add -N followed by add -p patch editing' '
1028 git add -N new-file &&
1029 test_write_lines e n q | git add -p &&
1030 git cat-file blob :new-file >actual &&
1031 test_cmp new-file-expect actual &&
1032 test_cmp patch-expect patch
1036 test_expect_success 'checkout -p patch editing of added file' '
1041 git commit -m "add new file" &&
1043 git commit -m "remove new file" &&
1044 test_write_lines e n q | git checkout -p HEAD^ &&
1045 test_cmp new-file-expect new-file &&
1046 test_cmp patch-expect patch
1050 test_expect_success 'show help from add--helper' '
1052 cat >expect <<-EOF &&
1054 <BOLD>*** Commands ***<RESET>
1055 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
1056 5: <BOLD;BLUE>p<RESET>atch 6: <BOLD;BLUE>d<RESET>iff 7: <BOLD;BLUE>q<RESET>uit 8: <BOLD;BLUE>h<RESET>elp
1057 <BOLD;BLUE>What now<RESET>> <BOLD;RED>status - show paths with changes
<RESET
>
1058 <BOLD
;RED
>update
- add working tree state to the staged
set of changes
<RESET
>
1059 <BOLD
;RED
>revert
- revert staged
set of changes back to the HEAD version
<RESET
>
1060 <BOLD
;RED
>patch - pick hunks and update selectively
<RESET
>
1061 <BOLD
;RED
>diff - view
diff between HEAD and index
<RESET
>
1062 <BOLD
;RED
>add untracked
- add contents of untracked files to the staged
set of changes
<RESET
>
1063 <BOLD
>*** Commands
***<RESET
>
1064 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
1065 5: <BOLD
;BLUE
>p
<RESET
>atch
6: <BOLD
;BLUE
>d
<RESET
>iff
7: <BOLD
;BLUE
>q
<RESET
>uit
8: <BOLD
;BLUE
>h
<RESET
>elp
1066 <BOLD
;BLUE
>What now
<RESET
>>$SP
1069 test_write_lines h | force_color git add
-i >actual.colored
&&
1070 test_decode_color
<actual.colored
>actual
&&
1071 test_cmp expect actual
1074 test_expect_success 'reset -p with unmerged files
' '
1075 test_when_finished
"git checkout --force main" &&
1076 test_commit one conflict
&&
1077 git checkout
-B side HEAD^
&&
1078 test_commit two conflict
&&
1079 test_must_fail git merge one
&&
1081 # this is a noop with only an unmerged entry
1084 # add files that sort before and after unmerged entry
1089 # confirm that we can reset those files
1090 printf "%s\n" y y | git
reset -p &&
1091 git diff-index
--cached --diff-filter=u HEAD
>staged
&&
1092 test_must_be_empty staged