bisect: check ancestors without forking a "git rev-list" process
[gitweb.git] / t / t3701-add-interactive.sh
index f15be93e7709acbb517bb85020d4d6b94a50f725..dfc65601aa2171bfc9321753a3d90db112d81f72 100755 (executable)
@@ -3,6 +3,11 @@
 test_description='add -i basic tests'
 . ./test-lib.sh
 
+if ! test_have_prereq PERL; then
+       say 'skipping git add -i tests, perl not available'
+       test_done
+fi
+
 test_expect_success 'setup (initial)' '
        echo content >file &&
        git add file &&
@@ -66,7 +71,81 @@ test_expect_success 'revert works (commit)' '
        grep "unchanged *+3/-0 file" output
 '
 
-test_expect_success 'patch does not affect mode' '
+cat >expected <<EOF
+EOF
+cat >fake_editor.sh <<EOF
+EOF
+chmod a+x fake_editor.sh
+test_set_editor "$(pwd)/fake_editor.sh"
+test_expect_success 'dummy edit works' '
+       (echo e; echo a) | git add -p &&
+       git diff > diff &&
+       test_cmp expected diff
+'
+
+cat >patch <<EOF
+@@ -1,1 +1,4 @@
+ this
++patch
+-doesn't
+ apply
+EOF
+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' '
+       git reset &&
+       (echo e; echo n; echo d) | git add -p >output &&
+       grep "hunk does not apply" output
+'
+
+cat >patch <<EOF
+this patch
+is garbage
+EOF
+test_expect_success 'garbage edit rejected' '
+       git reset &&
+       (echo e; echo n; echo d) | git add -p >output &&
+       grep "hunk does not apply" output
+'
+
+cat >patch <<EOF
+@@ -1,0 +1,0 @@
+ baseline
++content
++newcontent
++lines
+EOF
+cat >expected <<EOF
+diff --git a/file b/file
+index b5dd6c9..f910ae9 100644
+--- a/file
++++ b/file
+@@ -1,4 +1,4 @@
+ baseline
+ content
+-newcontent
++more
+ lines
+EOF
+test_expect_success 'real edit works' '
+       (echo e; echo n; echo d) | git add -p &&
+       git diff >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 &&
@@ -75,7 +154,7 @@ test_expect_success 'patch does not affect mode' '
        git diff file | grep "new mode"
 '
 
-test_expect_success 'stage mode but not hunk' '
+test_expect_success FILEMODE 'stage mode but not hunk' '
        git reset --hard &&
        echo content >>file &&
        chmod +x file &&
@@ -84,5 +163,6 @@ test_expect_success 'stage mode but not hunk' '
        git diff          file | grep "+content"
 '
 
+# end of tests disabled when filemode is not usable
 
 test_done