#!/bin/sh test_description='add -i basic tests' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh test_expect_success PERL 'setup (initial)' ' echo content >file && git add file && echo more >>file && echo lines >>file ' test_expect_success PERL 'status works (initial)' ' git add -i output && grep "+1/-0 *+2/-0 file" output ' test_expect_success PERL 'setup expected' ' cat >expected <output && sed -ne "/new file/,/content/p" diff && test_cmp expected diff ' test_expect_success PERL 'revert works (initial)' ' git add file && (echo r; echo 1) | git add -i && git ls-files >output && ! grep . output ' test_expect_success PERL 'setup (commit)' ' echo baseline >file && git add file && git commit -m commit && echo content >>file && git add file && echo more >>file && echo lines >>file ' test_expect_success PERL 'status works (commit)' ' git add -i output && grep "+1/-0 *+2/-0 file" output ' test_expect_success PERL 'setup expected' ' cat >expected <output && sed -ne "/^index/,/content/p" diff && test_cmp expected diff ' test_expect_success PERL 'revert works (commit)' ' git add file && (echo r; echo 1) | git add -i && git add -i output && grep "unchanged *+3/-0 file" output ' test_expect_success PERL 'setup expected' ' cat >expected <fake_editor.sh && chmod a+x fake_editor.sh && test_set_editor "$(pwd)/fake_editor.sh" ' test_expect_success PERL 'dummy edit works' ' (echo e; echo a) | git add -p && git diff > diff && test_cmp expected diff ' test_expect_success PERL 'setup patch' ' cat >patch <fake_editor.sh && cat >>fake_editor.sh <<\EOF && mv -f "$1" oldpatch && mv -f patch "$1" EOF chmod a+x fake_editor.sh && test_set_editor "$(pwd)/fake_editor.sh" ' test_expect_success PERL 'bad edit rejected' ' git reset && (echo e; echo n; echo d) | git add -p >output && grep "hunk does not apply" output ' test_expect_success PERL 'setup patch' ' cat >patch <output && grep "hunk does not apply" output ' test_expect_success PERL 'setup patch' ' cat >patch <expected <output && test_cmp expected output ' test_expect_success PERL 'skip files similarly as commit -a' ' git reset && echo file >.gitignore && echo changed >file && echo y | git add -p file && git diff >output && git reset && git commit -am commit && git diff >expected && test_cmp expected output && git reset --hard HEAD^ ' rm -f .gitignore test_expect_success PERL,FILEMODE 'patch does not affect mode' ' git reset --hard && echo content >>file && chmod +x file && printf "n\\ny\\n" | git add -p && git show :file | grep content && git diff file | grep "new mode" ' test_expect_success PERL,FILEMODE 'stage mode but not hunk' ' git reset --hard && echo content >>file && chmod +x file && printf "y\\nn\\n" | git add -p && git diff --cached file | grep "new mode" && git diff file | grep "+content" ' test_expect_success PERL,FILEMODE 'stage mode and hunk' ' git reset --hard && echo content >>file && chmod +x file && printf "y\\ny\\n" | git add -p && git diff --cached file | grep "new mode" && git diff --cached file | grep "+content" && test -z "$(git diff file)" ' # end of tests disabled when filemode is not usable test_expect_success PERL 'setup again' ' git reset --hard && test_chmod +x file && echo content >>file ' # Write the patch file with a new line at the top and bottom test_expect_success PERL 'setup patch' ' cat >patch <expected < diff && test_cmp expected diff ' test_expect_success PERL 'setup expected' ' cat >expected <non-empty && git add non-empty && git commit -m non-empty && rm non-empty && echo y | git add -p non-empty && git diff --cached >diff && test_cmp expected diff ' test_expect_success PERL 'setup expected' ' cat >expected < empty && git add empty && git commit -m empty && rm empty && echo y | git add -p empty && git diff --cached >diff && test_cmp expected diff ' test_done