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
!ADD_I_USE_BUILTIN
,!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
'setup (initial)' '
55 test_expect_success
'status works (initial)' '
56 git add -i </dev/null >output &&
57 grep "+1/-0 *+2/-0 file" output
60 test_expect_success
'setup expected' '
63 index 0000000..d95f3ad
71 test_expect_success
'diff works (initial)' '
72 test_write_lines d 1 | git add -i >output &&
73 sed -ne "/new file/,/content/p" <output >diff &&
74 diff_cmp expected diff
76 test_expect_success
'revert works (initial)' '
78 test_write_lines r 1 | git add -i &&
79 git ls-files >output &&
83 test_expect_success
'add untracked (multiple)' '
84 test_when_finished "git reset && rm [1-9]" &&
85 touch $(test_seq 9) &&
86 test_write_lines a "2-5 8-" | git add -i -- [1-9] &&
87 test_write_lines 2 3 4 5 8 9 >expected &&
88 git ls-files [1-9] >output &&
89 test_cmp expected output
92 test_expect_success
'setup (commit)' '
93 echo baseline >file &&
95 git commit -m commit &&
96 echo content >>file &&
101 test_expect_success
'status works (commit)' '
102 git add -i </dev/null >output &&
103 grep "+1/-0 *+2/-0 file" output
106 test_expect_success
'update can stage deletions' '
110 test_write_lines u t "" | git add -i &&
111 git ls-files to-delete >output &&
112 test_must_be_empty output
115 test_expect_success
'setup expected' '
116 cat >expected <<-\EOF
117 index 180b47c..b6f2c08 100644
126 test_expect_success
'diff works (commit)' '
127 test_write_lines d 1 | git add -i >output &&
128 sed -ne "/^index/,/content/p" <output >diff &&
129 diff_cmp expected diff
131 test_expect_success
'revert works (commit)' '
133 test_write_lines r 1 | git add -i &&
134 git add -i </dev/null >output &&
135 grep "unchanged *+3/-0 file" output
138 test_expect_success
'setup expected' '
139 cat >expected <<-\EOF
143 test_expect_success
'dummy edit works' '
145 test_write_lines e a | git add -p &&
147 diff_cmp expected diff
150 test_expect_success
'setup patch' '
160 test_expect_success
'setup fake editor' '
161 write_script "fake_editor.sh" <<-\EOF &&
162 mv -f "$1" oldpatch &&
165 test_set_editor "$(pwd)/fake_editor.sh"
168 test_expect_success
'bad edit rejected' '
170 test_write_lines e n d | git add -p >output &&
171 grep "hunk does not apply" output
174 test_expect_success
'setup patch' '
181 test_expect_success
'garbage edit rejected' '
183 test_write_lines e n d | git add -p >output &&
184 grep "hunk does not apply" output
187 test_expect_success
'setup patch' '
197 test_expect_success
'setup expected' '
198 cat >expected <<-\EOF
199 diff --git a/file b/file
200 index b5dd6c9..f910ae9 100644
212 test_expect_success
'real edit works' '
213 test_write_lines e n d | git add -p &&
215 diff_cmp expected output
218 test_expect_success
'setup file' '
219 test_write_lines a "" b "" c >file &&
221 test_write_lines a "" d "" c >file
224 test_expect_success
'setup patch' '
238 test_expect_success
'setup expected' '
240 diff --git a/file b/file
241 index b5dd6c9..f910ae9 100644
254 test_expect_success
'edit can strip spaces from empty context lines' '
255 test_write_lines e n q | git add -p 2>error &&
256 test_must_be_empty error &&
258 diff_cmp expected output
261 test_expect_success
'skip files similarly as commit -a' '
263 echo file >.gitignore &&
264 echo changed >file &&
265 echo y | git add -p file &&
268 git commit -am commit &&
269 git diff >expected &&
270 diff_cmp expected output &&
271 git reset --hard HEAD^
275 test_expect_success FILEMODE
'patch does not affect mode' '
277 echo content >>file &&
279 printf "n\\ny\\n" | git add -p &&
280 git show :file | grep content &&
281 git diff file | grep "new mode"
284 test_expect_success FILEMODE
'stage mode but not hunk' '
286 echo content >>file &&
288 printf "y\\nn\\n" | git add -p &&
289 git diff --cached file | grep "new mode" &&
290 git diff file | grep "+content"
294 test_expect_success FILEMODE
'stage mode and hunk' '
296 echo content >>file &&
298 printf "y\\ny\\n" | git add -p &&
299 git diff --cached file | grep "new mode" &&
300 git diff --cached file | grep "+content" &&
301 test -z "$(git diff file)"
304 # end of tests disabled when filemode is not usable
306 test_expect_success
'different prompts for mode change/deleted' '
310 git add --chmod=+x file deleted &&
311 echo changed >file &&
313 test_write_lines n n n |
314 git -c core.filemode=true add -p >actual &&
315 sed -n "s/^\(([0-9/]*) Stage .*?\).*/\1/p" actual >actual.filtered &&
316 cat >expect <<-\EOF &&
317 (1/1) Stage deletion [y,n,q,a,d,?]?
318 (1/2) Stage mode change [y,n,q,a,d,j,J,g,/,?]?
319 (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]?
321 test_cmp expect actual.filtered
324 test_expect_success
'correct message when there is nothing to do' '
327 test_i18ngrep "No changes" err &&
328 printf "\\0123" >binary &&
330 printf "\\0abc" >binary &&
332 test_i18ngrep "Only binary files changed" err
335 test_expect_success
'setup again' '
337 test_chmod +x file &&
338 echo content >>file &&
339 test_write_lines A B C D>file2 &&
343 # Write the patch file with a new line at the top and bottom
344 test_expect_success
'setup patch' '
346 index 180b47c..b6f2c08 100644
354 \ No newline at end of file
355 diff --git a/file2 b/file2
356 index 8422d40..35b930a 100644
370 # Expected output, diff is similar to the patch but w/ diff at the top
371 test_expect_success
'setup expected' '
372 echo diff --git a/file b/file >expected &&
373 sed -e "/^index 180b47c/s/ 100644/ 100755/" \
375 -e /Y/d patch >>expected &&
376 cat >expected-output <<-\EOF
384 \ No newline at end of file
393 \ No newline at end of file
419 # Test splitting the first patch, then adding both
420 test_expect_success
'add first line works' '
421 git commit -am "clear local changes" &&
423 test_write_lines s y y s y n y | git add -p 2>error >raw-output &&
424 sed -n -e "s/^([1-9]\/[1-9]) Stage this hunk[^@]*\(@@ .*\)/\1/" \
425 -e "/^[-+@ \\\\]"/p raw-output >output &&
426 test_must_be_empty error &&
427 git diff --cached >diff &&
428 diff_cmp expected diff &&
429 test_cmp expected-output output
432 test_expect_success
'setup expected' '
433 cat >expected <<-\EOF
434 diff --git a/non-empty b/non-empty
435 deleted file mode 100644
436 index d95f3ad..0000000
444 test_expect_success
'deleting a non-empty file' '
446 echo content >non-empty &&
448 git commit -m non-empty &&
450 echo y | git add -p non-empty &&
451 git diff --cached >diff &&
452 diff_cmp expected diff
455 test_expect_success
'setup expected' '
456 cat >expected <<-\EOF
457 diff --git a/empty b/empty
458 deleted file mode 100644
459 index e69de29..0000000
463 test_expect_success
'deleting an empty file' '
467 git commit -m empty &&
469 echo y | git add -p empty &&
470 git diff --cached >diff &&
471 diff_cmp expected diff
474 test_expect_success
'adding an empty file' '
478 test_commit initial &&
482 git commit -m empty &&
483 git tag added-file &&
484 git reset --hard HEAD^ &&
485 test_path_is_missing empty &&
487 echo y | git checkout -p added-file -- >actual &&
488 test_path_is_file empty &&
489 test_i18ngrep "Apply addition to index and worktree" actual
493 test_expect_success
'split hunk setup' '
495 test_write_lines 10 20 30 40 50 60 >test &&
498 git commit -m test &&
500 test_write_lines 10 15 20 21 22 23 24 30 40 50 60 >test
503 test_expect_success
'goto hunk' '
504 test_when_finished "git reset" &&
505 tr _ " " >expect <<-EOF &&
506 (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]? + 1: -1,2 +1,3 +15
508 go to which hunk? @@ -1,2 +1,3 @@
512 (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]?_
514 test_write_lines s y g 1 | git add -p >actual &&
515 tail -n 7 <actual >actual.trimmed &&
516 test_cmp expect actual.trimmed
519 test_expect_success
'navigate to hunk via regex' '
520 test_when_finished "git reset" &&
521 tr _ " " >expect <<-EOF &&
522 (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]? @@ -1,2 +1,3 @@
526 (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]?_
528 test_write_lines s y /1,2 | git add -p >actual &&
529 tail -n 5 <actual >actual.trimmed &&
530 test_cmp expect actual.trimmed
533 test_expect_success
'split hunk "add -p (edit)"' '
534 # Split, say Edit and do nothing. Then:
536 # 1. Broken version results in a patch that does not apply and
537 # only takes [y/n] (edit again) so the first q is discarded
538 # and then n attempts to discard the edit. Repeat q enough
541 # 2. Correct version applies the (not)edited version, and asks
542 # about the next hunk, against which we say q and program
544 printf "%s\n" s e q n q q |
545 EDITOR=: git add -p &&
550 test_expect_success
'setup ADD_I_USE_BUILTIN check' '
552 if ! test_have_prereq ADD_I_USE_BUILTIN
558 test_expect_
$result 'split hunk "add -p (no, yes, edit)"' '
559 test_write_lines 5 10 20 21 30 31 40 50 60 >test &&
561 # test sequence is s(plit), n(o), y(es), e(dit)
562 # q n q q is there to make sure we exit at the end.
563 printf "%s\n" s n y e q n q q |
564 EDITOR=: git add -p 2>error &&
565 test_must_be_empty error &&
570 test_expect_success
'split hunk with incomplete line at end' '
572 printf "missing LF" >>test &&
574 test_write_lines before 10 20 30 40 50 60 70 >test &&
575 git grep --cached missing &&
576 test_write_lines s n y q | git add -p &&
577 test_must_fail git grep --cached missing &&
579 test_must_fail git grep --cached before
582 test_expect_
$result 'edit, adding lines to the first hunk' '
583 test_write_lines 10 11 20 30 40 50 51 60 >test &&
585 tr _ " " >patch <<-EOF &&
595 # test sequence is s(plit), e(dit), n(o)
596 # q n q q is there to make sure we exit at the end.
597 printf "%s\n" s e n q n q q |
598 EDITOR=./fake_editor.sh git add -p 2>error &&
599 test_must_be_empty error &&
600 git diff --cached >actual &&
604 test_expect_success
'patch mode ignores unmerged entries' '
606 test_commit conflict &&
607 test_commit non-conflict &&
608 git checkout -b side &&
609 test_commit side conflict.t &&
611 test_commit main conflict.t &&
612 test_must_fail git merge side &&
613 echo changed >non-conflict.t &&
614 echo y | git add -p >output &&
615 ! grep a/conflict.t output &&
616 cat >expected <<-\EOF &&
617 * Unmerged path conflict.t
618 diff --git a/non-conflict.t b/non-conflict.t
619 index f766221..5ea2ed4 100644
626 git diff --cached >diff &&
627 diff_cmp expected diff
630 test_expect_success
'index is refreshed after applying patch' '
632 echo content >test &&
633 printf y | git add -p &&
634 git diff-files --exit-code
637 test_expect_success
'diffs can be colorized' '
640 echo content >test &&
642 force_color git add -p >output 2>&1 <y &&
643 git diff-files --exit-code &&
645 # We do not want to depend on the exact coloring scheme
646 # git uses for diffs, so just check that we saw some kind of color.
647 grep "$(printf "\\033")" output
650 test_expect_success
'colors can be overridden' '
652 test_when_finished "git rm -f color-test" &&
653 test_write_lines context old more-context >color-test &&
654 git add color-test &&
655 test_write_lines context new more-context another-one >color-test &&
657 echo trigger an error message >input &&
659 -c color.interactive.error=blue \
660 add -i 2>err.raw <input &&
661 test_decode_color <err.raw >err &&
662 grep "<BLUE>Huh (trigger)?<RESET>" err &&
664 test_write_lines help quit >input &&
666 -c color.interactive.header=red \
667 -c color.interactive.help=green \
668 -c color.interactive.prompt=yellow \
669 add -i >actual.raw <input &&
670 test_decode_color <actual.raw >actual &&
671 cat >expect <<-\EOF &&
672 <RED> staged unstaged path<RESET>
673 1: +3/-0 +2/-1 color-test
675 <RED>*** Commands ***<RESET>
676 1: <YELLOW>s<RESET>tatus 2: <YELLOW>u<RESET>pdate 3: <YELLOW>r<RESET>evert 4: <YELLOW>a<RESET>dd untracked
677 5: <YELLOW>p<RESET>atch 6: <YELLOW>d<RESET>iff 7: <YELLOW>q<RESET>uit 8: <YELLOW>h<RESET>elp
678 <YELLOW>What now<RESET>> <GREEN>status - show paths with changes<RESET>
679 <GREEN>update - add working tree state to the staged set of changes<RESET>
680 <GREEN>revert - revert staged set of changes back to the HEAD version<RESET>
681 <GREEN>patch - pick hunks and update selectively<RESET>
682 <GREEN>diff - view diff between HEAD and index<RESET>
683 <GREEN>add untracked - add contents of untracked files to the staged set of changes<RESET>
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>> Bye.
689 test_cmp expect actual &&
691 : exercise recolor_hunk by editing and then look at the hunk again &&
692 test_write_lines s e K q >input &&
694 -c color.interactive.prompt=yellow \
695 -c color.diff.meta=italic \
696 -c color.diff.frag=magenta \
697 -c color.diff.context=cyan \
698 -c color.diff.old=bold \
699 -c color.diff.new=blue \
700 -c core.editor=touch \
701 add -p >actual.raw <input &&
702 test_decode_color <actual.raw >actual.decoded &&
703 sed "s/index [0-9a-f]*\\.\\.[0-9a-f]* 100644/<INDEX-LINE>/" <actual.decoded >actual &&
704 cat >expect <<-\EOF &&
705 <ITALIC>diff --git a/color-test b/color-test<RESET>
706 <ITALIC><INDEX-LINE><RESET>
707 <ITALIC>--- a/color-test<RESET>
708 <ITALIC>+++ b/color-test<RESET>
709 <MAGENTA>@@ -1,3 +1,4 @@<RESET>
710 <CYAN> context<RESET>
712 <BLUE>+<RESET><BLUE>new<RESET>
713 <CYAN> more-context<RESET>
714 <BLUE>+<RESET><BLUE>another-one<RESET>
715 <YELLOW>(1/1) Stage this hunk [y,n,q,a,d,s,e,?]? <RESET><BOLD>Split into 2 hunks.<RESET>
716 <MAGENTA>@@ -1,3 +1,3 @@<RESET>
717 <CYAN> context<RESET>
719 <BLUE>+<RESET><BLUE>new<RESET>
720 <CYAN> more-context<RESET>
721 <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? <RESET><MAGENTA>@@ -3 +3,2 @@<RESET>
722 <CYAN> more-context<RESET>
723 <BLUE>+<RESET><BLUE>another-one<RESET>
724 <YELLOW>(2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]? <RESET><MAGENTA>@@ -1,3 +1,3 @@<RESET>
725 <CYAN> context<RESET>
728 <CYAN> more-context<RESET>
729 <YELLOW>(1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? <RESET>
731 test_cmp expect actual
734 test_expect_success
'colorized diffs respect diff.wsErrorHighlight' '
742 force_color git -c diff.wsErrorHighlight=all add -p >output.raw 2>&1 <y &&
743 test_decode_color <output.raw >output &&
747 test_expect_success
'diffFilter filters diff' '
750 echo content >test &&
751 test_config interactive.diffFilter "sed s/^/foo:/" &&
753 force_color git add -p >output 2>&1 <y &&
755 # avoid depending on the exact coloring or content of the prompts,
756 # and just make sure we saw our diff prefixed
757 grep foo:.*content output
760 test_expect_success
'detect bogus diffFilter output' '
763 echo content >test &&
764 test_config interactive.diffFilter "sed 6d" &&
766 force_color test_must_fail git add -p <y >output 2>&1 &&
767 grep "mismatched output" output
770 test_expect_success
'handle iffy colored hunk headers' '
773 echo content >test &&
775 force_color git -c interactive.diffFilter="sed s/.*@@.*/XX/" \
776 add -p >output 2>&1 <n &&
780 test_expect_success
'handle very large filtered diff' '
782 # The specific number here is not important, but it must
783 # be large enough that the output of "git diff --color"
784 # fills up the pipe buffer. 10,000 results in ~200k of
786 test_seq 10000 >test &&
787 test_config interactive.diffFilter cat &&
789 force_color git add -p >output 2>&1 <y &&
790 git diff-files --exit-code -- test
793 test_expect_success
'diff.algorithm is passed to `git diff-files`' '
798 echo changed >file &&
799 test_must_fail git -c diff.algorithm=bogus add -p 2>err &&
800 test_i18ngrep "error: option diff-algorithm accepts " err
803 test_expect_success
'patch-mode via -i prompts for files' '
808 git add -i <<-\EOF &&
817 git diff --cached --name-only >actual &&
818 diff_cmp expect actual
821 test_expect_success
'add -p handles globs' '
826 echo base >subdir/two.c &&
828 git commit -m base &&
830 echo change >one.c &&
831 echo change >subdir/two.c &&
832 git add -p "*.c" <<-\EOF &&
837 cat >expect <<-\EOF &&
841 git diff --cached --name-only >actual &&
842 test_cmp expect actual
845 test_expect_success
'add -p handles relative paths' '
848 echo base >relpath.c &&
850 git commit -m relpath &&
852 echo change >relpath.c &&
854 git -C subdir add -p .. 2>error <<-\EOF &&
858 test_must_be_empty error &&
860 cat >expect <<-\EOF &&
863 git diff --cached --name-only >actual &&
864 test_cmp expect actual
867 test_expect_success
'add -p does not expand argument lists' '
870 echo content >not-changed &&
871 git add not-changed &&
872 git commit -m "add not-changed file" &&
875 GIT_TRACE=$(pwd)/trace.out git add -p . <<-\EOF &&
879 # we know that "file" must be mentioned since we actually
880 # update it, but we want to be sure that our "." pathspec
881 # was not expanded into the argument list of any command.
882 # So look only for "not-changed".
883 ! grep -E "^trace: (built-in|exec|run_command): .*not-changed" trace.out
886 test_expect_success
'hunk-editing handles custom comment char' '
888 echo change >>file &&
889 test_config core.commentChar "\$" &&
890 echo e | GIT_EDITOR=true git add -p &&
894 test_expect_success
'add -p works even with color.ui=always' '
896 echo change >>file &&
897 test_config color.ui always &&
898 echo y | git add -p &&
900 git diff --cached --name-only >actual &&
901 test_cmp expect actual
904 test_expect_success
'setup different kinds of dirty submodules' '
905 test_create_repo for-submodules &&
908 test_commit initial &&
909 test_create_repo dirty-head &&
914 cp -R dirty-head dirty-otherwise &&
915 cp -R dirty-head dirty-both-ways &&
916 git add dirty-head &&
917 git add dirty-otherwise dirty-both-ways &&
918 git commit -m initial &&
921 test_commit updated &&
922 cd ../dirty-both-ways &&
923 test_commit updated &&
924 echo dirty >>initial &&
926 cd ../dirty-otherwise &&
927 echo dirty >>initial &&
930 git -C for-submodules diff-files --name-only >actual &&
931 cat >expected <<-\EOF &&
935 test_cmp expected actual &&
936 git -C for-submodules diff-files --name-only --ignore-submodules=none >actual &&
937 cat >expected <<-\EOF &&
942 test_cmp expected actual &&
943 git -C for-submodules diff-files --name-only --ignore-submodules=dirty >actual &&
944 cat >expected <<-\EOF &&
948 test_cmp expected actual
951 test_expect_success
'status ignores dirty submodules (except HEAD)' '
952 git -C for-submodules add -i </dev/null >output &&
953 grep dirty-head output &&
954 grep dirty-both-ways output &&
955 ! grep dirty-otherwise output
958 test_expect_success
'handle submodules' '
959 echo 123 >>for-submodules/dirty-otherwise/initial.t &&
961 force_color git -C for-submodules add -p dirty-otherwise >output 2>&1 &&
962 grep "No changes" output &&
964 force_color git -C for-submodules add -p dirty-head >output 2>&1 <y &&
965 git -C for-submodules ls-files --stage dirty-head >actual &&
966 rev="$(git -C for-submodules/dirty-head rev-parse HEAD)" &&
970 test_expect_success
'set up pathological context' '
972 test_write_lines a a a a a a a a a a a >a &&
975 test_write_lines c b a a a a a a a b a a a a >a &&
976 test_write_lines a a a a a a a b a a a a >expected-1 &&
977 test_write_lines b a a a a a a a b a a a a >expected-2 &&
978 # check editing can cope with missing header and deleted context lines
979 # as well as changes to other lines
980 test_write_lines +b " a" >patch
983 test_expect_success
'add -p works with pathological context lines' '
987 git cat-file blob :a >actual &&
988 test_cmp expected-1 actual
991 test_expect_success
'add -p patch editing works with pathological context lines' '
993 # n q q below is in case edit fails
994 printf "%s\n" e y n q q |
996 git cat-file blob :a >actual &&
997 test_cmp expected-2 actual
1000 test_expect_success
'checkout -p works with pathological context lines' '
1001 test_write_lines a a a a a a >a &&
1003 test_write_lines a b a b a b a b a b a >a &&
1004 test_write_lines s n n y q | git checkout -p &&
1005 test_write_lines a b a b a a b a b a >expect &&
1009 # This should be called from a subshell as it sets a temporary editor
1011 write_script new-file-editor.sh
<<-\EOF &&
1012 sed /^#/d "$1" >patch &&
1013 sed /^+c/d patch >"$1"
1015 test_set_editor "$(pwd)/new-file-editor.sh" &&
1016 test_write_lines a b c d e f >new-file &&
1017 test_write_lines a b d e f >new-file-expect &&
1018 test_write_lines "@@ -0,0 +1,6 @@" +a +b +c +d +e +f >patch-expect
1021 test_expect_success 'add -N followed by add -p patch editing' '
1025 git add -N new-file &&
1026 test_write_lines e n q | git add -p &&
1027 git cat-file blob :new-file >actual &&
1028 test_cmp new-file-expect actual &&
1029 test_cmp patch-expect patch
1033 test_expect_success 'checkout -p patch editing of added file' '
1038 git commit -m "add new file" &&
1040 git commit -m "remove new file" &&
1041 test_write_lines e n q | git checkout -p HEAD^ &&
1042 test_cmp new-file-expect new-file &&
1043 test_cmp patch-expect patch
1047 test_expect_success 'show help from add--helper' '
1049 cat >expect <<-EOF &&
1051 <BOLD>*** Commands ***<RESET>
1052 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
1053 5: <BOLD;BLUE>p<RESET>atch 6: <BOLD;BLUE>d<RESET>iff 7: <BOLD;BLUE>q<RESET>uit 8: <BOLD;BLUE>h<RESET>elp
1054 <BOLD;BLUE>What now<RESET>> <BOLD;RED>status - show paths with changes
<RESET
>
1055 <BOLD
;RED
>update
- add working tree state to the staged
set of changes
<RESET
>
1056 <BOLD
;RED
>revert
- revert staged
set of changes back to the HEAD version
<RESET
>
1057 <BOLD
;RED
>patch - pick hunks and update selectively
<RESET
>
1058 <BOLD
;RED
>diff - view
diff between HEAD and index
<RESET
>
1059 <BOLD
;RED
>add untracked
- add contents of untracked files to the staged
set of changes
<RESET
>
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
>>$SP
1066 test_write_lines h | force_color git add
-i >actual.colored
&&
1067 test_decode_color
<actual.colored
>actual
&&
1068 test_cmp expect actual
1071 test_expect_success 'reset -p with unmerged files
' '
1072 test_when_finished
"git checkout --force main" &&
1073 test_commit one conflict
&&
1074 git checkout
-B side HEAD^
&&
1075 test_commit two conflict
&&
1076 test_must_fail git merge one
&&
1078 # this is a noop with only an unmerged entry
1081 # add files that sort before and after unmerged entry
1086 # confirm that we can reset those files
1087 printf "%s\n" y y | git
reset -p &&
1088 git diff-index
--cached --diff-filter=u HEAD
>staged
&&
1089 test_must_be_empty staged