X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=t%2Ft3701-add-interactive.sh;h=9e236f9cc0bf43155d377c1706c8142d843c417d;hb=e06ed3ed8a72cadb2c3f9695825c827c1584549d;hp=b6eba6a83904a00724b7b550a9bc3b1b35825bee;hpb=03f94ae9f909952ed5a78917ab319a312889354b;p=git.git diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index b6eba6a83..9e236f9cc 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -2,22 +2,20 @@ test_description='add -i basic tests' . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh -if ! test_have_prereq PERL; then - say 'skipping git add -i tests, perl not available' - test_done -fi - -test_expect_success 'setup (initial)' ' +test_expect_success PERL 'setup (initial)' ' echo content >file && git add file && echo more >>file && echo lines >>file ' -test_expect_success 'status works (initial)' ' +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 'revert works (initial)' ' +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 'setup (commit)' ' +test_expect_success PERL 'setup (commit)' ' echo baseline >file && git add file && git commit -m commit && @@ -47,10 +47,12 @@ test_expect_success 'setup (commit)' ' echo more >>file && echo lines >>file ' -test_expect_success 'status works (commit)' ' +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 'revert works (commit)' ' +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 <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 +' + +test_expect_success PERL 'setup fake editor' ' + echo "#!$SHELL_PATH" >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' ' + 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 <patch <expected <output && test_cmp expected output ' -test_expect_success 'skip files similarly as commit -a' ' +test_expect_success PERL 'skip files similarly as commit -a' ' git reset && echo file >.gitignore && echo changed >file && @@ -152,14 +177,7 @@ test_expect_success 'skip files similarly as commit -a' ' ' rm -f .gitignore -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' ' +test_expect_success PERL,FILEMODE 'patch does not affect mode' ' git reset --hard && echo content >>file && chmod +x file && @@ -168,7 +186,7 @@ test_expect_success FILEMODE 'patch does not affect mode' ' git diff file | grep "new mode" ' -test_expect_success FILEMODE 'stage mode but not hunk' ' +test_expect_success PERL,FILEMODE 'stage mode but not hunk' ' git reset --hard && echo content >>file && chmod +x file && @@ -178,7 +196,7 @@ test_expect_success FILEMODE 'stage mode but not hunk' ' ' -test_expect_success FILEMODE 'stage mode and hunk' ' +test_expect_success PERL,FILEMODE 'stage mode and hunk' ' git reset --hard && echo content >>file && chmod +x file && @@ -190,13 +208,14 @@ test_expect_success FILEMODE 'stage mode and hunk' ' # end of tests disabled when filemode is not usable -test_expect_success 'setup again' ' +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 <expected <non-empty && git add non-empty && @@ -248,13 +275,15 @@ test_expect_success 'deleting a non-empty file' ' test_cmp expected diff ' +test_expect_success PERL 'setup expected' ' cat >expected < empty && git add empty && @@ -265,4 +294,40 @@ test_expect_success 'deleting an empty file' ' test_cmp expected diff ' +test_expect_success PERL 'split hunk setup' ' + git reset --hard && + for i in 10 20 30 40 50 60 + do + echo $i + done >test && + git add test && + test_tick && + git commit -m test && + + for i in 10 15 20 21 22 23 24 30 40 50 60 + do + echo $i + done >test +' + +test_expect_success PERL 'split hunk "add -p (edit)"' ' + # Split, say Edit and do nothing. Then: + # + # 1. Broken version results in a patch that does not apply and + # only takes [y/n] (edit again) so the first q is discarded + # and then n attempts to discard the edit. Repeat q enough + # times to get out. + # + # 2. Correct version applies the (not)edited version, and asks + # about the next hunk, against wich we say q and program + # exits. + for a in s e q n q q + do + echo $a + done | + EDITOR=: git add -p && + git diff >actual && + ! grep "^+15" actual +' + test_done