#!/bin/sh test_description='add -i basic tests' . ./test-lib.sh test_expect_success 'setup (initial)' ' echo content >file && git add file && echo more >>file && echo lines >>file ' test_expect_success 'status works (initial)' ' git add -i output && grep "+1/-0 *+2/-0 file" output ' cat >expected <output && sed -ne "/new file/,/content/p" diff && test_cmp expected diff ' test_expect_success 'revert works (initial)' ' git add file && (echo r; echo 1) | git add -i && git ls-files >output && ! grep . output ' test_expect_success '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 'status works (commit)' ' git add -i output && grep "+1/-0 *+2/-0 file" output ' cat >expected <output && sed -ne "/^index/,/content/p" diff && test_cmp expected diff ' test_expect_success 'revert works (commit)' ' git add file && (echo r; echo 1) | git add -i && git add -i output && grep "unchanged *+3/-0 file" output ' cat >expected <fake_editor.sh < diff && test_cmp expected diff ' 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 'bad edit rejected' ' git reset && (echo e; echo n; echo d) | git add -p >output && grep "hunk does not apply" output ' cat >patch <output && grep "hunk does not apply" output ' cat >patch <expected <output && test_cmp expected output ' if test "$(git config --bool core.filemode)" = false then say 'skipping filemode tests (filesystem does not properly support modes)' else test_set_prereq FILEMODE fi test_expect_success 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 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" ' # end of tests disabled when filemode is not usable test_done